MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: matrix of vectors - super slow

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88050] Re: matrix of vectors - super slow
  • From: dh <dh at metrohm.ch>
  • Date: Wed, 23 Apr 2008 04:06:53 -0400 (EDT)
  • References: <fukeuf$s67$1@smc.vnet.net>


Hi,

here is a more mathematica like implementation.You should test it well, 

because I did not have the time to do it thoroughly. Is it correct that 

for Pint and SInt only one element of the 2x2 matrix is used? What is 

the Norm[..] doing? Further, there is no need to create 128^2 equal 

copies in BeamIn. I only give the changes, the definitions that are 

unchanged are eliminated:



BeamIn={{Sqrt[2]/2},{Sqrt[2]/2}};



x=Table[R ((2 i-n)-1),{i,n}];

y=Table[R ((2 i-m)-1),{i,m}];

PBeam=Outer[(r=Sqrt[#1^2+#2^2];

\[Theta]=ArcTan[#2/#1];

PPol.LaserRod[r,\[Theta],1*10^-3].QuarterWave[\[Pi]/2].LaserRod[r,\[Theta],1*10^-3].PPol.BeamIn)&,x,y];

SBeam=Outer[(r=Sqrt[#1^2+#2^2];

\[Theta]=ArcTan[#2/#1];

SPol.LaserRod[r,\[Theta],1*10^-3].QuarterWave[\[Pi]/2].LaserRod[r,\[Theta],1*10^-3].PPol.BeamIn)&,x,y];

PInt=Map[Norm[#[[1,1]]]^2&,PBeam,{2}];

SInt=Map[Norm[#[[2,1]]]^2&,SBeam,{2}];



hope this helps, Daniel



baaarnes at gmail.com wrote:

> I have an matrix of vectors where each element has to go through

> various transformations, that is each element has to be multiplied by

> a few different matrices.  Is there a more efficient way of doing that

> from what I am currently doing?

> 

> n = 128*1;

> m = 128*1;

> R = 1;

> BeamIn = Table[( {

>      {Sqrt[2]/2},

>      {Sqrt[2]/2}

>     } ), {i, n}, {j, m}];

> PBeam = Table[0, {i, n}, {j, m}];

> SBeam = Table[0, {i, n}, {j, m}];

> PInt = Table[0, {i, n}, {j, m}];

> SInt = Table[0, {i, n}, {j, m}];

> 

> HalfWave[\[Theta]_] = ( {

>      {Cos[-\[Theta]], Sin[-\[Theta]]},

>      {-Sin[-\[Theta]], Cos[-\[Theta]]}

>     } ).( {

>      {1, 0},

>      {0, Exp[-I \[Pi]]}

>     } ).( {

>      {Cos[\[Theta]], Sin[\[Theta]]},

>      {-Sin[\[Theta]], Cos[\[Theta]]}

>     } );

> QuarterWave[\[Theta]_] = ( {

>      {Cos[-\[Theta]], Sin[-\[Theta]]},

>      {-Sin[-\[Theta]], Cos[-\[Theta]]}

>     } ).( {

>      {1, 0},

>      {0, Exp[-I \[Pi]/2]}

>     } ).( {

>      {Cos[\[Theta]], Sin[\[Theta]]},

>      {-Sin[\[Theta]], Cos[\[Theta]]}

>     } );

> PPol = ( {

>     {1, 0},

>     {0, 0}

>    } );

> SPol = ( {

>     {0, 0},

>     {0, 1}

>    } );

> LaserRod[TT_, \[Theta]_, Q_] = ( {

>      {Cos[-\[Theta]], Sin[-\[Theta]]},

>      {-Sin[-\[Theta]], Cos[-\[Theta]]}

>     } ).( {

>      {Exp[-I *2.8 *TT^2*Q], 0},

>      {0, Exp[I *0.4 *TT^2* Q]}

>     } ).( {

>      {Cos[\[Theta]], Sin[\[Theta]]},

>      {-Sin[\[Theta]], Cos[\[Theta]]}

>     } );

> 

> For[i = 1, i <= n, i++,

>   For[j = 1, j <= m, j++,

>     x = R ((2 i - n) - 1);

>     y = R ((2 j - m) - 1);

>     r = Sqrt[x^2 + y^2];

>     \[Theta] = ArcTan[y/x];

>     PBeam[[i, j]] =

>      PPol.LaserRod[r, \[Theta], 1*10^-3].QuarterWave[\[Pi]/

>        2].LaserRod[r, \[Theta], 1*10^-3].PPol.BeamIn[[i, j]];

>     SBeam[[i, j]] =

>      SPol.LaserRod[r, \[Theta], 1*10^-3].QuarterWave[\[Pi]/

>        2].LaserRod[r, \[Theta], 1*10^-3].PPol.BeamIn[[i, j]];

>     PInt[[i, j]] = Norm[PBeam[[i, j]][[1, 1]]]^2;

>     SInt[[i, j]] = Norm[SBeam[[i, j]][[2, 1]]]^2;

>     ];

>   ];

> ListDensityPlot[PInt]

> ListDensityPlot[SInt]

> 

> Cheers

> 




  • Prev by Date: Re: Wolfram User Interface Research?
  • Next by Date: Re: matrix of vectors - super slow
  • Previous by thread: matrix of vectors - super slow
  • Next by thread: Re: matrix of vectors - super slow