Alex Bikfalvi
SimStream Documentation
Chebyshev.cpp
00001 #include "Headers.h" 00002 #include "Chebyshev.h" 00003 00004 int ChebEval(const ChebSeries* cs, const double x, MathResult* result) 00005 { 00006 int j; 00007 double d = 0.0; 00008 double dd = 0.0; 00009 00010 double y = (2.0*x - cs->a - cs->b) / (cs->b - cs->a); 00011 double y2 = 2.0 * y; 00012 00013 double e = 0.0; 00014 00015 for(j = cs->order; j>=1; j--) 00016 { 00017 double temp = d; 00018 d = y2*d - dd + cs->c[j]; 00019 e += fabs(y2*temp) + fabs(dd) + fabs(cs->c[j]); 00020 dd = temp; 00021 } 00022 00023 { 00024 double temp = d; 00025 d = y*d - dd + 0.5 * cs->c[0]; 00026 e += fabs(y*temp) + fabs(dd) + 0.5 * fabs(cs->c[0]); 00027 } 00028 00029 result->val = d; 00030 result->err = MATH_DBL_EPSILON * e + fabs(cs->c[cs->order]); 00031 00032 return MATH_SUCCESS; 00033 }
Last updated: February 8, 2011