-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapproximation.cpp
More file actions
73 lines (67 loc) · 1.2 KB
/
approximation.cpp
File metadata and controls
73 lines (67 loc) · 1.2 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
float sum1(vector<float> x,vector<float> y, float n)
{
float suma = 0;
for (int i = 1; i <= n; i++)
{
suma += x[i-1] * y[i-1];
}
return suma;
}
float sum2(vector<float> y, float n)
{
float suma = 0;
for (int i = 1; i <= n; i++)
{
suma += y[i-1];
}
return suma;
}
float sum3(vector<float> x, float n)
{
float suma = 0;
for (int i = 1; i <= n; i++)
{
suma += x[i-1];
}
return suma;
}
float sum4(vector<float> x, float n)
{
float suma = 0;
for (int i = 1; i <= n; i++)
{
suma += pow(x[i-1], 2);
}
return suma;
}
int main() {
int c;
cout << "podaj ilosc danych" << endl;
cin >> c;
vector<float> x, y;
float a, b, d, p;
float s1, s2, s3, s4;
float temp1, temp2;
for (int i = 0; i < c; i++)
{
cout << "podaj " << i + 1 << " x:";
cin >> temp1;
x.push_back(temp1);
cout << "podaj " << i + 1 << " y:";
cin >> temp2;
y.push_back(temp2);
}
s1 = sum1(x, y, c);
s2 = sum2(y, c);
s3 = sum3(x, c);
s4 = sum4(x, c);
a = (c * s1 - s2 * s3) / (c * s4 - pow(s3, 2));
b = (s4 * s2 - s3 * s1) / (c * s4 - pow(s3, 2));
cout << "a jest rowne:" << a << endl;
cout << "b jest rowne:" << b << endl;
return 0;
}