Or login with:

#include <codecogs/maths/regression/linear.h> #include <iostream> #include <iomanip> using namespace std; int main() { double x[7] = { 1.5, 2.4, 3.2, 4.8, 5.0, 7.0, 8.43 }; double y[7] = { 3.5, 5.3, 7.7, 6.2, 11.0, 9.5, 10.27 }; Maths::Regression::Linear A(7, x, y); cout << " Slope = " << A.getSlope() << endl; cout << "Intercept = " << A.getIntercept() << endl << endl; cout << "Regression coefficient = " << A.getCoefficient() << endl; cout << endl << "Regression line values" << endl << endl; for (double i = 0.0; i <= 3; i += 0.6) { cout << "x = " << setw(3) << i << " y = " << A.getValue(i); cout << endl; } return 0; }Output:
Slope = 0.904273 Intercept = 3.46212 Regression coefficient = 0.808257 Regression line values x = 0 y = 3.46212 x = 0.6 y = 4.00469 x = 1.2 y = 4.54725 x = 1.8 y = 5.08981 x = 2.4 y = 5.63238 x = 3 y = 6.17494
Source code is available when you agree to a GP Licence or buy a Commercial Licence.
Not a member, then Register with CodeCogs. Already a Member, then Login.
| Linear( | int | n | |
| double* | x | ||
| double* | y | )[constructor] |
| n | The number of initial points in the arrays x and y |
| x | The x-coordinates of points |
| y | The y-coordinates of points |
| doublegetValue( | double | x | ) |
| x | the abscissa used to evaluate the linear regression function |
| doublegetCoefficient( | ) |
| doubleLinear_once( | int | n | |
| double* | x | ||
| double* | y | ||
| double | a | ) |
x = 1 y = 0.22 x = 2 y = 0.04 x = 3 y = -0.13 x = 4 y = -0.17 x = 5 y = -0.04 x = 6 y = 0.09 x = 7 y = 0.11

| n | The number of initial points in the arrays x and y |
| x | The x-coordinates of points |
| y | The y-coordinates of points |
| a | The x-coordinate for the output location |
Source code is available when you agree to a GP Licence or buy a Commercial Licence.
Not a member, then Register with CodeCogs. Already a Member, then Login.
You must login to leave a messge