include iostream include math using namespace std int main size_t dime

 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
#include <iostream>
#include <math.h>
using namespace std;
int main() {
size_t dimension;
cout << "Enter the dimension of points array:" << endl;
cin >> dimension;
double *x = new double[dimension];
double *y = new double[dimension];
cout << "Enter points:" << endl;
for (int i = 0; i < dimension; ++i) {
cout << "Enter x for point" << i << endl;
cin >> x[i];
cout << "Enter y for point" << i << endl;
cin >> y[i];
}
double b0, b1, alpha;
cout << "Enter b0" << endl;
cin >> b0;
cout << "Enter b1" << endl;
cin >> b1;
cout << "Enter alpha" << endl;
cin >> alpha;
for (int i = 0; i < 20; i ++) {
int idx = i % 5;
double p = b0 + b1 * x[idx],
err = p - y[idx];
b0 = b0 - alpha * err;
b1 = b1 - alpha * err * x[idx];
cout << "B0 = " << b0 << ", B1 = " << b1 << ", err = " << err << endl;
}
}