comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » matrix multiplication
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
matrix multiplication [message #911] Mon, 22 March 1993 14:51 Go to next message
c1dje is currently offline  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 #36932 is a reply to message #911] Fri, 14 November 2003 09:48 Go to previous messageGo to next message
Haje Korth is currently offline  Haje Korth
Messages: 651
Registered: May 1997
Senior Member
The nice thing about IDL is that it is sooo hands-on. Just try it yourself
with a small matrix and check the result by hand:
a=indgen(3,3)
b=[1,2,3]
print,a#b
print,a##b

It's not that hard and definitely faster than waiting for a newsgroup
response.
(Most likely you wanted a##b)

Cheers,
Haje



"jhkim" <planets@dreamwiz.com> wrote in message
news:7652fb5d.0311140809.58ae466@posting.google.com...
> A and B are matrices
> How can I write an IDL expression for A * B (matrix multiplication)in
> mathematics(linear algebra). Which is right, A#B or A##B? I think A##B
> is right....
>
> Thank you.
>
> Best regards!
Re: matrix multiplication [message #63073 is a reply to message #911] Tue, 28 October 2008 13:59 Go to previous messageGo to next message
Chris[6] is currently offline  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 Go to previous messageGo to next message
David Fanning is currently offline  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 Go to previous message
Vince Hradil is currently offline  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 Go to previous message
russ[1] is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: DLM unload
Next Topic: DLM unload

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 16:00:59 PDT 2025

Total time taken to generate the page: 0.00650 seconds