/* ATK IV - Numerical Programming (2006) */ /* Excercise 3.4 - Chebysev Polynomial Expansion */ #include<stdio.h> #include<math.h> #define NRANSI #include<nr.h> #define DEG 10 float f(float x); int main(void){ float a = -2.0; float b = 2.0; int n = 7; float c[DEG]; float x, y, h; int i, d; chebft(a,b,c,n,f); x=a; d=50; h=(b-a)/(1.0*d); for(i=0;i<d;i++){ y = chebev(a,b,c,n,x); printf("%f %f %f %E\n",x,y,f(x),fabs(f(x)-y)); x += h; } return 0; } float f(float x){ return tanh(x);}