summaryrefslogtreecommitdiff
path: root/lisp/calc/calc-vec.el
diff options
context:
space:
mode:
authorJay Belanger <jay.p.belanger@gmail.com>2008-04-07 21:55:05 +0000
committerJay Belanger <jay.p.belanger@gmail.com>2008-04-07 21:55:05 +0000
commit1aa484e3a6ca18f0efc8bdf472b27f96eed4b799 (patch)
treeb545b58824d993b8031980236cfa244cc40b588a /lisp/calc/calc-vec.el
parent60f2c210c0bbbfb1b2d3085aac4159126a26836e (diff)
downloademacs-1aa484e3a6ca18f0efc8bdf472b27f96eed4b799.tar.gz
(calcFunc-kron, calc-kron): New functions.
Diffstat (limited to 'lisp/calc/calc-vec.el')
-rw-r--r--lisp/calc/calc-vec.el40
1 files changed, 40 insertions, 0 deletions
diff --git a/lisp/calc/calc-vec.el b/lisp/calc/calc-vec.el
index b869a1e08a8..4055c4a7277 100644
--- a/lisp/calc/calc-vec.el
+++ b/lisp/calc/calc-vec.el
@@ -479,6 +479,11 @@
(calc-wrapper
(calc-binary-op "cros" 'calcFunc-cross arg)))
+(defun calc-kron (arg)
+ (interactive "P")
+ (calc-wrapper
+ (calc-binary-op "kron" 'calcFunc-kron arg)))
+
(defun calc-remove-duplicates (arg)
(interactive "P")
(calc-wrapper
@@ -1466,6 +1471,41 @@
(math-reject-arg a "*Three-vector expected")))
+;;; Compute a Kronecker product
+(defun calcFunc-kron (x y &optional nocheck)
+ "The Kronecker product of objects X and Y.
+The objects X and Y may be scalars, vectors or matrices.
+The type of the result depends on the types of the operands;
+the product of two scalars is a scalar,
+of one scalar and a vector is a vector,
+of two vectors is a vector.
+of one vector and a matrix is a matrix,
+of two matrices is a matrix."
+ (unless nocheck
+ (cond ((or (math-matrixp x)
+ (math-matrixp y))
+ (unless (math-matrixp x)
+ (setq x (if (math-vectorp x)
+ (list 'vec x)
+ (list 'vec (list 'vec x)))))
+ (unless (math-matrixp y)
+ (setq y (if (math-vectorp y)
+ (list 'vec y)
+ (list 'vec (list 'vec y))))))
+ ((or (math-vectorp x)
+ (math-vectorp y))
+ (unless (math-vectorp x)
+ (setq x (list 'vec x)))
+ (unless (math-vectorp y)
+ (setq y (list 'vec y))))))
+ (if (math-vectorp x)
+ (let (ret)
+ (dolist (v (cdr x))
+ (dolist (w (cdr y))
+ (setq ret (cons (calcFunc-kron v w t) ret))))
+ (cons 'vec (nreverse ret)))
+ (math-mul x y)))
+
;; The variable math-rb-close is local to math-read-brackets, but
;; is used by math-read-vector, which is called (directly and