methods - lab6 - дальше хз

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class Marina_lab6 {
static int size = 9;
public static double SKU(double a, double b, double[] x, double[] y) {
double sum = 0.0;
for (int i = 0; i < size; i++) {
sum += (a * x[i] + b - y[i]) * (a * x[i] + b - y[i]);
}
return Math.sqrt(sum);
}
public static void main(String args[]) {
double x[] = {1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0};
double y[] = {2.07, 2.41, 1.77, 1.98, 2.24, 2.73, 2.91, 2.56, 3.07};
double a = 0, b = 0, c = 0, d = 0;
double A, B;
for(int i = 0; i < size; i++) {
a += x[i] * x[i];
b += x[i];
c += x[i] * y[i];
d += y[i];
}
A = (size*c - b*d) / (size*a - b*b);
B = (d - A * b) / size;
System.out.println("Result:");
System.out.println("y = " + A + " *x + " + B);
System.out.println("SKU = " + SKU(A, B, x, y));
}
}