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
00043 using namespace std ;
00044
00045 #include <stdlib.h>
00046 #include <stdio.h>
00047 #include <string.h>
00048 #include <math.h>
00049
00050 #include "grid.h"
00051 #include "plot.h"
00052
00053 void petite_pause() ;
00054 double ff(double x) ;
00055
00056 int main() {
00057
00058
00059 int ng = 1000 ;
00060 double* xg = new double[ng] ;
00061 double* yg = new double[ng] ;
00062 for (int j=0; j<ng; j++) xg[j] = -1. + 2. * double(j) / double(ng-1) ;
00063
00064
00065 for (int j=0; j<ng; j++) yg[j] = ff(xg[j]) ;
00066
00067 int nfig0 = 0 ;
00068 plot_profile(yg, ng, 1, 1, nfig0, -0.5, 1.5, "Interpolation of 1/(1+25x\\u2\\d)") ;
00069
00070
00071
00072 for (int k = 0; k<6; k++) {
00073
00074 int nb_nodes = 4*(k+1) + 1 ;
00075 int nn = nb_nodes - 1 ;
00076
00077 int nfig1 = k+1 ;
00078
00079 Grid_uniform xcoloc(nb_nodes) ;
00080
00081
00082
00083 cout << "Grid: " << xcoloc << endl ;
00084
00085
00086
00087 for (int j=0; j<ng; j++) yg[j] = ff(xg[j]) ;
00088
00089 char title[180] ;
00090 strcpy(title, "Interpolation of 1/(1+25x\\u2\\d) , N = ") ;
00091 char string_nn[4] ;
00092 sprintf(string_nn, "%d", nn) ;
00093 strcat(title, string_nn) ;
00094 plot_profile(yg, ng, 1, 1, nfig1, -0.5, 1.5, title) ;
00095
00096 for (int j=0; j<ng; j++) yg[j] = xcoloc.interpole(ff, xg[j]) ;
00097
00098 plot_profile(yg, ng, k%15+2, 2, nfig0) ;
00099 plot_profile(yg, ng, 2, 1, nfig1) ;
00100
00101 xcoloc.plot(2, nfig1) ;
00102
00103 }
00104
00105 petite_pause() ;
00106
00107 plot_close_all() ;
00108
00109 delete [] xg ;
00110 delete [] yg ;
00111
00112 return EXIT_SUCCESS ;
00113 }
00114
00115 void petite_pause() {
00116 cout.flush() ;
00117 cout << "Continue = 'return'" << endl ;
00118 char cret ;
00119 cin.get(cret) ;
00120 }
00121
00122
00123 double ff(double x) {
00124
00125
00126 return 1. / (1. + 25.*x*x) ;
00127
00128
00129 }
00130