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 #include <iostream>
00040
00041 using namespace std ;
00042
00043 #include <stdlib.h>
00044 #include <math.h>
00045
00046 #include "grid.h"
00047 #include "plot.h"
00048
00049 void petite_pause() ;
00050 double ff(double x) ;
00051
00052 int main() {
00053
00054
00055 int ng = 1000 ;
00056 double* xg = new double[ng] ;
00057 double* yg = new double[ng] ;
00058 for (int j=0; j<ng; j++) xg[j] = -1. + 2. * double(j) / double(ng-1) ;
00059
00060
00061 int nb_nodes = 1 ;
00062 while (nb_nodes > 0) {
00063 cout << "Number of nodes ? (negative value = exit) " << endl ;
00064 cin >> nb_nodes ;
00065 while ( cin.get()!='\n' ) ;
00066 if (nb_nodes <= 0) continue ;
00067
00068 int nn = nb_nodes - 1 ;
00069
00070 double* xx = new double[nb_nodes] ;
00071 for (int i=0; i<=nn; i++) xx[i] = -1 + 2 * double(i) / double(nn) ;
00072
00073 Grid xcoloc(nb_nodes,xx) ;
00074
00075 cout << "Grid: " << xcoloc << endl ;
00076 cout << "Lebesgue constant : " << xcoloc.lebesgue_constant() << endl ;
00077 int nfig = 0 ;
00078
00079
00080
00081
00082 for (int i=0; i<=nn; i++) {
00083 for (int j=0; j<ng; j++) yg[j] = xcoloc.lagrange(i, xg[j]) ;
00084
00085 plot_profile(yg, ng, i%15+2, 1, nfig, -3., 3., "Lagrange polynomials") ;
00086 xcoloc.plot(1, nfig) ;
00087 plot_point(xcoloc(i), 0., i%15+2, nfig) ;
00088 double xp = xcoloc(i) ;
00089 double yp = xcoloc.lagrange(i, xp) ;
00090 plot_point_set(1, &xp, &yp, i%15+2, nfig) ;
00091
00092
00093 }
00094
00095
00096
00097 for (int j=0; j<ng; j++) yg[j] = xcoloc.nodal_polynomial(xg[j]) ;
00098
00099 nfig++ ;
00100 plot_profile(yg, ng, 2, 1, nfig, -0.1, 0.1, "Nodal polynomial") ;
00101 xcoloc.plot(2, nfig) ;
00102
00103
00104
00105 for (int j=0; j<ng; j++) {
00106 yg[j] = ff(xg[j]) ;
00107 }
00108 nfig++ ;
00109
00110 plot_profile(yg, ng, 3, 1, nfig, -1.2, 1.2, "Interpolation of cos(2 exp(x))") ;
00111
00112 for (int j=0; j<ng; j++) {
00113 yg[j] = xcoloc.interpole(ff, xg[j]) ;
00114 }
00115 plot_profile(yg, ng, 2, 1, nfig) ;
00116 xcoloc.plot(2, nfig) ;
00117
00118 petite_pause() ;
00119
00120 plot_close_all() ;
00121
00122 delete [] xx ;
00123
00124 }
00125
00126 delete [] xg ;
00127 delete [] yg ;
00128
00129 return EXIT_SUCCESS ;
00130 }
00131
00132
00133 void petite_pause() {
00134 cout.flush() ;
00135 cout << "Continue = 'return'" << endl ;
00136 char cret ;
00137 cin.get(cret) ;
00138 }
00139
00140
00141 double ff(double x) {
00142
00143 return cos(exp(2*x)) ;
00144 }