X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/8cf06c7f74ccb33646dabf1553c4fdbbe030ae6a..d02fe47dd3be7310d1bfd6e802d1fac2ea5f5e9d:/lisp/calc/calc-vec.el diff --git a/lisp/calc/calc-vec.el b/lisp/calc/calc-vec.el index e85d1259b5..c079e8985e 100644 --- a/lisp/calc/calc-vec.el +++ b/lisp/calc/calc-vec.el @@ -1,7 +1,7 @@ ;;; calc-vec.el --- vector functions for Calc ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004, -;; 2005, 2006, 2007 Free Software Foundation, Inc. +;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. ;; Author: David Gillespie ;; Maintainer: Jay Belanger @@ -10,7 +10,7 @@ ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 2, or (at your option) +;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, @@ -32,6 +32,10 @@ (require 'calc-ext) (require 'calc-macs) +;; Declare functions which are defined elsewhere. +(declare-function math-read-expr-level "calc-aent" (exp-prec &optional exp-term)) + + (defun calc-display-strings (n) (interactive "P") (calc-wrapper @@ -475,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 @@ -1462,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 @@ -1593,5 +1637,5 @@ (provide 'calc-vec) -;;; arch-tag: 7902a7af-ec69-440a-8635-ebb4db263402 +;; arch-tag: 7902a7af-ec69-440a-8635-ebb4db263402 ;;; calc-vec.el ends here