Services & Resources / Wolfram Forums / MathGroup Archive
-----

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: [mg88043] Re: matrix of vectors - super slow
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Wed, 23 Apr 2008 04:05:36 -0400 (EDT)
  • References: <fukeuf$s67$1@smc.vnet.net>

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
> 
Make absolutely sure your matrices are composed of Real or Complex 
numbers by applying N[..] as necessary. Otherwise there is a danger of 
performing arithmetic on exact expressions composed of surds, fractions 
and factors of Pi. This can generate extremely complicated expressions 
which then collapse silently to real numbers as you plot them!

David Bailey
http://www.dbaileyconsultancy.co.uk


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