Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

polyinterp Class Reference

Support for four point polynomial interpolation, using the Lagrange formula. More...

#include <polyinterp.h>

List of all members.

Public Methods

 polyinterp ()
 The polyinterp (polynomial interpolation) class constructor calculates the coefficients for a four point polynomial interpolated at -0.5, 0.5, 1.5, 2.5 and 3.5. More...

double interpPoint (double x, int N, double d[])
 Given four points at the x,y coordinates {0,d0}, {1,d1}, {2,d2}, {3,d3} return the y-coordinate value for the polynomial interpolated point at x. More...


Private Methods

void lagrange (double x, int N, double c[])
 The polynomial interpolation algorithm assumes that the known points are located at x-coordinates 0, 1,.. More...

void fillTable (const int N, double table[4][4])
 For a given N-point polynomial interpolation, fill the coefficient table, for points 0.5 ... More...

void printTable (double table[4][4], int N)
 Print an N x N table polynomial coefficient table. More...

void printTables ()
 Print the 4-point and 2-point polynomial coefficient tables. More...

void getCoef (double x, int n, double c[])
 For the polynomial interpolation point x-coordinate x, return the associated polynomial interpolation coefficients. More...


Private Attributes

double fourPointTable [4][4]
double twoPointTable [4][4]


Detailed Description

Support for four point polynomial interpolation, using the Lagrange formula.

Definition at line 32 of file polyinterp.h.


Constructor & Destructor Documentation

polyinterp::polyinterp ( ) [inline]
 

The polyinterp (polynomial interpolation) class constructor calculates the coefficients for a four point polynomial interpolated at -0.5, 0.5, 1.5, 2.5 and 3.5.

Definition at line 163 of file polyinterp.h.

00164    {
00165     // Fill in the 4-point polynomial interplation table
00166     // for the points 0.5, 1.5, 2.5, 3.5
00167     fillTable( 4, fourPointTable );
00168     
00169     // Fill in the 2-point polynomial interpolation table
00170     // for 0.5 and 1.5
00171     fillTable( 2, twoPointTable );
00172    } // polyinterp class constructor


Member Function Documentation

void polyinterp::fillTable ( const int N,
double table[4][4] ) [inline, private]
 

For a given N-point polynomial interpolation, fill the coefficient table, for points 0.5 ...

(N-0.5).

Definition at line 73 of file polyinterp.h.

Referenced by polyinterp().

00074   {
00075     double x;
00076     double n = N;
00077     int i = 0;
00078 
00079     for (x = 0.5; x < n; x = x + 1.0) {
00080       lagrange( x, N, table[i] );
00081       i++;
00082     }
00083   } // fillTable

void polyinterp::getCoef ( double x,
int n,
double c[] ) [inline, private]
 

For the polynomial interpolation point x-coordinate x, return the associated polynomial interpolation coefficients.

Parameters:
x   the x-coordinate for the interpolated pont
n   the number of polynomial interpolation points
c   [] an array to return the polynomial coefficients

Definition at line 127 of file polyinterp.h.

Referenced by interpPoint().

00128   {
00129     int j = (int)x;
00130 
00131     if (j < 0 || j >= n) {
00132       printf("poly::getCoef: n = %d, bad x value = %f\n", n, x);
00133     }
00134 
00135     if (n == 2) {
00136       c[2] = 0.0;
00137       c[3] = 0.0;
00138     }
00139     else if (n != 4) {
00140       printf("poly::getCoef: bad value for N\n");
00141       return;
00142     }
00143 
00144     for (int i = 0; i < n; i++) {
00145       if (n == 4) {
00146         c[i] = fourPointTable[j][i];
00147       }
00148       else { // n == 2
00149         c[i] = twoPointTable[j][i];
00150       }
00151     }
00152 
00153   } // getCoef

double polyinterp::interpPoint ( double x,
int N,
double d[] ) [inline]
 

Given four points at the x,y coordinates {0,d0}, {1,d1}, {2,d2}, {3,d3} return the y-coordinate value for the polynomial interpolated point at x.

Parameters:
x   the x-coordinate for the point to be interpolated
N   the number of interpolation points
d   [] an array containing the y-coordinate values for the known points (which are located at x-coordinates 0..N-1).

Definition at line 187 of file polyinterp.h.

Referenced by polyHaar::interp(), and poly::predict().

00188   {
00189     double c[4];
00190     double point = 0;
00191     
00192     int n = 4;
00193     if (N < 4)
00194       n = N;
00195 
00196     getCoef( x, n, c );
00197 
00198     if (n == 4) {
00199       point = c[0]*d[0] + c[1]*d[1] + c[2]*d[2] + c[3]*d[3]; 
00200     }
00201     else if (n == 2) {
00202       point = c[0]*d[0] + c[1]*d[1];
00203     }
00204 
00205     return point;
00206   } // interpPoint

void polyinterp::lagrange ( double x,
int N,
double c[] ) [inline, private]
 

The polynomial interpolation algorithm assumes that the known points are located at x-coordinates 0, 1,..

N-1. An interpolated point is calculated at x, using N coefficients. The polynomial coefficients for the point x can be calculated staticly, using the Lagrange method.

Parameters:
x   the x-coordinate of the interpolated point
N   the number of polynomial points.
c   [] an array for returning the coefficients

Definition at line 50 of file polyinterp.h.

Referenced by fillTable().

00051   {
00052     double num, denom;
00053 
00054     for (int i = 0; i < N; i++) {
00055       num = 1;
00056       denom = 1;
00057       for (int k = 0; k < N; k++) {
00058         if (i != k) {
00059           num = num * (x - k);
00060           denom = denom * (i - k);
00061         }
00062       } // for k
00063       c[i] = num / denom;
00064     } // for i
00065   } // lagrange

void polyinterp::printTable ( double table[4][4],
int N ) [inline, private]
 

Print an N x N table polynomial coefficient table.

Definition at line 89 of file polyinterp.h.

Referenced by printTables().

00090   {
00091     printf("%d-point interpolation table:\n", N);
00092     double x = 0.5;
00093     for (int i = 0; i < N; i++) {
00094       printf("%4.2f: ", x);
00095       for (int j = 0; j < N; j++) {
00096         printf("%6.4f", table[i][j] );
00097         if (j < N-1)
00098           printf(", ");
00099       }
00100       printf("\n");
00101       x = x + 1.0;
00102     }    
00103   }

void polyinterp::printTables ( ) [inline, private]
 

Print the 4-point and 2-point polynomial coefficient tables.

Definition at line 110 of file polyinterp.h.

00111   {
00112     printTable( fourPointTable, 4 );
00113     printTable( twoPointTable, 2 );
00114     printf("\n");
00115   } // printTables


Member Data Documentation

double polyinterp::fourPointTable [private]
 

Definition at line 35 of file polyinterp.h.

double polyinterp::twoPointTable [private]
 

Definition at line 36 of file polyinterp.h.


The documentation for this class was generated from the following file:
Generated at Sun Aug 18 16:56:42 2002 for Wavelet Spectral Analysis by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001