matrix addition/subtraction/init

Started by hs, September 03, 2006, 02:14:58 AM

Previous topic - Next topic

hs

hi all



can we easily initialize a matrix by setting it to some array?

do we have matrix built-in function other than invert, multiply, transpose?

battery-included init, add, sub, determinant, size functions are nice to have



i played with matrix for a bit and i feel my code's long:



(set 'a (array-list (array 3 2 (sequence 1 6))))  ;matrix initialization

(set 'b (array-list (array 3 2 (sequence 4 9))))  ;array-list and array redundant?

(set 'c (array-list (array (length a) (length (a 1)) (map + (flat a) (flat b)))))

(invert (multiply (transpose c) c))

;((1.028645833 -0.8567708333) (-0.8567708333 0.7161458333))



this is my first time, sorry if the topic is old (i searched old posts tho)

thx!

Lutz

#1
Historically matrix operations where introduced into newLISP before arrays. This is the main reason that matrix operations only work on lists.



I think, if we allow matrix operations to be performed on arrays, that would alleviate the initialization problem, and can be added quickly with very little code.



It also makes sense for other operations, like changing elements in a matrix which are much faster on arrays than on lists when matrices get big (nth-set and set-nth already work on arrays). Speedup was the reason arrays where introduced in the first place.



Regarding other matrix operations: init, add, sub, determinant. What would 'init' do?



Welcome to this discussion group and newLISP,



Lutz



ps: what kind of work are you doing?