LORENE
zero_list.C
1
/*
2
* Function zero_list
3
* Locates approximatively all the zeros of a function in a given interval
4
*
5
* (see file utilitaires.h for documentation)
6
*
7
*/
8
9
10
/*
11
* Copyright (c) 2003 Eric Gourgoulhon
12
*
13
* This file is part of LORENE.
14
*
15
* LORENE is free software; you can redistribute it and/or modify
16
* it under the terms of the GNU General Public License as published by
17
* the Free Software Foundation; either version 2 of the License, or
18
* (at your option) any later version.
19
*
20
* LORENE is distributed in the hope that it will be useful,
21
* but WITHOUT ANY WARRANTY; without even the implied warranty of
22
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
* GNU General Public License for more details.
24
*
25
* You should have received a copy of the GNU General Public License
26
* along with LORENE; if not, write to the Free Software
27
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
*
29
*/
30
31
char
zero_list_C[] =
"$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Utilities/zero_list.C,v 1.2 2014/10/13 08:53:32 j_novak Exp $"
;
32
33
34
/*
35
* $Id: zero_list.C,v 1.2 2014/10/13 08:53:32 j_novak Exp $
36
* $Log: zero_list.C,v $
37
* Revision 1.2 2014/10/13 08:53:32 j_novak
38
* Lorene classes and functions now belong to the namespace Lorene.
39
*
40
* Revision 1.1 2003/09/08 20:22:02 e_gourgoulhon
41
* First version
42
*
43
*
44
* $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Utilities/zero_list.C,v 1.2 2014/10/13 08:53:32 j_novak Exp $
45
*
46
*/
47
48
49
// Headers Lorene
50
#include "param.h"
51
#include "tbl.h"
52
53
//****************************************************************************
54
55
namespace
Lorene
{
56
57
void
zero_list
(
double
(*f)(
double
,
const
Param
&),
const
Param
& par,
58
double
xmin,
double
xmax,
int
nsub,
59
Tbl
*& az,
Tbl
*& bz ) {
60
61
int
nzero = 0 ;
62
63
double
dx = (xmax-xmin) /
double
(nsub) ;
64
double
f1 = f(xmin, par) ;
65
double
x1 = xmin ;
66
double
x2 = xmin + dx ;
67
68
double
* borne_inf =
new
double
[nsub] ;
// At maximum nsub zeros
69
double
* borne_sup =
new
double
[nsub] ;
70
71
for
(
int
i=0; i<nsub; i++) {
72
double
f2 = f(x2, par) ;
73
if
(f1*f2 < 0.) {
// A zero has been found
74
borne_inf[nzero] = x1 ;
75
borne_sup[nzero] = x2 ;
76
nzero += 1 ;
77
}
78
// Next sub-interval :
79
x1 = x2 ;
80
f1 = f2 ;
81
x2 += dx ;
82
}
83
84
// Result:
85
86
az =
new
Tbl
(nzero) ;
87
bz =
new
Tbl
(nzero) ;
88
89
if
(nzero > 0) {
90
91
az->
set_etat_qcq
() ;
92
bz->
set_etat_qcq
() ;
93
94
for
(
int
i=0; i<nzero; i++) {
95
az->
set
(i) = borne_inf[i] ;
96
bz->
set
(i) = borne_sup[i] ;
97
}
98
}
99
100
delete
[] borne_inf ;
101
delete
[] borne_sup ;
102
103
}
104
}
Lorene::Param
Parameter storage.
Definition
param.h:125
Lorene::Tbl
Basic array class.
Definition
tbl.h:161
Lorene::Tbl::set_etat_qcq
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition
tbl.C:361
Lorene::Tbl::set
double & set(int i)
Read/write of a particular element (index i) (1D case)
Definition
tbl.h:281
Lorene::zero_list
void zero_list(double(*f)(double, const Param &), const Param &par, double xmin, double xmax, int nsub, Tbl *&az, Tbl *&bz)
Locates approximatively all the zeros of a function in a given interval.
Definition
zero_list.C:57
Lorene
Lorene prototypes.
Definition
app_hor.h:64
C++
Source
Non_class_members
Utilities
zero_list.C
Generated by
1.12.0