Function: calc-get-fit-variables
calc-get-fit-variables is a byte-compiled function defined in
calcalg3.el.gz.
Signature
(calc-get-fit-variables NV NC &optional DEFV DEFC WITH-Y HOMOG)
Source Code
;; Defined in /usr/src/emacs/lisp/calc/calcalg3.el.gz
(defun calc-get-fit-variables (nv nc &optional defv defc with-y homog)
(or (= nv (if with-y (1+ calc-curve-nvars) calc-curve-nvars))
(error "Wrong number of data vectors for this type of model"))
(if (integerp defv)
(setq homog defv
defv nil))
(if homog
(setq nc (1- nc)))
(or defv
(setq defv (calc-invent-independent-variables nv)))
(or defc
(setq defc (calc-invent-parameter-variables nc defv)))
(let ((vars (read-string (format-prompt
"Fitting variables"
(format "%s; %s"
(mapconcat 'symbol-name
(mapcar (lambda (v)
(nth 1 v))
defv)
",")
(mapconcat 'symbol-name
(mapcar (lambda (v)
(nth 1 v))
defc)
",")))))
(coefs nil))
(setq vars (if (string-search "[" vars)
(math-read-expr vars)
(math-read-expr (concat "[" vars "]"))))
(if (eq (car-safe vars) 'error)
(error "Bad format in expression: %s" (nth 2 vars)))
(or (math-vectorp vars)
(error "Expected a variable or vector of variables"))
(if (equal vars '(vec))
(setq vars (cons 'vec defv)
coefs (cons 'vec defc))
(if (math-vectorp (nth 1 vars))
(if (and (= (length vars) 3)
(math-vectorp (nth 2 vars)))
(setq coefs (nth 2 vars)
vars (nth 1 vars))
(error
"Expected independent variables vector, then parameters vector"))
(setq coefs (cons 'vec defc))))
(or (= nv (1- (length vars)))
(and (not with-y) (= (1+ nv) (1- (length vars))))
(error "Expected %d independent variable%s" nv (if (= nv 1) "" "s")))
(or (= nc (1- (length coefs)))
(error "Expected %d parameter variable%s" nc (if (= nc 1) "" "s")))
(if homog
(setq coefs (cons 'vec (cons homog (cdr coefs)))))
(if calc-curve-varnames
(setq calc-curve-model (math-multi-subst calc-curve-model (cdr calc-curve-varnames) (cdr vars))))
(if calc-curve-coefnames
(setq calc-curve-model (math-multi-subst calc-curve-model (cdr calc-curve-coefnames) (cdr coefs))))
(setq calc-curve-varnames vars
calc-curve-coefnames coefs)))