Or login with:

#include <codecogs/maths/regression/orthogonal.h> #include "orthogonal.h" #include <cmath> #include <iostream> #include <iomanip> using namespace std; #define PI 3.1415926535897932384626433832795 #define N 13 int main() { // Declare and initialize two arrays to hold the coordinates of the initial data points double x[N], y[N]; double xx = PI, step = 4 * PI / (N - 1); for (int i = 0; i < N; i++, xx += step) { x[i] = xx; y[i] = sin(xx) + xx; } // Initialize the regression approximation routine with known data points Maths::Regression::Orthogonal A(N, x, y, N - 1); // Interrogate the regression function to find approximated values int N_out = 10; xx = PI, step = (3 * PI) / (N_out - 1); for (int i = 0; i < N_out; ++i, xx += step) { cout << "x = " << setw(7) << xx << " y = "; cout << setw(7) << A.getValue(xx); cout << setw(10) << "error = " << fabs(sin(xx) + xx - A.getValue(xx)) << endl; } return 0; }Output:
x = 3.14159 y = 3.14159 error = 1.33227e-15 x = 4.18879 y = 3.32276 error = 1.77636e-15 x = 5.23599 y = 4.36996 error = 1.86517e-14 x = 6.28319 y = 6.28319 error = 7.19425e-14 x = 7.33038 y = 8.19641 error = 1.1191e-13 x = 8.37758 y = 9.24361 error = 2.41585e-13 x = 9.42478 y = 9.42478 error = 2.91323e-13 x = 10.472 y = 9.60595 error = 2.62901e-13 x = 11.5192 y = 10.6531 error = 2.2915e-13 x = 12.5664 y = 12.5664 error = 1.04805e-13
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.
| Orthogonal( | int | n | |
| double* | x | ||
| double* | y | ||
| int | degree | )[constructor] |
| n | The number of initial points in the arrays x and y |
| x | The x-coordinates for the initial points |
| y | The y-coordinates for the initial points |
| degree | The number of orthogonal polynomials to use in the approximation (must be strictly less than the number of points n) |
| doublegetValue( | double | x | ) |
| x | The abscissa of the approximation point |
| doubleOrthogonal_once( | int | n | |
| double* | x | ||
| double* | y | ||
| int | degree | ||
| 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 for the initial points |
| y | The y-coordinates for the initial points |
| degree | The number of polynomials to use in the approximation (must be strictly less than the number of points n) |
| a | The x-coordinate for the output point |
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