Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
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
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!
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.")
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
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
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?