#include <polyinterp.h>
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] |
Definition at line 32 of file polyinterp.h.
|
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 |
|
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 |
|
For the polynomial interpolation point x-coordinate x, return the associated polynomial interpolation 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 |
|
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.
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 |
|
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.
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 |
|
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 } |
|
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 |
|
Definition at line 35 of file polyinterp.h. |
|
Definition at line 36 of file polyinterp.h. |