1*5ddc57e5SXin Li /* 2*5ddc57e5SXin Li * Library: lmfit (Levenberg-Marquardt least squares fitting) 3*5ddc57e5SXin Li * 4*5ddc57e5SXin Li * File: lmmin.h 5*5ddc57e5SXin Li * 6*5ddc57e5SXin Li * Contents: Declarations for Levenberg-Marquardt minimization. 7*5ddc57e5SXin Li * 8*5ddc57e5SXin Li * Copyright: Joachim Wuttke, Forschungszentrum Juelich GmbH (2004-2013) 9*5ddc57e5SXin Li * 10*5ddc57e5SXin Li * License: see ../COPYING (FreeBSD) 11*5ddc57e5SXin Li * 12*5ddc57e5SXin Li * Homepage: apps.jcns.fz-juelich.de/lmfit 13*5ddc57e5SXin Li */ 14*5ddc57e5SXin Li 15*5ddc57e5SXin Li #ifndef LMMIN_H 16*5ddc57e5SXin Li #define LMMIN_H 17*5ddc57e5SXin Li #undef __BEGIN_DECLS 18*5ddc57e5SXin Li #undef __END_DECLS 19*5ddc57e5SXin Li #ifdef __cplusplus 20*5ddc57e5SXin Li #define __BEGIN_DECLS extern "C" { 21*5ddc57e5SXin Li #define __END_DECLS } 22*5ddc57e5SXin Li #else 23*5ddc57e5SXin Li #define __BEGIN_DECLS /* empty */ 24*5ddc57e5SXin Li #define __END_DECLS /* empty */ 25*5ddc57e5SXin Li #endif 26*5ddc57e5SXin Li 27*5ddc57e5SXin Li #include "lmstruct.h" 28*5ddc57e5SXin Li 29*5ddc57e5SXin Li __BEGIN_DECLS 30*5ddc57e5SXin Li 31*5ddc57e5SXin Li /* Levenberg-Marquardt minimization. */ 32*5ddc57e5SXin Li void lmmin(const int n_par, double* par, const int m_dat, const void* data, 33*5ddc57e5SXin Li void (*evaluate)(const double* par, const int m_dat, 34*5ddc57e5SXin Li const void* data, double* fvec, int* userbreak), 35*5ddc57e5SXin Li const lm_control_struct* control, lm_status_struct* status); 36*5ddc57e5SXin Li /* 37*5ddc57e5SXin Li * This routine contains the core algorithm of our library. 38*5ddc57e5SXin Li * 39*5ddc57e5SXin Li * It minimizes the sum of the squares of m nonlinear functions 40*5ddc57e5SXin Li * in n variables by a modified Levenberg-Marquardt algorithm. 41*5ddc57e5SXin Li * The function evaluation is done by the user-provided routine 'evaluate'. 42*5ddc57e5SXin Li * The Jacobian is then calculated by a forward-difference approximation. 43*5ddc57e5SXin Li * 44*5ddc57e5SXin Li * Parameters: 45*5ddc57e5SXin Li * 46*5ddc57e5SXin Li * n is the number of variables (INPUT, positive integer). 47*5ddc57e5SXin Li * 48*5ddc57e5SXin Li * x is the solution vector (INPUT/OUTPUT, array of length n). 49*5ddc57e5SXin Li * On input it must be set to an estimated solution. 50*5ddc57e5SXin Li * On output it yields the final estimate of the solution. 51*5ddc57e5SXin Li * 52*5ddc57e5SXin Li * m is the number of functions to be minimized (INPUT, positive integer). 53*5ddc57e5SXin Li * It must fulfill m>=n. 54*5ddc57e5SXin Li * 55*5ddc57e5SXin Li * data is a pointer that is ignored by lmmin; it is however forwarded 56*5ddc57e5SXin Li * to the user-supplied functions evaluate and printout. 57*5ddc57e5SXin Li * In a typical application, it contains experimental data to be fitted. 58*5ddc57e5SXin Li * 59*5ddc57e5SXin Li * evaluate is a user-supplied function that calculates the m functions. 60*5ddc57e5SXin Li * Parameters: 61*5ddc57e5SXin Li * n, x, m, data as above. 62*5ddc57e5SXin Li * fvec is an array of length m; on OUTPUT, it must contain the 63*5ddc57e5SXin Li * m function values for the parameter vector x. 64*5ddc57e5SXin Li * userbreak is an integer pointer. When *userbreak is set to a 65*5ddc57e5SXin Li * nonzero value, lmmin will terminate. 66*5ddc57e5SXin Li * 67*5ddc57e5SXin Li * control contains INPUT variables that control the fit algorithm, 68*5ddc57e5SXin Li * as declared and explained in lmstruct.h 69*5ddc57e5SXin Li * 70*5ddc57e5SXin Li * status contains OUTPUT variables that inform about the fit result, 71*5ddc57e5SXin Li * as declared and explained in lmstruct.h 72*5ddc57e5SXin Li */ 73*5ddc57e5SXin Li 74*5ddc57e5SXin Li /* Refined calculation of Eucledian norm. */ 75*5ddc57e5SXin Li double lm_enorm(int, const double*); 76*5ddc57e5SXin Li 77*5ddc57e5SXin Li __END_DECLS 78*5ddc57e5SXin Li #endif /* LMMIN_H */ 79