2 #include <gsl/gsl_errno.h>
3 #include <gsl/gsl_math.h>
4 #include <gsl/gsl_roots.h>
13 int iter = 0, max_iter = 100;
14 const gsl_root_fdfsolver_type *T;
15 gsl_root_fdfsolver *s;
16 double x0, x = 5.0, r_expected = sqrt (5.0);
18 struct quadratic_params params = {1.0, 0.0, -5.0};
21 FDF.df = &quadratic_deriv;
22 FDF.fdf = &quadratic_fdf;
25 T = gsl_root_fdfsolver_newton;
26 s = gsl_root_fdfsolver_alloc (T);
27 gsl_root_fdfsolver_set (s, &FDF, x);
29 printf ("using %s method\n",
30 gsl_root_fdfsolver_name (s));
32 printf ("%-5s %10s %10s %10s\n",
33 "iter", "root", "err", "err(est)");
37 status = gsl_root_fdfsolver_iterate (s);
39 x = gsl_root_fdfsolver_root (s);
40 status = gsl_root_test_delta (x, x0, 0, 1e-3);
42 if (status == GSL_SUCCESS)
43 printf ("Converged:\n");
45 printf ("%5d %10.7f %+10.7f %10.7f\n",
46 iter, x, x - r_expected, x - x0);
48 while (status == GSL_CONTINUE && iter < max_iter);
50 gsl_root_fdfsolver_free (s);