MathGroup Archive 2004

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

Search the Archive

Re: Do-loop conversion


Hi Rich, 

<snippage>

Do[
     wavevectmap := wavetabc[revdelta, revbeta, phi];
     leftvectmap := leftvectmapc[wavevectmap];
     thtest := thtestcomp[revrough, leftvectmap, wavevectmap];
     maproughrev := roughrevcomp[thtest];
     coeffmap := coeffcomp[wavevectmap, leftvectmap, maproughrev];
     phasemap := phasecomp[wavevectmap, revthick];
     coeffs := fcoeffcomp[coeffmap, phasemap];
     recurr[prior_, {fc_, pf_}] := (fc + (prior*pf^2))/(1 +
(fc*prior*pf^2));
     intensity := intensitycomp[Fold[recurr, 0, coeffs ]];
     newdata = newdatacomp[phi, intensity, params];
     newc = AppendTo[newc, newdata],
     {phi, phistart, phiend, phiinc}]

<snippage>

 -------------------

An easy(!) way into a functional style might be ...

1. define phirange = Range[phistart, phiend, phiinc];
2. map this range using

newc = (
	wavevectmap := wavetabc[revdelta, revbeta, #];
     leftvectmap := leftvectmapc[wavevectmap];
     thtest := thtestcomp[revrough, leftvectmap, wavevectmap];
     maproughrev := roughrevcomp[thtest];
     coeffmap := coeffcomp[wavevectmap, leftvectmap, maproughrev];
     phasemap := phasecomp[wavevectmap, revthick];
     coeffs := fcoeffcomp[coeffmap, phasemap];
     recurr[prior_, {fc_, pf_}] := (fc + (prior*pf^2))/(1 +
(fc*prior*pf^2));
     intensity := intensitycomp[Fold[recurr, 0, coeffs ]];
     newdata = newdatacomp[#, intensity, params];
)& /@ phirange

Another speed improvement might be to precompute wavevectmap and using it as
a table lookup; from your code excerpt, there's no need to have this inside
the loop.

Regards,

Dave.


  • Prev by Date: Re: 3D Screensavers for Mathematica users
  • Next by Date: RE: Re: Comparison of Mathematica on Various Computers
  • Previous by thread: Re: Do-loop conversion
  • Next by thread: Function Solve from its Property