I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
COST (GBP)
this unit 9.98
sub units 0.00
+
0

Forsythe

Approximates an arbitrary function using Forsythe orthogonal polynomials.
Controller: CodeCogs

add cart

Interface

C++
Excel

Class Forsythe

This class approximates an arbitrary function by least squares fitting using Forsythe orthogonal polynomials. It uses a generalization of the three-term relation by G. Forsythe (1957), generating recursively a system of orthonormal polynomials over arbitrary sets of data points.

Below you will find the regression graph for a set of points obtained by evaluating the function f(x) = \sin(x) + x, displayed in light blue, at particular abscissas. The regression polynomial, displayed in red, has been calculated using this class. The root mean squared error is also displayed.

1/forsythe-378.png
+

References:

  • Jean-Pierre Moreau's Home Page, http://perso.wanadoo.fr/jean-pierre.moreau/
  • F.R. Ruckdeschel, "BASIC Scientific Subroutines", Vol. II, BYTE/McGRAWW-HILL, 1981

Example 1

The following example displays 10 approximated values (you may change this amount through the N_out variable) for the given function f(x) with abscissas equally spaced in the [ \pi, 3\pi] interval. The X and Y coordinate arrays are initialized by evaluating this function for N = 12 points equally spaced in the domain from π to 5 π .
#include <codecogs/maths/regression/forsythe.h>
 
#include <cmath>
#include <iostream>
#include <iomanip>
using namespace std;
 
#define PI  3.1415926535897932384626433832795
#define N   12
 
int main() {
    // Declare and initialize two arrays to hold the coordinates of the initial data points
    double x[N], y[N];
 
    // Generate the points
    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::Forsythe A(N, x, y, 11);
 
    // 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(11) << A.getValue(xx) << endl;
  }
    return 0;
}
Output:
x = 3.14159  y =     3.14159
x = 4.18879  y =     3.32358
x = 5.23599  y =     4.36968
x = 6.28319  y =     6.28329
x = 7.33038  y =     8.19637
x = 8.37758  y =     9.24362
x = 9.42478  y =     9.42478
x =  10.472  y =     9.60593
x = 11.5192  y =     10.6532
x = 12.5664  y =     12.5663

Authors

Lucian Bentea (August 2005)
Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.

Members of Forsythe

Forsythe

 
Forsytheintn
double*x
double*y
intdegree )[constructor]
Initializes the necessary data for following evaluations of the polynomial.
nThe number of initial points in the arrays x and y
xThe x-coordinates for the initial points
yThe y-coordinates for the initial points
degreeThe number of polynomials to use in the approximation

GetValue

 
doublegetValuedoublex )
Returns the approximated ordinate at the given abscissa.
xThe abscissa of the approximation point


Forsythe Once

 
doubleForsythe_onceintn
double*x
double*y
intdegree
doublea )
This function implements the Forsythe class for one off calculations, thereby avoid the need to instantiate the Forsythe class yourself.

Example 2

The following graph are constructed by forming a regression of the following values, using a 3rd order orthogonal polynomials
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
There is an error with your graph parameters for Forsythe_once with options n=7 x="1 2 3 4 5 6 7" y="0.22 0.04 -0.13 -0.17 -0.04 0.09 0.11" degree=3 a=1:7 .input

Error Message:Function Forsythe_once failed. Ensure that: Invalid C++

Parameters

nThe number of initial points in the arrays x and y
xThe x-coordinates for the initial points
yThe y-coordinates for the initial points
degreeThe number of polynomials to use in the approximation
aThe x-coordinate for the output point

Returns

the interpolated y-coordinate that corresponds to a.
Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.