Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class testing_programm {
- public static double epsilon = Math.pow(10,-3);
- public static void main(String[] args) {
- double x0[];
- double x[] = {0,0,0};
- double y[] = {-0.6, 0.868, 0.03};
- double matrix[][] = {
- {0.5, 0.08, -0.04},
- {0.1, 0.5, -0.212},
- {-0.069, -0.29, 0.5}
- };
- int count = 0;
- do {
- x0 = x;
- x = mul(matrix,x0);
- for(int i = 0; i < x.length; i++) {
- x[i] += y[i];
- }
- count++;
- } while (check(x,x0));
- System.out.println("Vector:");
- for(int i = 0; i < x.length; i++) {
- System.out.println(x[i]);
- }
- System.out.println("Amount of iterations = " + count + ";");
- }
- public static double[] mul (double[][] m, double[] v) {
- double vector[] = new double[v.length];
- for(int i = 0; i < v.length; i++){
- for(int j = 0; j < m.length; j++) {
- vector[i] += m[i][j] * v[j];
- }
- }
- return vector;
- }
- public static boolean check (double[] x1, double[] x2) {
- double max = Math.abs(x1[0] - x2[0]);
- for(int i = 1; i < x1.length; i++) {
- if(Math.abs(x2[i] - x1[i]) > max) {
- max = Math.abs(x2[i] - x1[i]);
- }
- }
- if(max < epsilon) {
- return false;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement