gsl_multifit_nlin.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* multifit_nlin/gsl_multifit_nlin.h
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 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. #ifndef __GSL_MULTIFIT_NLIN_H__
  20. #define __GSL_MULTIFIT_NLIN_H__
  21. #include <stdlib.h>
  22. #include "gsl_types.h"
  23. #include "gsl_math.h"
  24. #include "gsl_vector.h"
  25. #include "gsl_matrix.h"
  26. #undef __BEGIN_DECLS
  27. #undef __END_DECLS
  28. #ifdef __cplusplus
  29. # define __BEGIN_DECLS extern "C" {
  30. # define __END_DECLS }
  31. #else
  32. # define __BEGIN_DECLS /* empty */
  33. # define __END_DECLS /* empty */
  34. #endif
  35. __BEGIN_DECLS
  36. int gsl_multifit_gradient (const gsl_matrix * J, const gsl_vector * f,
  37. gsl_vector * g);
  38. int gsl_multifit_covar (const gsl_matrix * J, double epsrel, gsl_matrix * covar);
  39. /* Definition of vector-valued functions with parameters based on gsl_vector */
  40. struct gsl_multifit_function_struct
  41. {
  42. int (* f) (const gsl_vector * x, void * params, gsl_vector * f);
  43. size_t n; /* number of functions */
  44. size_t p; /* number of independent variables */
  45. void * params;
  46. };
  47. typedef struct gsl_multifit_function_struct gsl_multifit_function ;
  48. #define GSL_MULTIFIT_FN_EVAL(F,x,y) (*((F)->f))(x,(F)->params,(y))
  49. typedef struct
  50. {
  51. const char *name;
  52. size_t size;
  53. int (*alloc) (void *state, size_t n, size_t p);
  54. int (*set) (void *state, gsl_multifit_function * function, gsl_vector * x, gsl_vector * f, gsl_vector * dx);
  55. int (*iterate) (void *state, gsl_multifit_function * function, gsl_vector * x, gsl_vector * f, gsl_vector * dx);
  56. void (*free) (void *state);
  57. }
  58. gsl_multifit_fsolver_type;
  59. typedef struct
  60. {
  61. const gsl_multifit_fsolver_type * type;
  62. gsl_multifit_function * function ;
  63. gsl_vector * x ;
  64. gsl_vector * f ;
  65. gsl_vector * dx ;
  66. void *state;
  67. }
  68. gsl_multifit_fsolver;
  69. gsl_multifit_fsolver *
  70. gsl_multifit_fsolver_alloc (const gsl_multifit_fsolver_type * T,
  71. size_t n, size_t p);
  72. void gsl_multifit_fsolver_free (gsl_multifit_fsolver * s);
  73. int gsl_multifit_fsolver_set (gsl_multifit_fsolver * s,
  74. gsl_multifit_function * f,
  75. const gsl_vector * x);
  76. int gsl_multifit_fsolver_iterate (gsl_multifit_fsolver * s);
  77. const char * gsl_multifit_fsolver_name (const gsl_multifit_fsolver * s);
  78. gsl_vector * gsl_multifit_fsolver_position (const gsl_multifit_fsolver * s);
  79. /* Definition of vector-valued functions and gradient with parameters
  80. based on gsl_vector */
  81. struct gsl_multifit_function_fdf_struct
  82. {
  83. int (* f) (const gsl_vector * x, void * params, gsl_vector * f);
  84. int (* df) (const gsl_vector * x, void * params, gsl_matrix * df);
  85. int (* fdf) (const gsl_vector * x, void * params, gsl_vector * f, gsl_matrix *df);
  86. size_t n; /* number of functions */
  87. size_t p; /* number of independent variables */
  88. void * params;
  89. };
  90. typedef struct gsl_multifit_function_fdf_struct gsl_multifit_function_fdf ;
  91. #define GSL_MULTIFIT_FN_EVAL_F(F,x,y) ((*((F)->f))(x,(F)->params,(y)))
  92. #define GSL_MULTIFIT_FN_EVAL_DF(F,x,dy) ((*((F)->df))(x,(F)->params,(dy)))
  93. #define GSL_MULTIFIT_FN_EVAL_F_DF(F,x,y,dy) ((*((F)->fdf))(x,(F)->params,(y),(dy)))
  94. typedef struct
  95. {
  96. const char *name;
  97. size_t size;
  98. int (*alloc) (void *state, size_t n, size_t p);
  99. int (*set) (void *state, gsl_multifit_function_fdf * fdf, gsl_vector * x, gsl_vector * f, gsl_matrix * J, gsl_vector * dx);
  100. int (*iterate) (void *state, gsl_multifit_function_fdf * fdf, gsl_vector * x, gsl_vector * f, gsl_matrix * J, gsl_vector * dx);
  101. void (*free) (void *state);
  102. }
  103. gsl_multifit_fdfsolver_type;
  104. typedef struct
  105. {
  106. const gsl_multifit_fdfsolver_type * type;
  107. gsl_multifit_function_fdf * fdf ;
  108. gsl_vector * x;
  109. gsl_vector * f;
  110. gsl_matrix * J;
  111. gsl_vector * dx;
  112. void *state;
  113. }
  114. gsl_multifit_fdfsolver;
  115. gsl_multifit_fdfsolver *
  116. gsl_multifit_fdfsolver_alloc (const gsl_multifit_fdfsolver_type * T,
  117. size_t n, size_t p);
  118. int
  119. gsl_multifit_fdfsolver_set (gsl_multifit_fdfsolver * s,
  120. gsl_multifit_function_fdf * fdf,
  121. const gsl_vector * x);
  122. int
  123. gsl_multifit_fdfsolver_iterate (gsl_multifit_fdfsolver * s);
  124. void
  125. gsl_multifit_fdfsolver_free (gsl_multifit_fdfsolver * s);
  126. const char * gsl_multifit_fdfsolver_name (const gsl_multifit_fdfsolver * s);
  127. gsl_vector * gsl_multifit_fdfsolver_position (const gsl_multifit_fdfsolver * s);
  128. int gsl_multifit_test_delta (const gsl_vector * dx, const gsl_vector * x,
  129. double epsabs, double epsrel);
  130. int gsl_multifit_test_gradient (const gsl_vector * g, double epsabs);
  131. /* extern const gsl_multifit_fsolver_type * gsl_multifit_fsolver_gradient; */
  132. GSL_VAR const gsl_multifit_fdfsolver_type * gsl_multifit_fdfsolver_lmder;
  133. GSL_VAR const gsl_multifit_fdfsolver_type * gsl_multifit_fdfsolver_lmsder;
  134. __END_DECLS
  135. #endif /* __GSL_MULTIFIT_NLIN_H__ */