;;; calc-nlfit.el --- nonlinear curve fitting for Calc
-;; Copyright (C) 2007 Free Software Foundation, Inc.
+;; Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 'calc-arith)
+(require 'calcalg3)
+
+;; Declare functions which are defined elsewhere.
+(declare-function calc-get-fit-variables "calcalg3" (nv nc &optional defv defc with-y homog))
+(declare-function math-map-binop "calcalg3" (binop args1 args2))
(defun math-nlfit-least-squares (xdata ydata &optional sdata sigmas)
"Return the parameters A and B for the best least squares fit y=a+bx."
;;; the maximum value of q.
(defun math-nlfit-find-qmax (qdata pdata tdata)
- (let* ((ratios (mapcar* 'math-div pdata qdata))
+ (let* ((ratios (math-map-binop 'math-div pdata qdata))
(lsdata (math-nlfit-least-squares ratios tdata))
(qmax (math-max-list (car qdata) (cdr qdata)))
(a (math-neg (math-div (nth 1 lsdata) (nth 0 lsdata)))))
(mat nil)
(k 0))
(while (< k i)
- (setq mat (cons (copy-list row) mat))
+ (setq mat (cons (copy-sequence row) mat))
(setq k (1+ k)))
mat))
(let* ((Ctilda (math-nlfit-make-Ctilda C lambda))
(dtilda (math-nlfit-make-dtilda d (length (car C))))
(zeta (math-nlfit-givens Ctilda dtilda))
- (newparms (mapcar* 'math-add (copy-tree parms) zeta))
+ (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
(nth 0 sigmacovar)))
(finalparms
(if sigmas
- (mapcar* (lambda (x y) (list 'sdev x y)) finalparms sigmas)
+ (math-map-binop
+ (lambda (x y) (list 'sdev x y)) finalparms sigmas)
finalparms))
(soln (funcall solnexpr finalparms var)))
(let ((calc-fit-to-trail t)
(mapcar (lambda (x) (math-get-sdev x t)) pdata)
nil))
(pdata (mapcar (lambda (x) (math-get-value x)) pdata))
- (poverqdata (mapcar* 'math-div pdata qdata))
+ (poverqdata (math-map-binop 'math-div pdata qdata))
(parmvals (math-nlfit-least-squares qdata poverqdata sdata sdevv))
(finalparms (list (nth 0 parmvals)
(math-neg