Function: math-do-matrix-lud
math-do-matrix-lud is a byte-compiled function defined in
calc-mtx.el.gz.
Signature
(math-do-matrix-lud M)
Source Code
;; Defined in /usr/src/emacs/lisp/calc/calc-mtx.el.gz
;;; Numerical Recipes section 2.3; implicit pivoting omitted.
(defun math-do-matrix-lud (m)
(let* ((lu (math-copy-matrix m))
(n (1- (length lu)))
i (j 1) k imax sum big
(d 1) (index nil))
(while (<= j n)
(setq i 1
big 0
imax j)
(while (< i j)
(math-working "LUD step" (format "%d/%d" j i))
(setq sum (nth j (nth i lu))
k 1)
(while (< k i)
(setq sum (math-sub sum (math-mul (nth k (nth i lu))
(nth j (nth k lu))))
k (1+ k)))
(setcar (nthcdr j (nth i lu)) sum)
(setq i (1+ i)))
(while (<= i n)
(math-working "LUD step" (format "%d/%d" j i))
(setq sum (nth j (nth i lu))
k 1)
(while (< k j)
(setq sum (math-sub sum (math-mul (nth k (nth i lu))
(nth j (nth k lu))))
k (1+ k)))
(setcar (nthcdr j (nth i lu)) sum)
(let ((dum (math-lud-pivot-check sum)))
(if (or (math-zerop big) (Math-lessp big dum))
(setq big dum
imax i)))
(setq i (1+ i)))
(if (> imax j)
(setq lu (math-swap-rows lu j imax)
d (- d)))
(setq index (cons imax index))
(let ((pivot (nth j (nth j lu))))
(if (math-zerop pivot)
(throw 'singular nil)
(setq i j)
(while (<= (setq i (1+ i)) n)
(setcar (nthcdr j (nth i lu))
(math-div (nth j (nth i lu)) pivot)))))
(setq j (1+ j)))
(list lu (nreverse index) d)))