zero_list.C

00001 /*
00002  * Function zero_list 
00003  * Locates approximatively all the zeros of a function in a given interval
00004  * 
00005  * (see file utilitaires.h for documentation)
00006  *
00007  */
00008 
00009 
00010 /*
00011  *   Copyright (c) 2003 Eric Gourgoulhon
00012  *
00013  *   This file is part of LORENE.
00014  *
00015  *   LORENE is free software; you can redistribute it and/or modify
00016  *   it under the terms of the GNU General Public License as published by
00017  *   the Free Software Foundation; either version 2 of the License, or
00018  *   (at your option) any later version.
00019  *
00020  *   LORENE is distributed in the hope that it will be useful,
00021  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *   GNU General Public License for more details.
00024  *
00025  *   You should have received a copy of the GNU General Public License
00026  *   along with LORENE; if not, write to the Free Software
00027  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028  *
00029  */
00030 
00031 char zero_list_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Utilities/zero_list.C,v 1.1 2003/09/08 20:22:02 e_gourgoulhon Exp $" ;
00032 
00033 
00034 /*
00035  * $Id: zero_list.C,v 1.1 2003/09/08 20:22:02 e_gourgoulhon Exp $
00036  * $Log: zero_list.C,v $
00037  * Revision 1.1  2003/09/08 20:22:02  e_gourgoulhon
00038  * First version
00039  *
00040  *
00041  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Utilities/zero_list.C,v 1.1 2003/09/08 20:22:02 e_gourgoulhon Exp $
00042  *
00043  */
00044 
00045 
00046 // Headers Lorene 
00047 #include "param.h"
00048 #include "tbl.h"
00049 
00050 //****************************************************************************
00051 
00052 void zero_list( double (*f)(double, const Param&), const Param& par,
00053         double xmin, double xmax, int nsub, 
00054         Tbl*& az, Tbl*& bz ) {
00055         
00056     int nzero = 0 ; 
00057     
00058     double dx = (xmax-xmin) / double(nsub) ;     
00059     double f1 = f(xmin, par) ;
00060     double x1 = xmin ; 
00061     double x2 = xmin + dx ; 
00062     
00063     double* borne_inf = new double[nsub] ;   // At maximum nsub zeros
00064     double* borne_sup = new double[nsub] ;      
00065     
00066     for (int i=0; i<nsub; i++) {
00067     double f2 = f(x2, par) ;
00068     if (f1*f2 < 0.) {       // A zero has been found
00069         borne_inf[nzero] = x1 ; 
00070         borne_sup[nzero] = x2 ; 
00071         nzero += 1 ;    
00072     } 
00073     // Next sub-interval :
00074     x1 = x2 ; 
00075     f1 = f2 ;  
00076     x2 += dx ;
00077     } 
00078 
00079     // Result:
00080 
00081     az = new Tbl(nzero) ; 
00082     bz = new Tbl(nzero) ; 
00083     
00084     if (nzero > 0) {
00085 
00086     az->set_etat_qcq() ; 
00087     bz->set_etat_qcq() ; 
00088 
00089     for (int i=0; i<nzero; i++) {
00090         az->set(i) = borne_inf[i] ;
00091         bz->set(i) = borne_sup[i] ;
00092     }
00093     }
00094     
00095     delete [] borne_inf ; 
00096     delete [] borne_sup ; 
00097     
00098 }  

Generated on Tue Feb 7 01:35:21 2012 for LORENE by  doxygen 1.4.6