Function: math-powell-min

math-powell-min is a byte-compiled function defined in calcalg3.el.gz.

Signature

(math-powell-min EXPR N GUESSES PREC)

Source Code

;; Defined in /usr/src/emacs/lisp/calc/calcalg3.el.gz
;;; "powell"
(defun math-powell-min (expr n guesses prec)
  (let* ((f1dim (math-line-min-func expr n))
	 (xi (calcFunc-idn 1 n))
	 (p (cons 'vec (mapcar 'car guesses)))
	 (pt p)
	 (ftol (list 'float 1 (- prec)))
	 (fret (math-min-eval expr p))
	 fp ptt fptt xit i ibig del diff res)
    (while (progn
	     (setq fp fret
		   ibig 0
		   del '(float 0 0)
		   i 0)
	     (while (<= (setq i (1+ i)) n)
	       (setq fptt fret
		     res (math-line-min f1dim p
					(math-mat-col xi i)
					n prec)
		     p (let ((calc-internal-prec prec))
			 (math-normalize (car res)))
		     fret (nth 2 res)
		     diff (math-abs (math-sub-float fptt fret)))
	       (if (math-lessp-float del diff)
		   (setq del diff
			 ibig i)))
	     (math-lessp-float
	      (math-mul-float ftol
			      (math-add-float (math-abs fp)
					      (math-abs fret)))
	      (math-mul-float '(float 2 0)
			      (math-abs (math-sub-float fp
							fret)))))
      (setq ptt (math-sub (math-mul '(float 2 0) p) pt)
	    xit (math-sub p pt)
	    pt p
	    fptt (math-min-eval expr ptt))
      (if (and (math-lessp-float fptt fp)
	       (math-lessp-float
		(math-mul-float
		 (math-mul-float '(float 2 0)
				 (math-add-float
				  (math-sub-float fp
						  (math-mul-float '(float 2 0)
								  fret))
				  fptt))
		 (math-sqr-float (math-sub-float
				  (math-sub-float fp fret) del)))
		(math-mul-float del
				(math-sqr-float (math-sub-float fp fptt)))))
	  (progn
	    (setq res (math-line-min f1dim p xit n prec)
		  p (car res)
		  fret (nth 2 res)
		  i 0)
	    (while (<= (setq i (1+ i)) n)
	      (setcar (nthcdr ibig (nth i xi))
		      (nth i (nth 1 res)))))))
    (list 'vec p fret)))