00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <iostream>
00042 #include <fstream>
00043
00044 using namespace std ;
00045
00046 #include <stdlib.h>
00047 #include <math.h>
00048
00049 #include "grid.h"
00050 #include "ortho_poly.h"
00051 #include "plot.h"
00052
00053 double ff(double x) ;
00054
00055 int main() {
00056
00057
00058 int ng = 1000 ;
00059 double* xg = new double[ng] ;
00060 double* yg = new double[ng] ;
00061 double* yg0 = new double[ng] ;
00062 double* yg1 = new double[ng] ;
00063
00064 for (int j=0; j<ng; j++) xg[j] = -1. + 2. * double(j) / double(ng-1) ;
00065
00066 int nfig = -1 ;
00067
00068 ofstream fproj("err_proj.d") ;
00069 ofstream finter("err_inter.d") ;
00070
00071 int nn = 0 ;
00072 while (nn >= 0) {
00073 cout << "Maximum degree N of polynomials ? (negative value = exit) "
00074 << endl ;
00075 cin >> nn ;
00076 while ( cin.get()!='\n' ) ;
00077 if (nn < 0) continue ;
00078
00079 double* xc = new double[nn+1] ;
00080 double* yc = new double[nn+1] ;
00081
00082
00083 nfig++ ;
00084 for (int j=0; j<ng; j++) yg0[j] = ff(xg[j]) ;
00085 plot_profile(yg0, ng, 2, 1, nfig, -1.2, 1.2) ;
00086
00087
00088
00089 Chebyshev_poly poly(nn) ;
00090
00091
00092
00093 double* cf_proj = new double[nn+1] ;
00094 poly.coef_projection(ff, cf_proj) ;
00095
00096 double err = 0 ;
00097 for (int j=0; j<ng; j++) {
00098 double y = poly.series(cf_proj, xg[j]) ;
00099 double diff = fabs(y - yg0[j]) ;
00100 if (diff > err) err = diff ;
00101 yg1[j] = y ;
00102 }
00103 cout << "Error projection : " << err << endl ;
00104 fproj << nn << " " << err << endl ;
00105 plot_profile(yg1, ng, 5, 1, nfig) ;
00106
00107
00108 double* cf_inter = new double[nn+1] ;
00109 poly.coef_interpolant_GL(ff, cf_inter) ;
00110
00111 err = 0 ;
00112 for (int j=0; j<ng; j++) {
00113 double y = poly.series(cf_inter, xg[j]) ;
00114 double diff = fabs(y - yg0[j]) ;
00115 if (diff > err) err = diff ;
00116 yg[j] = y ;
00117 }
00118 cout << "Error GL interpolant : " << err << endl ;
00119 finter << nn << " " << err << endl ;
00120 plot_profile(yg, ng, 3, 1, nfig) ;
00121
00122 for (int i=0; i<=nn; i++) {
00123 xc[i] = poly.gauss_lobatto_nodes()(i) ;
00124 yc[i] = poly.gauss_lobatto_nodes().interpole(ff, xc[i]) ;
00125 }
00126 plot_point_set(nn+1, xc, yc, 3, nfig) ;
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 delete [] xc ;
00140 delete [] yc ;
00141 delete [] cf_proj ;
00142 delete [] cf_inter ;
00143
00144 }
00145
00146 plot_close_all() ;
00147
00148 fproj.close() ;
00149 finter.close() ;
00150
00151 delete [] xg ;
00152 delete [] yg ;
00153 delete [] yg0 ;
00154 delete [] yg1 ;
00155
00156 return EXIT_SUCCESS ;
00157 }
00158
00159
00160
00161 double ff(double x) {
00162
00163
00164 return cos(exp(2*x)) ;
00165 }
00166