Чмы лаба 6

 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream>
#include<math.h>
#define SIZE 9
float x[] = {1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5};
float y[] = {1.22, 1.18, 2.5, 2.35, 4.47, 6.02, 7.35, 10.9, 15.33};
void reverse(){
for (int i = 0; i < SIZE; i++){
x[i] = 1/x[i];
y[i] = 1/y[i];
}
}
float SKU(float a, float b){
float sum = 0;
for(int i = 0; i < SIZE; i++){
sum += (a*x[i] + b - y[i])*(a*x[i] + b - y[i]);
}
return sqrt(sum);
}
float Func(float x, float a, float b){
return x/(a*x + b);
}
int main(){
reverse();
float a = 0, b = 0, c = 0, d = SIZE, e = 0, f = 0;
for(int i = 0; i < SIZE; i++){
a += x[i]*x[i];
b += x[i];
e += y[i];
f += x[i]*y[i];
}
c = b;
float A, B;
B = (a*e - c*f)/(a*d - b*c);
A = (f - b*B)/a;
std::cout << "y = x/(" << B << "*x+" << A << ")" <<std::endl;
std::cout << "СКУ = " << SKU(A, B) << std::endl;
return 0;
}