• https://me.yahoo.com
COST (GBP)
8.74
0.00
0

# Stiefel

Approximates a given function using the Stiefel-Remes method.
Controller: CodeCogs

C++
Excel

## Class Stiefel

This algorithm gives the best approximation of a continuous function with real argument in the sense of maximum norm. It uses the Stiefel-Remes method.

An important detail when using this class is that the abscissas array given as argument to the constructor needs to be sorted in ascending order and its elements need to be equally spaced, meaning that:

$X[i]&space;-&space;X[i&space;-&space;1]&space;=&space;\alpha&space;\in&space;\mathcal{R}&space;\mbox{&space;a&space;constant&space;}&space;\qquad&space;1&space;\leq&space;i&space;\leq&space;N&space;-&space;1$

where N is the size of the array. In other words, the associated function needs to be discrete.

Below you will find the regression graphs for a set of points obtained by evaluating the function $\inline&space;&space;f(x)&space;=&space;\sin(2x)&space;/&space;x$, displayed in light blue, at particular abscissas. The Stiefel-Remes polynomial, displayed in red, has been calculated using this class. In the first graph there had been chosen a number of 12 points and degree of polynomial 9, while in the second 36 points were considered with the polynomial degree 16. You may notice the root mean squared error in each of the cases.

### Warning

Choosing too high a degree, numerical rounding errors lead to high-frequency contamination of the results, which become increasingly evident with large values of x. This is visible with the following graph.

## References:

• "Procedures Algol en Analyse Numerique", Editions du CNRS, 1967

### Example 1

#include <codecogs/maths/regression/stiefel.h>

#include <cmath>
#include <iostream>
#include <iomanip>
using namespace std;

#define PI  3.1415
#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(2 * xx) / xx;
}

// Initialize the Stiefel-Remes approximation routine with known data points
Maths::Regression::Stiefel A(N, x, y, 7);

// Interrogate Stiefel polynomial to find approximated values
int N_out = 20;
xx = PI, step = (3 * PI) / (N_out - 1);
for (int i = 0; i < N_out; ++i, xx += step)
cout << "x = " << setw(7) << xx << "  y = " << setw(13) << A.getValue(xx) << endl;
return 0;
}
Output:
x =  3.1415  y =       0.11495
x = 3.63753  y =      0.154609
x = 4.13355  y =     0.0875854
x = 4.62958  y =    0.00476885
x = 5.12561  y =    -0.0516197
x = 5.62163  y =    -0.0705339
x = 6.11766  y =     -0.058554
x = 6.61368  y =    -0.0298593
x = 7.10971  y =   0.000714345
x = 7.60574  y =     0.0219604
x = 8.10176  y =     0.0283645
x = 8.59779  y =     0.0203744
x = 9.09382  y =    0.00330991
x = 9.58984  y =    -0.0146569
x = 10.0859  y =    -0.0250193
x = 10.5819  y =    -0.0215192
x = 11.0779  y =   -0.00236588
x = 11.5739  y =      0.028343
x =   12.07  y =     0.0604278
x =  12.566  y =      0.079094

Vince Cole (August 2005)

### 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 Stiefel

#### Stiefel

 Stiefel( int n double* x double* y int degree )[constructor]
Initializes the necessary data for following evaluations of the polynomial.
 n The number of points x The x-coordinates of the points y The y-coordinates of the points degree The order of the regression

#### GetValue

 doublegetValue( double x )
Returns the approximated ordinate at the given abscissa.
 x The x-coordinate of the position of interest

## Stiefel Once

 doubleStiefel_once( int n double* x double* y int degree double a )
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 performs a regression on the following values, using a 3rd order polynomial:
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 Stiefel_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 Stiefel_once failed. Ensure that: Invalid C++

### Parameters

 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 a The 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.