Natalia__krkrkr

Метод парабол

Sep 22nd, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. public class Main {
  2.     public static void main(String[] args) {
  3.         double xOne = 1;
  4.         double functionXOne = formula(xOne);
  5.         double xTwo = 2;
  6.         double functionXTwo = formula(xTwo);
  7.         double xThree = 3;
  8.         double functionXThree = formula(xThree);
  9.         double delta = 0;
  10.         double finaleE = 0.001;
  11.         double aZero = 0;
  12.         double aOne = 0;
  13.         double aTwo = 0;
  14.         double xLine = 0;
  15.         int n = 1;
  16.         do {
  17.             aZero = functionXOne;
  18.             aOne = (functionXTwo - functionXOne) / (xTwo - xOne);
  19.             aTwo = (1 / (xThree - xTwo)) * (((functionXTwo - functionXOne) / (xThree - xOne)) - ((functionXTwo - functionXOne) / (xTwo - xOne)));
  20.             xLine = (0.5) * (xOne + xTwo - (aOne / aTwo));
  21.             delta = Math.abs(Math.pow(xLine, n) - Math.pow(xLine, n - 1));
  22.             System.out.print("n: " + n + " ");
  23.             System.out.print("x1: " + Math.round(xOne * 1000.0) / 1000.0 + " ");
  24.             System.out.print("x2: " + Math.round(xTwo * 1000.0) / 1000.0 + " ");
  25.             System.out.print("x3: " + Math.round(xThree * 1000.0) / 1000.0 + " ");
  26.             System.out.print("x_: " + Math.round(xLine * 1000.0) / 1000.0 + " ");
  27.             System.out.println("D: " + Math.round(delta * 1000.0) / 1000.0 + " ");
  28.             n++;
  29.             double functionLine = formula(xLine);
  30.             xOne = xTwo;
  31.             xTwo = xLine;
  32.         } while (delta > finaleE);
  33.     }
  34.  
  35.     public static double formula(double x) {
  36.         double end_x;
  37.         return end_x = 10 * Math.pow((3 - x), 4) + 5 * x * x;
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment