Add a provide statement.
[bpt/emacs.git] / lisp / calc / calc-mtx.el
index b9dc2aa..6cac30a 100644 (file)
@@ -1,6 +1,9 @@
-;; Calculator for GNU Emacs, part II [calc-mat.el]
-;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
-;; Written by Dave Gillespie, daveg@synaptics.com.
+;;; calc-mtx.el --- matrix functions for Calc
+
+;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
+
+;; Author: David Gillespie <daveg@synaptics.com>
+;; Maintainer: Jay Belanger <belanger@truman.edu>
 
 ;; This file is part of GNU Emacs.
 
 ;; file named COPYING.  Among other things, the copyright notice
 ;; and this notice must be preserved on all copies.
 
+;;; Commentary:
 
+;;; Code:
 
 ;; This file is autoloaded from calc-ext.el.
-(require 'calc-ext)
 
+(require 'calc-ext)
 (require 'calc-macs)
 
-(defun calc-Need-calc-mat () nil)
-
-
 (defun calc-mdet (arg)
   (interactive "P")
   (calc-slow-wrapper
-   (calc-unary-op "mdet" 'calcFunc-det arg))
-)
+   (calc-unary-op "mdet" 'calcFunc-det arg)))
 
 (defun calc-mtrace (arg)
   (interactive "P")
   (calc-slow-wrapper
-   (calc-unary-op "mtr" 'calcFunc-tr arg))
-)
+   (calc-unary-op "mtr" 'calcFunc-tr arg)))
 
 (defun calc-mlud (arg)
   (interactive "P")
   (calc-slow-wrapper
-   (calc-unary-op "mlud" 'calcFunc-lud arg))
-)
+   (calc-unary-op "mlud" 'calcFunc-lud arg)))
 
 
 ;;; Coerce row vector A to be a matrix.  [V V]
   (if (and (Math-vectorp a)
           (not (math-matrixp a)))
       (list 'vec a)
-    a)
-)
+    a))
 
 ;;; Coerce column vector A to be a matrix.  [V V]
 (defun math-col-matrix (a)
   (if (and (Math-vectorp a)
           (not (math-matrixp a)))
       (cons 'vec (mapcar (function (lambda (x) (list 'vec x))) (cdr a)))
-    a)
-)
+    a))
 
 
 
          (setq accum (math-add accum (math-mul (car ap) (nth col (car bp))))))
        (setq row (cons accum row)))
       (setq mat (cons (cons 'vec row) mat)))
-    (cons 'vec (nreverse mat)))
-)
+    (cons 'vec (nreverse mat))))
 
 (defun math-mul-mat-vec (a b)
   (cons 'vec (mapcar (function (lambda (row)
                                 (math-dot-product row b)))
-                    (cdr a)))
-)
+                    (cdr a))))
 
 
 
 (defun calcFunc-tr (mat)   ; [Public]
   (if (math-square-matrixp mat)
       (math-matrix-trace-step 2 (1- (length mat)) mat (nth 1 (nth 1 mat)))
-    (math-reject-arg mat 'square-matrixp))
-)
+    (math-reject-arg mat 'square-matrixp)))
 
 (defun math-matrix-trace-step (n size mat sum)
   (if (<= n size)
       (math-matrix-trace-step (1+ n) size mat
                              (math-add sum (nth n (nth n mat))))
-    sum)
-)
+    sum))
 
 
 ;;; Matrix inverse and determinant.
                det)))
       (let ((lud (math-matrix-lud m)))
        (and lud
-            (math-lud-solve lud (calcFunc-idn 1 n))))))
-)
+            (math-lud-solve lud (calcFunc-idn 1 n)))))))
 
 (defun calcFunc-det (m)
   (if (math-square-matrixp m)
             (or (math-zerop (nth 1 m))
                 (math-equal-int (nth 1 m) 1)))
        (nth 1 m)
-      (math-reject-arg m 'square-matrixp)))
-)
+      (math-reject-arg m 'square-matrixp))))
+
+;; The variable math-det-lu is local to math-det-raw, but is
+;; used by math-det-step, which is called by math-det-raw.
+(defvar math-det-lu)
 
 (defun math-det-raw (m)
   (let ((n (1- (length m))))
                                (nth 3 (nth 3 m))))))
          (t (let ((lud (math-matrix-lud m)))
               (if lud
-                  (let ((lu (car lud)))
+                  (let ((math-det-lu (car lud)))
                     (math-det-step n (nth 2 lud)))
-                0)))))
-)
+                0))))))
 
 (defun math-det-step (n prod)
   (if (> n 0)
-      (math-det-step (1- n) (math-mul prod (nth n (nth n lu))))
-    prod)
-)
+      (math-det-step (1- n) (math-mul prod (nth n (nth n math-det-lu))))
+    prod))
 
-;;; This returns a list (LU index d), or NIL if not possible.
+;;; This returns a list (LU index d), or nil if not possible.
 ;;; Argument M must be a square matrix.
+(defvar math-lud-cache nil)
 (defun math-matrix-lud (m)
   (let ((old (assoc m math-lud-cache))
        (context (list calc-internal-prec calc-prefer-frac)))
        (if old
            (setcdr old entry)
          (setq math-lud-cache (cons (cons m entry) math-lud-cache)))
-       lud)))
-)
-(defvar math-lud-cache nil)
+       lud))))
 
 ;;; Numerical Recipes section 2.3; implicit pivoting omitted.
 (defun math-do-matrix-lud (m)
            (setcar (nthcdr j (nth i lu))
                    (math-div (nth j (nth i lu)) pivot)))))
       (setq j (1+ j)))
-    (list lu (nreverse index) d))
-)
+    (list lu (nreverse index) d)))
 
 (defun math-swap-rows (m r1 r2)
   (or (= r1 r2)
        (setcdr r1prev row2)
        (setcdr row2 (cdr row1))
        (setcdr row1 r2next)))
-  m
-)
+  m)
 
 
 (defun math-lud-solve (lud b &optional need)
          (setq col (1+ col)))
        x)
     (and need
-        (math-reject-arg need "*Singular matrix")))
-)
+        (math-reject-arg need "*Singular matrix"))))
 
 (defun calcFunc-lud (m)
   (if (math-square-matrixp m)
                             (setq perm (math-swap-rows perm j pos)))))
                     (list 'vec perm lmat umat)))))
          (math-reject-arg m "*Singular matrix"))
-    (math-reject-arg m 'square-matrixp))
-)
+    (math-reject-arg m 'square-matrixp)))
+
+(provide 'calc-mtx)
 
+;;; arch-tag: fc0947b1-90e1-4a23-8950-d8ead9c3a306
+;;; calc-mtx.el ends here