00001 #include "chebyshev.h"
00002 #include "tnt_array1d.h"
00003 #include "tnt_array2d.h"
00004 #include "chebyshev_fit.h"
00005 #include "lsqrinvert.h"
00006
00007 using namespace TNT;
00008
00009 double CChebyshevDataFit::Error(double x) const{
00010 return 0.0;
00011 }
00012
00013
00014 void CChebyshevDataFit::ChiSquareFitCoeffs(const Array1D<double> &x,
00015 const Array1D<double> &y,const Array1D<double> &dy){
00016
00017
00018 int M=x.dim(), N=nc;
00019 Array2D<double> T(M,N);
00020
00021
00022 double midpt=0.5*(uplim+lolim);
00023 double halfrange=0.5*(uplim-lolim);
00024
00025
00026 {
00027 double xx;int i,j;
00028 for (i=0;i<M;i++){
00029 xx=(x[i]-midpt)/halfrange;
00030 T[i][0]=ChebyshevPolynomial(0,xx)-0.5;
00031 for (j=1;j<N;j++){
00032 T[i][j]=ChebyshevPolynomial(j,xx);
00033 }
00034 }
00035 }
00036
00037 Array1D<double> new_c(N);
00038 Array2D<double> new_cov(N,N);
00039
00040 LeastSquaresInvert(y,dy,T,new_c,new_cov);
00041
00042 c=new_c;
00043 d2c=new_cov;
00044 }
00045
00046 void CChebyshevDataFit::ChiSquareFitCoeffs(const Array1D<double> &x,
00047 const Array1D<double> &y,const Array2D<double> &covy){
00048
00049
00050 int M=x.dim(), N=nc;
00051 Array2D<double> T(M,N);
00052
00053
00054 double midpt=0.5*(uplim+lolim);
00055 double halfrange=0.5*(uplim-lolim);
00056
00057
00058 {
00059 double xx;int i,j;
00060 for (i=0;i<M;i++){
00061 xx=(x[i]-midpt)/halfrange;
00062 T[i][0]=ChebyshevPolynomial(0,xx)-0.5;
00063 for (j=1;j<N;j++){
00064 T[i][j]=ChebyshevPolynomial(j,xx);
00065 }
00066 }
00067 }
00068
00069 Array1D<double> new_c(N);
00070 Array2D<double> new_cov(N,N);
00071
00072 LeastSquaresInvert(y,covy,T,new_c,new_cov);
00073
00074 c=new_c;
00075 d2c=new_cov;
00076 }