Function: math-nlfit-fit
math-nlfit-fit is a byte-compiled function defined in
calc-nlfit.el.gz.
Signature
(math-nlfit-fit XLIST YLIST PARMS FN GRAD &optional SLIST)
Source Code
;; Defined in /usr/src/emacs/lisp/calc/calc-nlfit.el.gz
(defun math-nlfit-fit (xlist ylist parms fn grad &optional slist)
(let*
((C (math-nlfit-jacobian grad xlist parms slist))
(d (math-nlfit-make-d fn xlist ylist parms slist))
(chisq (math-nlfit-chi-sq xlist ylist parms fn slist))
(lambda (math-nlfit-init-lambda C))
(really-done nil)
(iters 0))
(while (and
(not really-done)
(< iters math-nlfit-max-its))
(setq iters (1+ iters))
(let ((done nil))
(while (not done)
(let* ((Ctilda (math-nlfit-make-Ctilda C lambda))
(dtilda (math-nlfit-make-dtilda d (length (car C))))
(zeta (math-nlfit-givens Ctilda dtilda))
(newparms (math-map-binop 'math-add (copy-tree parms) zeta))
(newchisq (math-nlfit-chi-sq xlist ylist newparms fn slist)))
(if (math-lessp newchisq chisq)
(progn
(if (math-lessp
(math-div
(math-sub chisq newchisq) newchisq) math-nlfit-epsilon)
(setq really-done t))
(setq lambda (math-div lambda 10))
(setq chisq newchisq)
(setq parms newparms)
(setq done t))
(setq lambda (math-mul lambda 10)))))
(setq C (math-nlfit-jacobian grad xlist parms slist))
(setq d (math-nlfit-make-d fn xlist ylist parms slist))))
(list chisq parms)))