zero_premier.C

00001 /*
00002  *  Locates the first zero of a function in a given interval.
00003  *
00004  */
00005 
00006 /*
00007  *   Copyright (c) 1999-2001 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 char zero_premier_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Utilities/zero_premier.C,v 1.2 2002/10/16 14:37:12 j_novak Exp $" ;
00029 
00030 /*
00031  * $Id: zero_premier.C,v 1.2 2002/10/16 14:37:12 j_novak Exp $
00032  * $Log: zero_premier.C,v $
00033  * Revision 1.2  2002/10/16 14:37:12  j_novak
00034  * Reorganization of #include instructions of standard C++, in order to
00035  * use experimental version 3 of gcc.
00036  *
00037  * Revision 1.1.1.1  2001/11/20 15:19:29  e_gourgoulhon
00038  * LORENE
00039  *
00040  * Revision 1.2  2000/01/04  10:57:51  eric
00041  * Le test f1*f2 < 0. est remplace par f1*f2 <= double(0).
00042  *
00043  * Revision 1.1  1999/12/24  13:00:10  eric
00044  * Initial revision
00045  *
00046  *
00047  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Utilities/zero_premier.C,v 1.2 2002/10/16 14:37:12 j_novak Exp $
00048  *
00049  */
00050 
00051 // Headers Lorene 
00052 #include "headcpp.h"
00053 #include "param.h"
00054 //****************************************************************************
00055 
00056 bool zero_premier(double (*f)(double, const Param&), const Param& par,
00057           double a, double b, int n, double& a0, double& b0) {
00058 
00059     double dx = (b-a)/double(n) ;     
00060 
00061     a0 = a ; 
00062     b0 = a0 + dx ; 
00063 
00064     double f1 = f(a0, par) ;
00065     bool trouve = false ; 
00066     
00067     for (int i=0; i<n; i++) {
00068     double f2 = f(b0, par) ;
00069     if (f1*f2 <= double(0)) {       // on a encadre le zero
00070         trouve = true ; 
00071         break ; 
00072     } 
00073 
00074     // On passe au sous-intervalle suivant :
00075     a0 = b0 ; 
00076     f1 = f2 ;  
00077     b0 += dx ;
00078     } 
00079     
00080     return trouve ; 
00081 
00082 }

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