matrixMultiply

Raymond E. Griffith rgriffit at vnet.net
Wed Jul 24 15:23:00 EDT 2002


Gregory Lypny <gregory.lypny at videotron.ca> asked...

> Hi Everyone,
> 
> I'm  having trouble with matrixMultiply.  I've created two 1 x 20
> vectors (arrays) named Prob and V.  I want to compute the dot product
> (for example, the expected value of V in statistics), which is
> 
> prob[1] x V[1] + prob[2] x V[2] + ... + prob[20] x V[20]
> 
> but it's not clear whether MetaCard treats vectors as columns or
> rows by default.  All of the following result in error messages:
> 
> matrixMultiply(prob,V) 
> 
> matrixMultiply(transpose(prob),V)
> 
> matrixMultiply(prob,transpose(V))
> 
> Any help would be much appreciated.
> 
> Regards,
> 
> Greg
> 

transpose does not work on single column vectors. Transpose takes the index
[i,j] and replaces it with [j,i].

In your case, you need to create your vectors as prob[i,j]. Transpose ought
to work then.

Or you could just do this (and it might be a bit faster even):

function dotp x,y
    if keys(x) = keys(y) then
    repeat for each line i in keys(x)
      add x[i]*y[i] to sum
    end repeat
    return sum
end dotp

> Gregory Lypny
> Concordia University
> ___________________
> "Better for us if you don't understand."
> The Tragically Hip
> 
> http://rubbersoul.concordia.ca
> 

Raymond




More information about the metacard mailing list