diff options
| author | Jay Belanger | 2008-04-07 21:55:05 +0000 |
|---|---|---|
| committer | Jay Belanger | 2008-04-07 21:55:05 +0000 |
| commit | 1aa484e3a6ca18f0efc8bdf472b27f96eed4b799 (patch) | |
| tree | b545b58824d993b8031980236cfa244cc40b588a /lisp/calc | |
| parent | 60f2c210c0bbbfb1b2d3085aac4159126a26836e (diff) | |
| download | emacs-1aa484e3a6ca18f0efc8bdf472b27f96eed4b799.tar.gz emacs-1aa484e3a6ca18f0efc8bdf472b27f96eed4b799.zip | |
(calcFunc-kron, calc-kron): New functions.
Diffstat (limited to 'lisp/calc')
| -rw-r--r-- | lisp/calc/calc-vec.el | 40 |
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 @@ | |||
| 479 | (calc-wrapper | 479 | (calc-wrapper |
| 480 | (calc-binary-op "cros" 'calcFunc-cross arg))) | 480 | (calc-binary-op "cros" 'calcFunc-cross arg))) |
| 481 | 481 | ||
| 482 | (defun calc-kron (arg) | ||
| 483 | (interactive "P") | ||
| 484 | (calc-wrapper | ||
| 485 | (calc-binary-op "kron" 'calcFunc-kron arg))) | ||
| 486 | |||
| 482 | (defun calc-remove-duplicates (arg) | 487 | (defun calc-remove-duplicates (arg) |
| 483 | (interactive "P") | 488 | (interactive "P") |
| 484 | (calc-wrapper | 489 | (calc-wrapper |
| @@ -1466,6 +1471,41 @@ | |||
| 1466 | (math-reject-arg a "*Three-vector expected"))) | 1471 | (math-reject-arg a "*Three-vector expected"))) |
| 1467 | 1472 | ||
| 1468 | 1473 | ||
| 1474 | ;;; Compute a Kronecker product | ||
| 1475 | (defun calcFunc-kron (x y &optional nocheck) | ||
| 1476 | "The Kronecker product of objects X and Y. | ||
| 1477 | The objects X and Y may be scalars, vectors or matrices. | ||
| 1478 | The type of the result depends on the types of the operands; | ||
| 1479 | the product of two scalars is a scalar, | ||
| 1480 | of one scalar and a vector is a vector, | ||
| 1481 | of two vectors is a vector. | ||
| 1482 | of one vector and a matrix is a matrix, | ||
| 1483 | of two matrices is a matrix." | ||
| 1484 | (unless nocheck | ||
| 1485 | (cond ((or (math-matrixp x) | ||
| 1486 | (math-matrixp y)) | ||
| 1487 | (unless (math-matrixp x) | ||
| 1488 | (setq x (if (math-vectorp x) | ||
| 1489 | (list 'vec x) | ||
| 1490 | (list 'vec (list 'vec x))))) | ||
| 1491 | (unless (math-matrixp y) | ||
| 1492 | (setq y (if (math-vectorp y) | ||
| 1493 | (list 'vec y) | ||
| 1494 | (list 'vec (list 'vec y)))))) | ||
| 1495 | ((or (math-vectorp x) | ||
| 1496 | (math-vectorp y)) | ||
| 1497 | (unless (math-vectorp x) | ||
| 1498 | (setq x (list 'vec x))) | ||
| 1499 | (unless (math-vectorp y) | ||
| 1500 | (setq y (list 'vec y)))))) | ||
| 1501 | (if (math-vectorp x) | ||
| 1502 | (let (ret) | ||
| 1503 | (dolist (v (cdr x)) | ||
| 1504 | (dolist (w (cdr y)) | ||
| 1505 | (setq ret (cons (calcFunc-kron v w t) ret)))) | ||
| 1506 | (cons 'vec (nreverse ret))) | ||
| 1507 | (math-mul x y))) | ||
| 1508 | |||
| 1469 | 1509 | ||
| 1470 | ;; The variable math-rb-close is local to math-read-brackets, but | 1510 | ;; The variable math-rb-close is local to math-read-brackets, but |
| 1471 | ;; is used by math-read-vector, which is called (directly and | 1511 | ;; is used by math-read-vector, which is called (directly and |