Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- int startA = 1;
- int startB = 3;
- double e = 0.001;
- double eN = 0;
- int n = 1;
- double a = startA;
- double b = startB;
- double x;
- do{
- eN = end_e(n, startA, startB);
- double xOne = xOne(a,b);
- double formulsXOne = formula(xOne);
- double xTwo = xTwo(a,b);
- double formulXTwo = formula(xTwo);
- if(formulsXOne>formulXTwo) {
- System.out.print("Функция убывающая: ");
- a = xOne;
- System.out.print("n: " + n + " ");
- System.out.print("E: " + Math.round(eN * 10000.0) / 10000.0 + " ");
- System.out.print("a: " + Math.round(a * 100.0) / 100.0 + " ");
- System.out.print("b: " + Math.round(b * 100.0) / 100.0 + " ");
- x = xTwo;
- System.out.print("x1: " +Math.round(xOne * 100.0) / 100.0 + " ");
- System.out.print("x2: " + Math.round(xTwo * 100.0) / 100.0 + " ");
- System.out.print("x: " + Math.round(x * 100.0)/ 100.0 + " ");
- System.out.print("formulsXOne: " + Math.round(formulsXOne * 100.0)/ 100.0 + " ");
- System.out.println("formulXTwo: " + Math.round(formulXTwo * 100.0)/ 100.0 + " ");
- }
- if (formulsXOne<formulXTwo){
- System.out.print("Функция возрастает: ");
- b = xTwo;
- System.out.print("n: " + n + " ");
- System.out.print("E: " + Math.round(eN * 10000.0) / 10000.0 + " ");
- System.out.print("a: " + Math.round(a * 100.0) / 100.0 + " ");
- System.out.print("b: " + Math.round(b * 100.0) / 100.0 + " ");
- x = xOne;
- System.out.print("x1: " +Math.round(xOne * 100.0) / 100.0 + " ");
- System.out.print("x2: " + Math.round(xTwo * 100.0) / 100.0 + " ");
- System.out.print("x: " + Math.round(x * 100.0)/ 100.0 + " ");
- System.out.print("formulsXOne: " + Math.round(formulsXOne * 100.0)/ 100.0 + " ");
- System.out.println("formulXTwo: " + Math.round(formulXTwo * 100.0)/ 100.0 + " ");
- }
- n++;
- }while (eN>e);
- }
- public static double formula (double x){
- double end_x;
- return end_x = 10*Math.pow((3-x),4)+5*x*x;
- }
- public static double xOne (double a, double b){
- double end_x1;
- return end_x1 = a + 0.38*(b-a);
- }
- public static double xTwo (double a, double b){
- double end_x1;
- return end_x1 = a + 0.62*(b-a);
- }
- public static double end_e(int n, double a, double b){
- double end_e;
- return end_e = Math.pow(((Math.sqrt(5)-1)/2),n)*(b-a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment