-- LMfit Version 1.1, 14-Dec-2001 ~ Procedure LMfit((x,y,guess,weights) fits a user-given function to a set of data using the Levenberg-Marquard algorithm as in Bevington. Parameters: x: vector for independent variables' values y: vector for dependent variables' values weights: vector with weights or scalar 1 for non-weighted fit. guess: vector of initial guesses for coeffs Globals to set: LM_f(coeffs,x) the function of x with coeffs to be fitted epsilon: accuracy criterion (1e-5 is good, 1e-8 is ok). Maxiter: Max. no. of iterations LM_lambda:lambda parmeter, defaults to 0.001 LM_fast: set to 1 for faster, but less accurate, derivatives Globals to read: coeffs: vector of final fitted coefficients LM_deltas(guess): vector or scalar of initial stepsize LM_iter: returns the no. of iterations performed LM_chisq[:Maxiter]: Vector of squared errors LM_lambdas[:Maxiter]: Vector of lambda values If the weights are derived from 1-sigma errors, LMfit returns the Chi-squared/deg-of-freedom of the fit. Needs "matrix ops" to work: I have renamed the "invert" function to "minvert" to avoid a conflict with SVD. I have not had good results with the invert function of SVD. It is used in LM_New. H.-Ulrich (Uli) Wienands, Stanford Linear Accelerator Center, uli@slac.stanford.edu ~ LMfit(xx,yy,guess,weights) = LM_Init(xx,yy,guess,weights), (LM_alphas(xx,yy,coeffs,weights), LM_New(xx,yy,coeffs,weights), progressbar(LM_iter/Maxiter*100), (LM_lambda:=LM_lambda*10, LM_New(xx,yy,coeffs,weights)) while (LM_err1>=LM_err0), LM_lambda:=LM_lambda/10, coeffs:=LM_B, LM_iter:=LM_iter+1, LM_chisq[LM_iter]:=LM_err1, LM_lambdas[LM_iter]:=LM_lambda) while (abs(LM_err1-LM_err0)/LM_err0>epsilon and LM_iter