LORENE
zero_premier.C
1/*
2 * Locates the first zero of a function in a given interval.
3 *
4 */
5
6/*
7 * Copyright (c) 1999-2001 Eric Gourgoulhon
8 *
9 * This file is part of LORENE.
10 *
11 * LORENE is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * LORENE is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with LORENE; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27
28char zero_premier_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Utilities/zero_premier.C,v 1.3 2014/10/13 08:53:32 j_novak Exp $" ;
29
30/*
31 * $Id: zero_premier.C,v 1.3 2014/10/13 08:53:32 j_novak Exp $
32 * $Log: zero_premier.C,v $
33 * Revision 1.3 2014/10/13 08:53:32 j_novak
34 * Lorene classes and functions now belong to the namespace Lorene.
35 *
36 * Revision 1.2 2002/10/16 14:37:12 j_novak
37 * Reorganization of #include instructions of standard C++, in order to
38 * use experimental version 3 of gcc.
39 *
40 * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon
41 * LORENE
42 *
43 * Revision 1.2 2000/01/04 10:57:51 eric
44 * Le test f1*f2 < 0. est remplace par f1*f2 <= double(0).
45 *
46 * Revision 1.1 1999/12/24 13:00:10 eric
47 * Initial revision
48 *
49 *
50 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Utilities/zero_premier.C,v 1.3 2014/10/13 08:53:32 j_novak Exp $
51 *
52 */
53
54// Headers Lorene
55#include "headcpp.h"
56#include "param.h"
57//****************************************************************************
58
59namespace Lorene {
60
61bool zero_premier(double (*f)(double, const Param&), const Param& par,
62 double a, double b, int n, double& a0, double& b0) {
63
64 double dx = (b-a)/double(n) ;
65
66 a0 = a ;
67 b0 = a0 + dx ;
68
69 double f1 = f(a0, par) ;
70 bool trouve = false ;
71
72 for (int i=0; i<n; i++) {
73 double f2 = f(b0, par) ;
74 if (f1*f2 <= double(0)) { // on a encadre le zero
75 trouve = true ;
76 break ;
77 }
78
79 // On passe au sous-intervalle suivant :
80 a0 = b0 ;
81 f1 = f2 ;
82 b0 += dx ;
83 }
84
85 return trouve ;
86
87}
88}
Time evolution with partial storage (*** under development ***).
Definition evolution.h:371
Parameter storage.
Definition param.h:125
bool zero_premier(double(*f)(double, const Param &), const Param &par, double a, double b, int n, double &a0, double &b0)
Locates the sub-interval containing the first zero of a function in a given interval.
Lorene prototypes.
Definition app_hor.h:64