Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- double xOne = 1;
- double functionXOne = formula(xOne);
- double xTwo = 2;
- double functionXTwo = formula(xTwo);
- double xThree = 3;
- double functionXThree = formula(xThree);
- double delta = 0;
- double finaleE = 0.001;
- double aZero = 0;
- double aOne = 0;
- double aTwo = 0;
- double xLine = 0;
- int n = 1;
- do {
- aZero = functionXOne;
- aOne = (functionXTwo - functionXOne) / (xTwo - xOne);
- aTwo = (1 / (xThree - xTwo)) * (((functionXTwo - functionXOne) / (xThree - xOne)) - ((functionXTwo - functionXOne) / (xTwo - xOne)));
- xLine = (0.5) * (xOne + xTwo - (aOne / aTwo));
- delta = Math.abs(Math.pow(xLine, n) - Math.pow(xLine, n - 1));
- System.out.print("n: " + n + " ");
- System.out.print("x1: " + Math.round(xOne * 1000.0) / 1000.0 + " ");
- System.out.print("x2: " + Math.round(xTwo * 1000.0) / 1000.0 + " ");
- System.out.print("x3: " + Math.round(xThree * 1000.0) / 1000.0 + " ");
- System.out.print("x_: " + Math.round(xLine * 1000.0) / 1000.0 + " ");
- System.out.println("D: " + Math.round(delta * 1000.0) / 1000.0 + " ");
- n++;
- double functionLine = formula(xLine);
- xOne = xTwo;
- xTwo = xLine;
- } while (delta > finaleE);
- }
- public static double formula(double x) {
- double end_x;
- return end_x = 10 * Math.pow((3 - x), 4) + 5 * x * x;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment