00001 #if !defined CHEBYSHEV_H
00002 #define CHEBYSHEV_H
00003
00004 #if !defined PI
00005 #define PI 3.141592653589793
00006 #endif
00007
00008 #include <iostream>
00009 #include "tnt_array1d.h"
00010 #include "tnt_array2d.h"
00011
00012 using namespace TNT;
00013 using namespace std;
00014
00015 double ChebyshevPolynomial(int n, double x);
00016
00017 class CChebyshevApprox1D{
00018
00019
00020 friend ostream& operator<<(ostream &s, const CChebyshevApprox1D &A);
00021 friend istream& operator>>(istream &s, CChebyshevApprox1D &A);
00022
00023 public:
00024
00025
00026 CChebyshevApprox1D(void) {nc = 0;uplim = 0.0;lolim = 0.0;this->RunLoud();};
00027 CChebyshevApprox1D(
00028 double upperlimit, double lowerlimit,
00029 int ncoeff, double (*func)(double, void*), void *pars)
00030 {this->Setup(upperlimit,lowerlimit,ncoeff,func,pars);this->RunLoud();};
00031 CChebyshevApprox1D(
00032 double upperlimit, double lowerlimit,
00033 int ncoeff, const Array1D<double> &controlpts,
00034 const Array1D<double> &ftnvals){this->SetupFit(upperlimit, lowerlimit,
00035 ncoeff, controlpts, ftnvals);this->RunLoud();};
00036
00037 ~CChebyshevApprox1D(void) {};
00038
00039 CChebyshevApprox1D Copy(const CChebyshevApprox1D &A);
00040 CChebyshevApprox1D operator=(const CChebyshevApprox1D &A)
00041 {this->Copy(A); return *this;};
00042
00043 int Ncoeffs(void) const {return nc;};
00044 double Upperlimit(void) const {return uplim;};
00045 double Lowerlimit(void) const {return lolim;};
00046 double Coeff(int i) const {return c[i];};
00047 Array1D<double> CoeffVector(void) const {return c;};
00048
00049 void SetParameters(double upperlimit, double lowerlimit, int ncoeff);
00050 void Setup(
00051 double upperlimit, double lowerlimit,
00052 int ncoeff, double (*func)(double, void*), void *pars);
00053 void Setup(
00054 double upperlimit, double lowerlimit,
00055 int ncoeff, Array1D<double> coeffs);
00056 void SetupFit(
00057 double upperlimit, double lowerlimit,
00058 int ncoeff, const Array1D<double> &controlpts,
00059 const Array1D<double> &ftnvals);
00060
00061 double ColocPoint(int i) const;
00062
00063 double Val(double x, int m) const;
00064 double Val(double x) const {return this->Val(x,this->nc);};
00065 double operator()(double x, int m) const {return this->Val(x,m);};
00066 double operator()(double x) const {return this->Val(x,this->nc);};
00067
00068 CChebyshevApprox1D Derivative(void) const;
00069 CChebyshevApprox1D Integral(void) const;
00070
00071 void RunQuiet(void) {quiet=true;}
00072 void RunLoud(void) {quiet=false;}
00073
00074 protected:
00075
00076 int nc;
00077 double uplim, lolim;
00078 Array1D<double> c;
00079 bool quiet;
00080
00081 };
00082
00083
00084 class CChebyshevApprox2D{
00085
00086
00087 friend ostream& operator<<(ostream &s, const CChebyshevApprox2D &A);
00088 friend istream& operator>>(istream &s, CChebyshevApprox2D &A);
00089
00090 public:
00091
00092
00093 CChebyshevApprox2D(void);
00094 CChebyshevApprox2D(
00095 double upperlimit_x, double lowerlimit_x,
00096 double upperlimit_y, double lowerlimit_y,
00097 int ncoeff_x, int ncoeff_y,
00098 double (*func)(double, double, void*), void *pars)
00099 {this->Setup(
00100 upperlimit_x,lowerlimit_x,
00101 upperlimit_y,lowerlimit_y,
00102 ncoeff_x,ncoeff_y,func,pars);
00103 };
00104 CChebyshevApprox2D(
00105 double upperlimit_x, double lowerlimit_x,
00106 double upperlimit_y, double lowerlimit_y,
00107 int ncoeff_x, int ncoeff_y,
00108 const Array1D<double> &x_controlpts,
00109 const Array1D<double> &y_controlpts,
00110 const Array2D<double> &ftnvals)
00111 {this->SetupFit(
00112 upperlimit_x,lowerlimit_x,
00113 upperlimit_y,lowerlimit_y,
00114 ncoeff_x,ncoeff_y,
00115 x_controlpts,y_controlpts,ftnvals);
00116 };
00117
00118 ~CChebyshevApprox2D(void) {};
00119
00120 CChebyshevApprox2D Copy(const CChebyshevApprox2D &A);
00121 CChebyshevApprox2D operator=(const CChebyshevApprox2D &A)
00122 {this->Copy(A); return *this;};
00123
00124 int Ncoeffs_x(void) const {return nc_x;};
00125 double Upperlimit_x(void) const {return uplim_x;};
00126 double Lowerlimit_x(void) const {return lolim_x;};
00127 int Ncoeffs_y(void) const {return nc_y;};
00128 double Upperlimit_y(void) const {return uplim_y;};
00129 double Lowerlimit_y(void) const {return lolim_y;};
00130 double Coeff(int i, int j) const {return c[i][j];};
00131 Array2D<double> CoeffMatrix(void) const {return c;};
00132
00133 void SetParameters(
00134 double upperlimit_x, double lowerlimit_x,
00135 double upperlimit_y, double lowerlimit_y,
00136 int ncoeff_x, int ncoeff_y);
00137 void Setup(
00138 double upperlimit_x, double lowerlimit_x,
00139 double upperlimit_y, double lowerlimit_y,
00140 int ncoeff_x, int ncoeff_y,
00141 double (*func)(double, double, void*), void *pars);
00142 void SetupFit(
00143 double upperlimit_x, double lowerlimit_x,
00144 double upperlimit_y, double lowerlimit_y,
00145 int ncoeff_x, int ncoeff_y,
00146 const Array1D<double> &x_controlpts,
00147 const Array1D<double> &y_controlpts,
00148 const Array2D<double> &ftnvals);
00149
00150 double ColocPoint_x(int i) const;
00151 double ColocPoint_y(int i) const;
00152
00153 double Val(double x, double y, int m_x, int m_y) const;
00154 double Val(double x, double y) const
00155 {return this->Val(x,y,this->nc_x,this->nc_y);};
00156 double operator()(double x, double y, int m_x, int m_y) const
00157 {return this->Val(x,y,m_x,m_y);};
00158 double operator()(double x, double y) const
00159 {return this->Val(x,y,this->nc_x,this->nc_y);};
00160
00161 protected:
00162
00163 int nc_x,nc_y;
00164 double uplim_x, lolim_x;
00165 double uplim_y, lolim_y;
00166 Array2D<double> c;
00167
00168 };
00169
00170 #endif