;;; A simple demonstration of how to use lisplab (in-package :ll-user) ;;; 19 ways to create a matrix (defparameter *test-matrices* (list ;; Blank matrices (mnew 'matrix-dge 0 3 5) ; same as (dnew 0 3 5) ; same as (mnew '(:d :ge :any) 0 3 5) (mnew 'matrix-zge 0 3 5) ; same as (znew 0 3 5) ; same as (mnew '(:z :ge :any) 0 3 5) (drow 2 4 2) (dcol 2 3 1) (zrow 2 %i 1) (zcol 2 %i 1) ;; Read macro #md((1 2) (-1 4)) #mz((1 2) (-1 4)) #mm((1 2) (-1 4)) ;; Setting of individual elements (dmat '((0 4 -2) (1 3 -5) (-2 4 0))) (zmat '((0 #c(0 2) -2) (1 3 -5) (-2 #c(0 1) 0))) ;; Setting of structure (funmat '(4 4) (lambda (i j) (if (= i j) 1 0))) (fmat 'matrix-dge '(3 4) (lambda (i j) (if (< i j) 1 0.5))) ;; From another matrix (copy #md((1 4) (-2 3))) (mcreate #md((1 4) (-2 3))) (convert '((3 2 4) (1 4 2)) 'matrix-dge) (convert (funmat '(3 3) (lambda (i j) (random 1.0))) 'matrix-dge) (mmap '(:z :ge :any) #'random (mnew '(:d :ge :any) 1 3 3)) (.+ 3 #md((2 3) (-2 9))) )) (mapcar (lambda (x) (mref x 0 0)) *test-matrices*) (mapcar (lambda (x) (vref x 2)) *test-matrices*) ;; Arithmetics (let ((a #md((0 4 -2) (1 3 -5) (-2 4 0))) (b #mz((0 (.* 2 %i) -2) (1 3 -5) (-2 %i 0)))) (.+ (.* 3 a) b)) ;; Infix arithmetics (let ((a #md((0 4 -2) (1 3 -5) (-2 4 0))) (b #mz((0 #c(0 2) -2) (1 3 -5) (-2 %i 0)))) (w/infix 3 .* a .+ b)) ;; Matrix inversion (minv #md((0 4 -2) (1 3 -5) (-2 4 0)))