/* test the fit to a delta function by * Chebyshev and Legendre polynormials */ #include #include #include "../gkslib/gkslib.h" #include "../iolib/message.h" #include "../const/const.h" #define N 100 main() { Gwlimit wcsz; Gwpoint curve[N]; Gwpoint postn; float *farray1(),**farray2(); float Chebyshev(); float Legpolyn(); float *f,**atb,**ata; float x0,eta,x; int i,j,p,pmax; double add; char string[120]; wcsz.xmin=-3.0; wcsz.xmax=3.0; wcsz.ymin=-2.; wcsz.ymax=3.5; gstart(&wcsz,1); gcreateseg(1); curve[1].y=curve[0].y=0.0; curve[0].x=-1.0; curve[1].x=1.0; gpolyline(2,curve); curve[1].x=curve[0].x=-1.0; curve[0].y=-0.5; curve[1].y=1.0; gpolyline(2,curve); gcloseseg(); printf("Max degree="); scanf("%d",&pmax); printf("the location of input delta function [0,1]:"); scanf("%f%*c",&x0); printf("damping="); scanf("%f%*c",&eta); gcreateseg(2); curve[1].x=curve[0].x=x0; curve[0].y=0.0; curve[1].y=1.0; gpolyline(2,curve); f=farray1(0,pmax); ata=farray2(1,pmax+1,1,pmax+1); /*RECIPES package*/ atb=farray2(1,pmax+1,1,1); /*RECIPES package*/ /* Chebyshev */ for(p=0;p<=pmax;p++) f[p]=Chebyshev(p,x0,1); for(i=1;i<=pmax+1;i++) { atb[i][1]=f[i-1]; for(j=1;j<=pmax+1;j++) ata[i][j]=f[i-1]*f[j-1]; ata[i][i]+=eta; } gaussj(ata,pmax+1,atb,1); for(i=0;i