Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.util.Scanner;
- public class Main {
- public static double alpha = 0.135;
- public static double [] xk = new double[2];
- public static double [] xk1 = new double[2];
- public static double [] phi = new double[2];
- public static double eps = 0;
- public static int rd = 0;
- public static int n = 0;
- public static double norma = 0;
- public static BigDecimal x0;
- public static BigDecimal x1;
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- eps = sc.nextDouble();
- xk[0] = sc.nextDouble();
- xk[1] = sc.nextDouble();
- rd = rd(eps);
- System.out.println("k\txk\t\t |xk-xk-1|");
- for(int i = 0;i<100;i++){
- if(n==0){
- System.out.println(n + "\t" + xk[0]+"\n\t"+xk[1]);
- n++;
- }else{
- xk1 = getXk1(xk);
- phi = getPhi(xk,alpha);
- xk = getXk(xk,phi,alpha);
- norma = getNorma(xk1,xk);
- BigDecimal r = new BigDecimal(eps).setScale(rd, RoundingMode.HALF_UP);
- BigDecimal nor = new BigDecimal(norma).setScale(rd+1,
- RoundingMode.HALF_UP);
- x0 = new BigDecimal(xk[0]).setScale(rd, RoundingMode.HALF_UP);
- x1 = new BigDecimal(xk[1]).setScale(rd, RoundingMode.HALF_UP);
- System.out.println(n + "\t" + x0+"\t\t"+nor+"\n\t"+x1);
- if(r.compareTo(nor)==1 ||r.compareTo(nor)==0 ){
- break;
- }
- n++;
- }
- }
- System.out.println("x* = " + x0+"\n\t "+x1);
- }
- public static double [] getPhi(double [] xk,double alpha){
- phi[0] =
- (2*(Math.tan(xk[0]*xk[1])-Math.pow(xk[0],2)))*(-2*xk[0]+xk[1]*Math.pow(1/Math.cos(xk[
- 0]*xk[1]),2))+
- +(2*(0.7*xk[0]*xk[0]+2*xk[1]*xk[1]-1))*(xk[0]*Math.pow(1/Math.cos(xk[0]*xk[1]),2));
- phi[1] = (2*(Math.tan(xk[0]*xk[1])-Math.pow(xk[0],2)))*(1.4*xk[0])+
- +(2*(0.7*xk[0]*xk[0]+2*xk[1]*xk[1]-1))*(4*xk[1]);
- return phi;
- }
- public static double getNorma(double [] xk1,double [] xk){
- double a = Math.abs(xk[0]-xk1[0]);
- double b = Math.abs(xk[1]-xk1[1]);
- return Math.max(a,b);
- }
- public static double [] getXk1(double [] xk){
- xk1[0] = xk[0];
- xk1[1] = xk[1];
- return xk1;
- }
- public static double [] getXk(double [] xk,double [] phi,double alpha){
- for(int i = 0;i<2;i++){
- phi[i] = alpha * phi[i];
- }
- for(int i = 0;i<2;i++){
- xk[i] = xk[i]- phi[i];
- }
- return xk;
- }
- public static int rd(double e){
- int k = 0;
- while(e > 0 && e < 1){
- e *= 10;
- k++;
- }
- return k;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement