3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Reid Priedhorsky, Brian Gough
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <gsl/gsl_errno.h>
24 #include <gsl/gsl_roots.h>
27 gsl_root_fsolver_alloc (const gsl_root_fsolver_type * T)
29 gsl_root_fsolver * s = (gsl_root_fsolver *) malloc (sizeof (gsl_root_fsolver));
33 GSL_ERROR_VAL ("failed to allocate space for root solver struct",
37 s->state = malloc (T->size);
41 free (s); /* exception in constructor, avoid memory leak */
43 GSL_ERROR_VAL ("failed to allocate space for root solver state",
54 gsl_root_fsolver_set (gsl_root_fsolver * s, gsl_function * f, double x_lower, double x_upper)
56 if (x_lower > x_upper)
58 GSL_ERROR ("invalid interval (lower > upper)", GSL_EINVAL);
62 s->root = 0.5 * (x_lower + x_upper); /* initial estimate */
66 return (s->type->set) (s->state, s->function, &(s->root), x_lower, x_upper);
70 gsl_root_fsolver_iterate (gsl_root_fsolver * s)
72 return (s->type->iterate) (s->state,
73 s->function, &(s->root),
74 &(s->x_lower), &(s->x_upper));
78 gsl_root_fsolver_free (gsl_root_fsolver * s)
85 gsl_root_fsolver_name (const gsl_root_fsolver * s)
91 gsl_root_fsolver_root (const gsl_root_fsolver * s)
97 gsl_root_fsolver_x_lower (const gsl_root_fsolver * s)
103 gsl_root_fsolver_x_upper (const gsl_root_fsolver * s)