Debian Codegraph @

external/gsl/gsl_roots__fdfsolver.c

raw
1 /* roots/fdfsolver.c
2 *
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Reid Priedhorsky, Brian Gough
4 *
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.
9 *
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.
14 *
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.
18 */
19
20 #include "gsl__config.h"
21 #include <stdlib.h>
22 #include <string.h>
23 #include "gsl_errno.h"
24 #include "gsl_roots.h"
25
26 gsl_root_fdfsolver *
27 gsl_root_fdfsolver_alloc (const gsl_root_fdfsolver_type * T)
28 {
29
30 gsl_root_fdfsolver * s = (gsl_root_fdfsolver *) malloc (sizeof (gsl_root_fdfsolver));
31
32 if (s == 0)
33 {
34 GSL_ERROR_VAL ("failed to allocate space for root solver struct",
35 GSL_ENOMEM, 0);
36 };
37
38 s->state = malloc (T->size);
39
40 if (s->state == 0)
41 {
42 free (s); /* exception in constructor, avoid memory leak */
43
44 GSL_ERROR_VAL ("failed to allocate space for root solver state",
45 GSL_ENOMEM, 0);
46 };
47
48 s->type = T ;
49 s->fdf = NULL;
50
51 return s;
52 }
53
54 int
55 gsl_root_fdfsolver_set (gsl_root_fdfsolver * s, gsl_function_fdf * f, double root)
56 {
57 s->fdf = f;
58 s->root = root;
59
60 return (s->type->set) (s->state, s->fdf, &(s->root));
61 }
62
63 int
64 gsl_root_fdfsolver_iterate (gsl_root_fdfsolver * s)
65 {
66 return (s->type->iterate) (s->state, s->fdf, &(s->root));
67 }
68
69 void
70 gsl_root_fdfsolver_free (gsl_root_fdfsolver * s)
71 {
72 free (s->state);
73 free (s);
74 }
75
76 const char *
77 gsl_root_fdfsolver_name (const gsl_root_fdfsolver * s)
78 {
79 return s->type->name;
80 }
81
82 double
83 gsl_root_fdfsolver_root (const gsl_root_fdfsolver * s)
84 {
85 return s->root;
86 }
87
88