summaryrefslogtreecommitdiffstats
path: root/determ.scm
diff options
context:
space:
mode:
authorThomas Bushnell, BSG <tb@debian.org>2007-12-28 16:25:32 -0800
committerBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:39 -0800
commitd8ae23691ed6392b7f320f5fa7d4dd78ae52c10e (patch)
treeb20b8bc02e854c4c86d39ee22a0638a8b06e01af /determ.scm
parentedd1ebef3ad774e7cbcc2f5918d555bfb0b44091 (diff)
parent64f037d91e0c9296dcaef9a0ff3eb33b19a2ed34 (diff)
downloadslib-d8ae23691ed6392b7f320f5fa7d4dd78ae52c10e.tar.gz
slib-d8ae23691ed6392b7f320f5fa7d4dd78ae52c10e.zip
Import Debian changes 3a5-1debian/3a5-1
slib (3a5-1) unstable; urgency=low * New upstream release. * slib.texi (Library Catalogs): Repeat change from 3a3-3. * Makefile: Repeat $(htmldir)slib_toc.html changes from 3a2-1. * guile.init: (library-vicinity): Repeat change from 3a4-2. * debian/rules (binary-indep): Don't hide .init files in a separate subdirectory, thus conforming better to the usual slib practice. Put a symlink in place to ease transitions. (Closes: #407370).
Diffstat (limited to 'determ.scm')
-rw-r--r--determ.scm48
1 files changed, 38 insertions, 10 deletions
diff --git a/determ.scm b/determ.scm
index 0962e4a..30dabbc 100644
--- a/determ.scm
+++ b/determ.scm
@@ -114,18 +114,46 @@
matrix))))
;;@body
-;;Returns the product of matrices @1 and @2.
-(define (matrix:product m1 m2)
+;;Returns the element-wise sum of matricies @1 and @2.
+(define (matrix:sum m1 m2)
(define mat1 (matrix->lists m1))
(define mat2 (matrix->lists m2))
- (define (dot-product v1 v2) (apply + (map * v1 v2)))
- (coerce-like-arg
- (map (lambda (arow)
- (apply map
- (lambda bcol (dot-product bcol arow))
- mat2))
- mat1)
- m1))
+ (coerce-like-arg (map (lambda (row1 row2) (map + row1 row2)) mat1 mat2)
+ m1))
+
+;;@body
+;;Returns the element-wise difference of matricies @1 and @2.
+(define (matrix:difference m1 m2)
+ (define mat1 (matrix->lists m1))
+ (define mat2 (matrix->lists m2))
+ (coerce-like-arg (map (lambda (row1 row2) (map - row1 row2)) mat1 mat2)
+ m1))
+
+(define (matrix:scale m1 scl)
+ (coerce-like-arg (map (lambda (row1) (map (lambda (x) (* scl x)) row1))
+ (matrix->lists m1))
+ m1))
+
+;;@args m1 m2
+;;Returns the product of matrices @1 and @2.
+;;@args m1 z
+;;Returns matrix @var{m1} times scalar @var{z}.
+;;@args z m1
+;;Returns matrix @var{m1} times scalar @var{z}.
+(define (matrix:product m1 m2)
+ (cond ((number? m1) (matrix:scale m2 m1))
+ ((number? m2) (matrix:scale m1 m2))
+ (else
+ (let ((mat1 (matrix->lists m1))
+ (mat2 (matrix->lists m2)))
+ (define (dot-product v1 v2) (apply + (map * v1 v2)))
+ (coerce-like-arg
+ (map (lambda (arow)
+ (apply map
+ (lambda bcol (dot-product bcol arow))
+ mat2))
+ mat1)
+ m1)))))
;;@body
;;@1 must be a square matrix.