• API
• FAQ
• Tools
• Archive
SHARE
TWEET Untitled a guest May 19th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. public class testing_programm {
2.     public static double epsilon = Math.pow(10,-3);
3.     public static void main(String[] args) {
4.         double x0[];
5.         double x[] = {0,0,0};
6.         double y[] = {-0.6, 0.868, 0.03};
7.         double matrix[][] = {
8.                 {0.5, 0.08, -0.04},
9.                 {0.1, 0.5, -0.212},
10.                 {-0.069, -0.29, 0.5}
11.         };
12.         int count = 0;
13.         do {
14.             x0 = x;
15.             x = mul(matrix,x0);
16.             for(int i = 0; i < x.length; i++) {
17.                 x[i] += y[i];
18.             }
19.             count++;
20.         }   while (check(x,x0));
21.         System.out.println("Vector:");
22.         for(int i = 0; i < x.length; i++) {
23.             System.out.println(x[i]);
24.         }
25.         System.out.println("Amount of iterations = " + count + ";");
26.     }
27.     public static double[] mul (double[][] m, double[] v) {
28.         double vector[] = new double[v.length];
29.         for(int i = 0; i < v.length; i++){
30.             for(int j = 0; j < m.length; j++) {
31.                 vector[i] += m[i][j] * v[j];
32.             }
33.         }
34.         return vector;
35.     }
36.     public static boolean check (double[] x1, double[] x2) {
37.         double max = Math.abs(x1 - x2);
38.         for(int i = 1; i < x1.length; i++) {
39.             if(Math.abs(x2[i] - x1[i]) > max) {
40.                 max = Math.abs(x2[i] - x1[i]);
41.             }
42.         }
43.         if(max < epsilon) {
44.             return false;
45.         }
46.         return true;
47.     }
48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top