Re: Do-loop conversion
- To: mathgroup at smc.vnet.net
- Subject: [mg50283] Re: [mg50211] Do-loop conversion
- From: "David Annetts" <davidannetts at ihug.com.au>
- Date: Tue, 24 Aug 2004 06:22:30 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
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.