#include <iostream>
#include <vector>
//#include <qfile>
//#include <qrandomgenerator>
//#include <qtextstream>
using namespace std;
void regression(vector<float> &x, vector<float> &y, float &a, float &b)
{
double S, Sx = 0, Sy = 0, Sxx = 0, Syy = 0, Sxy = 0, Delta;
S = x.size();
for (const auto &v : x) {
Sx += v;
}
for (const auto &v : y) {
Sy += v;
}
for (const auto &v : x) {
Sxx += v * v;
}
for (const auto &v : y) {
Syy += v * v;
}
for (int i = 0; i < x.size() && i < y.size(); i++) {
Sxy += x[i] * y[i];
}
Delta = ((S * Sxx) - (Sx * Sx));
a = (((S * Sxy) - (Sx * Sy)) / Delta);
b = (((Sxx * Sy) - (Sx * Sxy)) / Delta);
}
int main()
{
vector<float> x, y, x1,
y1 = {6.41, 9.27, 11.53, 14.56, 17.02, 20.45, 23.09, 25.12, 28.36, 30.80};
float a, b, a1, b1;
for (int i = 0; i < 1000; i++) {
x.emplace_back(i);
}
for (int i = 1; i <= 10; i++) {
x1.emplace_back(i);
}
regression(x, y, a, b);
regression(x1, y1, a1, b1);
cout << a << " " << b << endl;
return 0;
}
Tutaj mam kod w którym brakuje mi samego notatnika z danymi z tabeli i polecenia wierszowego które go odczyta
oraz jakiś pomysł na print regresji ( ostatni podpunkt wizualizacja danych)