Loading [MathJax]/extensions/TeX/AMSsymbols.js
LAL 7.7.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
FindRoot.h
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Jolien Creighton, Kipp Cannon
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20#ifndef _FINDROOT_H
21#define _FINDROOT_H
22
23#include <lal/LALDatatypes.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29
30/**
31 * \defgroup FindRoot_h Header FindRoot.h
32 * \ingroup lal_utilities
33 *
34 * \brief Root finding routines.
35 *
36 * ### Synopsis ###
37 *
38 * \code
39 * #include <lal/FindRoot.h>
40 * \endcode
41 *
42 * This header covers the routines for root finding.
43 *
44 * ### Description ###
45 *
46 * The routine <tt>LALSBracketRoot()</tt> expands the specified domain until a root
47 * is contained. The routine <tt>LALDBracketRoot()</tt> is the same but for a
48 * double-precision function.
49 *
50 * The routine <tt>LALSBisectionFindRoot()</tt> bisects the domain (which must contain one
51 * root) until the root is found with the desired accuracy. The routine
52 * <tt>LALDBisectionFindRoot()</tt> is the same but for a double-precision function.
53 *
54 * ### Operating Instructions ###
55 *
56 * Suppose we want to find the root of the function \f$y = F(x;y_0) = y_0 + x^2\f$.
57 * Define the function:
58 * \code
59 * static void F( LALStatus *status, REAL4 *y, REAL4 x, void *y0 )
60 * {
61 * INITSTATUS(status);
62 * ASSERT( y0, status, 1, "Null pointer" );
63 * y = *(REAL4 *)y0 + x*x;
64 * RETURN( status );
65 * }
66 * \endcode
67 *
68 * Then use the following code to bracket and find the root \f$x_0=1\f$ where
69 * \f$F(x_0;y_0=-1)=0\f$:
70 * \code
71 * static LALStatus status;
72 * SFindRootIn input;
73 * REAL4 y0;
74 * REAL4 x0;
75 *
76 * y0 = -1;
77 * input.function = F;
78 * input.xmin = 0.1;
79 * input.xmax = 0.2;
80 * input.xacc = 1e-5;
81 *
82 * /\* expand domain until a root is bracketed *\/
83 * LALSBracketRoot( &status, &input, &y0 );
84 *
85 * /\* bisect domain until root is found *\/
86 * LALSBisectionFindRoot( &status, &x0, &input, &y0 );
87 * \endcode
88 *
89 * ### Algorithm ###
90 *
91 * This is an implementation of the root bracketing and bisection finding
92 * routines \c zbrac and \c rtbis in Numerical Recipes \cite ptvf1992 .
93 *
94 */
95/** @{ */
96
97/** \name Error Codes */
98/** @{ */
99#define FINDROOTH_ENULL 1 /**< Null pointer */
100#define FINDROOTH_EIDOM 2 /**< Invalid initial domain */
101#define FINDROOTH_EMXIT 4 /**< Maximum iterations exceeded */
102#define FINDROOTH_EBRKT 8 /**< Root not bracketed */
103/** @} */
104
105/** \cond DONT_DOXYGEN */
106#define FINDROOTH_MSGENULL "Null pointer"
107#define FINDROOTH_MSGEIDOM "Invalid initial domain"
108#define FINDROOTH_MSGEMXIT "Maximum iterations exceeded"
109#define FINDROOTH_MSGEBRKT "Root not bracketed"
110/** \endcond */
111
112/**
113 * These are function pointers to functions that map REAL4 numbers to REAL4 numbers.
114 */
115typedef struct
116tagSFindRootIn
117{
118 void (*function)(LALStatus *s, REAL4 *y, REAL4 x, void *p); /**< The function to find the root of */
119 REAL4 xmax; /**< The maximum value of the domain interval to look for the root */
120 REAL4 xmin; /**< The minimum value of the domain interval to look for the root */
121 REAL4 xacc; /**< The accuracy desired for the root */
122}
124
125/**
126 * These are function pointers to functions that map REAL8 numbers to REAL8 numbers.
127 */
128typedef struct
129tagDFindRootIn
130{
131 void (*function)(LALStatus *s, REAL8 *y, REAL8 x, void *p); /**< The function to find the root of */
132 REAL8 xmax; /**< The maximum value of the domain interval to look for the root */
133 REAL8 xmin; /**< The minimum value of the domain interval to look for the root */
134 REAL8 xacc; /**< The accuracy desired for the root */
135}
137
138/* ----- FindRoot.c ----- */
139void
142 SFindRootIn *inout,
143 void *params
144 );
145
146int
148 REAL8 (*y)(REAL8, void *),
149 REAL8 *xmin,
150 REAL8 *xmax,
151 void *params
152);
153
154void
157 DFindRootIn *inout,
158 void *params
159 );
160
161void
164 REAL4 *root,
165 SFindRootIn *input,
166 void *params
167 );
168
169REAL8
171 REAL8 (*y)(REAL8, void *),
172 REAL8 xmin,
173 REAL8 xmax,
174 REAL8 xacc,
175 void *params
176);
177
178void
181 REAL8 *root,
182 DFindRootIn *input,
183 void *params
184 );
185
186/** @} */
187
188#ifdef __cplusplus
189}
190#endif
191
192#endif /* _FINDROOT_H */
void LALDBracketRoot(LALStatus *status, DFindRootIn *inout, void *params)
Definition: FindRoot.c:147
void LALSBracketRoot(LALStatus *status, SFindRootIn *inout, void *params)
Definition: FindRoot.c:29
REAL8 XLALDBisectionFindRoot(REAL8(*y)(REAL8, void *), REAL8 xmin, REAL8 xmax, REAL8 xacc, void *params)
Definition: FindRoot.c:308
int XLALDBracketRoot(REAL8(*y)(REAL8, void *), REAL8 *xmin, REAL8 *xmax, void *params)
Definition: FindRoot.c:97
void LALDBisectionFindRoot(LALStatus *status, REAL8 *root, DFindRootIn *input, void *params)
Definition: FindRoot.c:381
void LALSBisectionFindRoot(LALStatus *status, REAL4 *root, SFindRootIn *input, void *params)
Definition: FindRoot.c:215
double REAL8
Double precision real floating-point number (8 bytes).
float REAL4
Single precision real floating-point number (4 bytes).
These are function pointers to functions that map REAL8 numbers to REAL8 numbers.
Definition: FindRoot.h:130
REAL8 xacc
The accuracy desired for the root.
Definition: FindRoot.h:134
REAL8 xmax
The maximum value of the domain interval to look for the root.
Definition: FindRoot.h:132
REAL8 xmin
The minimum value of the domain interval to look for the root.
Definition: FindRoot.h:133
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947
These are function pointers to functions that map REAL4 numbers to REAL4 numbers.
Definition: FindRoot.h:117
REAL4 xacc
The accuracy desired for the root.
Definition: FindRoot.h:121
REAL4 xmax
The maximum value of the domain interval to look for the root.
Definition: FindRoot.h:119
REAL4 xmin
The minimum value of the domain interval to look for the root.
Definition: FindRoot.h:120