matrix multiplication



Sorry Jaime, I looked through your email for the final function
specification and somehow missed it (sitting right there in the middle
of the email).  I have added one small feature and think the finish
product is quite cool thanks to you.  It now returns a column vector
if v1 one was a column vector going in by calling transpose on the
output if needed:

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)$

Simple test with i and j as rows, columns, and lists:

(%i1) load("E:/siue/AdvDynamics/rotation_matrices.mac")$
(%i2) iv:matrix([1,0,0]);
(%o2) matrix([1,0,0])
(%i3) jv:matrix([0,1,0]);
(%o3) matrix([0,1,0])
(%i4) cross(iv,jv);
(%o4) [0,0,1]
(%i5) ic:matrix([1],[0],[0]);
(%o5) matrix([1],[0],[0])
(%i6) jc:matrix([0],[1],[0]);
(%o6) matrix([0],[1],[0])
(%i7) cross(ic,jc);
(%o7) matrix([0],[0],[1])
(%i8) il:[1,0,0];
(%o8) [1,0,0]
(%i9) jl:[0,1,0];
(%o9) [0,1,0]
(%i10) cross(il,jl);
(%o10) [0,0,1]


Should something like this get included in some linear algebra package
somewhere/somehow?  It is sort of a patch of the problem I was having
- i.e. I don't need to load vect.mac now and my dot operator isn't
affected

Thanks,

Ryan

On 3/23/07, Jaime E. Villate <villate at fe.up.pt> wrote:
> On Fri, 2007-03-23 at 10:26 -0500, Ryan Krauss wrote:
> > cross (v1, v2) :=
> >    block(M:transpose(matrix([[1, 0, 0], [0, 1, 0], [0, 0,1]])),
> >    if length(transpose(v1)[1])=1 then v1: transpose(v1),
> >    if length(transpose(v2)[1])=1 then v2: transpose(v2),
> >    M: addcol(M,v1), M: addcol(M,v2), determinant(M),
> >    makelist((-1)^(i-1)*determinant(submatrix(i,M)),i,1,3))$
>
> That definition is wrong. M at the end will be a 3x3, matrix.
> submatrix(i,M) will remove row i, leaving a 2x3, which cannot
> be used to calculate a determinant. You would have to do something such
> as submatrix(i,M,1) to remove row i and column 1, leaving a 2x2 matrix.
> But then the unit vector [1,0,0]... are useless.
> Do exactly as I said :)
>
> cross (v1, v2) := block([M],
>          if length(transpose(v1)[1])=1 then v1: transpose(v1),
>          if length(transpose(v2)[1])=1 then v2: transpose(v2),
>          M: addcol(v1,v2),
>          makelist((-1)^(i-1)*determinant(submatrix(i,M)),i,1,3))$
>
> as I showed you, it works.
>
> Cheers,
> Jaime
>
>
>