MathGroup Archive 2008

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

Search the Archive

matrix of vectors - super slow

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88038] matrix of vectors - super slow
  • From: baaarnes at gmail.com
  • Date: Tue, 22 Apr 2008 06:30:10 -0400 (EDT)

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: Re: Defining derivatives
  • Next by Date: Re: Re: Timing
  • Previous by thread: Re: Re: installing Playe rPro killed using Mathematica itself: BEWARE!
  • Next by thread: Re: matrix of vectors - super slow