matrix multiplication [message #911] |
Mon, 22 March 1993 14:51  |
c1dje
Messages: 2 Registered: March 1993
|
Junior Member |
|
|
I am trying to apply a list of rotation matrices to a matching list
of vectors, i.e. a vector of three-vectors and a vector of 3x3 matrices. I
can correctly apply a rotation matrix between a vector and a matrix, but
now the vector is a list of vectors and the matrix is a list of matrices.
I could handle all of this with a "for" loop, but that is inefficient in
IDL; I would like IDL to loop over all of the indices internally. My
problem is creating the rotation matrix with the proper ordering for matrix
multiply (#).
Previously I multiplied a 3-vector by a 3x3 matrix:
[v1,v2,v3] # [[a1,a2,a3],[a4,a5,a6],[a7,a8,a9]]
but now all of the variables are vectors (of matching length) so V is Nx3
and A is Nx3x3. I can transpose V so that it is 3xN but IDL requires the
argument of transpose to be 1D or 2D, not 3D as the rotation matrix
appears. How do I generate the 3x3xN matrix from nine vectors of length N?
Will this collective matrix multiply even work as I expect?
David
============================================================ ===================
David Edelsohn T.J. Watson Research Center
c1dje@watson.ibm.com P.O. Box 218
+1 914 945 3011 (Tieline 862) Yorktown Heights, NY 10598
"The Church doesn't have problems with sex; the world does" -- Vatican official
"A good theory should fit on a T-shirt" -- Astronomer at Jan 1992 AAS meeting
|
|
|
|
Re: matrix multiplication [message #63073 is a reply to message #911] |
Tue, 28 October 2008 13:59   |
Chris[6]
Messages: 84 Registered: July 2008
|
Member |
|
|
On Oct 28, 8:42 am, David Fanning <n...@dfanning.com> wrote:
> russ writes:
>> Probably a stupid question but I haven't used idl for a while
>
>> Is there a quicker way of doing this?
>
>> a=fltarr(1000,20)
>> b=fltarr(20)
>
>> for i=0,999 do begin
>> a(i,*)=a(i,*)*b
>> endfor
>
> It might be faster to realize the end result is going
> to be an array of zeros than it would be to actually
> write the code. :-)
>
> But, I think you want this:
>
> a = a * rebin(reform(b, 1, 20) ,1000, 20)
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Coyote's Guide to IDL Programming (www.dfanning.com)
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
I also like this shortcut for reform:
a = a * rebin(1#b, 1000, 20)
chris
|
|
|
Re: matrix multiplication [message #63080 is a reply to message #911] |
Tue, 28 October 2008 11:42   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
russ writes:
> Probably a stupid question but I haven't used idl for a while
>
> Is there a quicker way of doing this?
>
> a=fltarr(1000,20)
> b=fltarr(20)
>
> for i=0,999 do begin
> a(i,*)=a(i,*)*b
> endfor
It might be faster to realize the end result is going
to be an array of zeros than it would be to actually
write the code. :-)
But, I think you want this:
a = a * rebin(reform(b, 1, 20) ,1000, 20)
Cheers,
David
--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: matrix multiplication [message #63157 is a reply to message #63080] |
Tue, 28 October 2008 19:17  |
Vince Hradil
Messages: 574 Registered: December 1999
|
Senior Member |
|
|
On Oct 28, 1:42 pm, David Fanning <n...@dfanning.com> wrote:
> russ writes:
>> Probably a stupid question but I haven't used idl for a while
>
>> Is there a quicker way of doing this?
>
>> a=fltarr(1000,20)
>> b=fltarr(20)
>
>> for i=0,999 do begin
>> a(i,*)=a(i,*)*b
>> endfor
>
> It might be faster to realize the end result is going
> to be an array of zeros than it would be to actually
> write the code. :-)
>
> But, I think you want this:
>
> a = a * rebin(reform(b, 1, 20) ,1000, 20)
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Coyote's Guide to IDL Programming (www.dfanning.com)
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Cool - I would have definitely thrown in a TRANSPOSE...
i.e. a = a * transpose(rebin(b,20,1000)), but your way has to be
faster - I'm not in front of my IDL machine so I can't check it.
Vince
P.S. what is it with me and speed these days?
|
|
|
Re: matrix multiplication [message #63168 is a reply to message #63073] |
Tue, 28 October 2008 14:32  |
russ[1]
Messages: 8 Registered: April 2008
|
Junior Member |
|
|
On 28 Oct, 20:59, Chris <beaum...@ifa.hawaii.edu> wrote:
> On Oct 28, 8:42 am, David Fanning <n...@dfanning.com> wrote:
>
>
>
>> russ writes:
>>> Probably a stupid question but I haven't used idl for a while
>
>>> Is there a quicker way of doing this?
>
>>> a=fltarr(1000,20)
>>> b=fltarr(20)
>
>>> for i=0,999 do begin
>>> a(i,*)=a(i,*)*b
>>> endfor
>
>> It might be faster to realize the end result is going
>> to be an array of zeros than it would be to actually
>> write the code. :-)
>
>> But, I think you want this:
>
>> a = a * rebin(reform(b, 1, 20) ,1000, 20)
>
>> Cheers,
>
>> David
>> --
>> David Fanning, Ph.D.
>> Coyote's Guide to IDL Programming (www.dfanning.com)
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
> I also like this shortcut for reform:
> a = a * rebin(1#b, 1000, 20)
>
> chris
many thanks to you both
Russ
|
|
|