Comments:
(1) The variables 'M', 'out', and 'cols' are undefined global variables:
(%i2) cross([1,2,0],[6,7,8]);
(%o2) [16,-8,-5]
(%i3) M;
(%o3) matrix([1,6],[2,7],[0,8]) <-- M shouldn't have a value, but it does!
To fix this, the block construct should be something like
cross (v1, v2) :=
block([M : transpose(matrix([[1, 0, 0], [0, 1, 0], [0, 0,1]])),
cols, out],
(2) I'm not a fan of functions that signal errors that would seem
mysterious to the user:
(%i6) cross(x,x);
First argument to `addcol' must be a matrix
The error doesn't tell the user how to correct the problem--something
like "The arguments to 'cross' must be..." would be much better.
(3) I'm also not keen on having two cross product functions (one in
vect.mac).
If the function in vect.mac is broken or needs to be generalized, then fix
it.
After that, find a solution to the non-commutative "." problem in vect.mac.
(4) I'm not fond of gratuitous generalizations:
(%i6) cross([1,2,3], matrix([5],[9],[10]));
(%o6) [-7,5,-1]
I think such things lead to trouble.
Barton
-----maxima-bounces at math.utexas.edu wrote: -----
>cross (v1, v2) :=
> block(M:transpose(matrix([[1, 0, 0], [0, 1, 0], [0, 0,1]])),
> cols: is (length(transpose(v1)[1])#1),
> if length(transpose(v1)[1])=1 then v1: transpose(v1),
> if length(transpose(v2)[1])=1 then v2: transpose(v2),
> M: addcol(v1,v2),
> out: makelist((-1)^(i-1)*determinant(submatrix(i,M)),i,1,3),
> if cols then out:transpose(out) else out)$