es.C

00001 /*
00002  * Test code for class Grid
00003  *
00004  */
00005 
00006 /*
00007  *   Copyright (c) 2005 Eric Gourgoulhon
00008  *
00009  *   This file is part of LORENE.
00010  *
00011  *   LORENE is free software; you can redistribute it and/or modify
00012  *   it under the terms of the GNU General Public License as published by
00013  *   the Free Software Foundation; either version 2 of the License, or
00014  *   (at your option) any later version.
00015  *
00016  *   LORENE is distributed in the hope that it will be useful,
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *   GNU General Public License for more details.
00020  *
00021  *   You should have received a copy of the GNU General Public License
00022  *   along with LORENE; if not, write to the Free Software
00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  *
00025  */
00026 
00027 /*
00028  * $Id: es.C,v 1.1 2005/11/14 01:56:58 e_gourgoulhon Exp $
00029  * $Log: es.C,v $
00030  * Revision 1.1  2005/11/14 01:56:58  e_gourgoulhon
00031  * First version
00032  *
00033  *
00034  * $Header: /cvsroot/Lorene/School05/Monday/es.C,v 1.1 2005/11/14 01:56:58 e_gourgoulhon Exp $
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     // For the plots
00055     int ng = 1000 ;      // Number of points to draw the curves
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     // Nodes
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) ;    // Construction of the grid 
00074     
00075     cout << "Grid: " << xcoloc << endl ; 
00076     cout << "Lebesgue constant : " << xcoloc.lebesgue_constant() << endl ; 
00077     int nfig = 0 ;  // index of next figure
00078     // xcoloc.plot(3, nfig) ;  // draws the point in 3=green
00079     
00080     // Lagrange polynomials 
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         // nfig++ ;  // new figure
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         // plot_close(nfig) ;   // Figure needs to be closed before the
00092                                 // next one if it's an EPS file. 
00093     }
00094          
00095     // Nodal polynomial
00096     
00097     for (int j=0; j<ng; j++) yg[j] = xcoloc.nodal_polynomial(xg[j]) ; 
00098 
00099     nfig++ ;   // new figure
00100     plot_profile(yg, ng, 2, 1, nfig, -0.1, 0.1, "Nodal polynomial") ; 
00101     xcoloc.plot(2, nfig) ; 
00102 
00103     // Interpolating polynomial 
00104 
00105     for (int j=0; j<ng; j++) {
00106         yg[j] = ff(xg[j]) ; 
00107     }
00108     nfig++ ;   // new figure
00109  //   plot_profile(yg, ng, 3, 1, nfig, -0.2, 1.1, "Interpolation of 1/(1+25x\\u2\\d)") ;     
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     }  // end of while
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 //    return 1. / (1. + 25.*x*x) ; 
00143     return cos(exp(2*x)) ; 
00144 }

Generated on Tue Dec 6 14:48:44 2011 for POLYNOM by  doxygen 1.4.6