Re: double loop
- To: mathgroup at smc.vnet.net
- Subject: [mg113051] Re: double loop
- From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
- Date: Tue, 12 Oct 2010 04:26:10 -0400 (EDT)
- References: <i8s5f9$93p$1@smc.vnet.net> <i8uklb$ocu$1@smc.vnet.net>
Exact numbers may have an impact on speed and memory use, though. I remember one PseudoInverse calculation I did many years ago on a 20x90 matrix where I forgot to use reals (this was when I just started using Mathematica). This took my physics Dept. mainframe a week to calculate and resulted in a matrix of 20 MB, because all matrix entries consisted of ratios of very long integers. At that time, my mac had an internal memory of 4 MB. Problems were of a different order then... Cheers -- Sjoerd On Oct 11, 11:16 am, "Nasser M. Abbasi" <n... at 12000.org> wrote: > On 10/10/2010 3:44 AM, maria giovanna dainotti wrote: > > > Dear All, > > I cleared up the notebook but when I plot the picture I don't recover t= he > > contour plot desidered.=C2 The colours should be the different corre= lation > > coefficient and it is not the case. > > I will be grateful if you could help > > Maria > > =C2 > > h=0.71 > > ckms=299792.5 > > HubE[z_,Om_,Ol_]:=SQRT(Om*(1+z)^3+Ol)dL[z_,Om_,Ol_,h_]:=3.0856*1018= *106*ckms/(100*h)*(1+z)*NIntegrate[1/HubE[z,Om,Ol],{z,0,z},MaxRecursion > > > ->100] > > TabOmegalambda=Table[i,{i,0.1,1.1,0.05}] > > TabOmegaM=Table[i,{i,0.0,1.0,0.05}] > > I can't help you on the code below now. I just want to make a comment on > the above code. > > I think it is better to change the above table commands so they do not > use floats. Look at the difference > > In[168]:= N[TabOmegaM=Table[i,{i,0.0,1.0,0.05}],$MachinePrecision] > > Out[168]= {0., > 0.05, > 0.1, > 0.15000000000000002, > 0.2, > 0.25, > 0.30000000000000004, > 0.35000000000000003, > 0.4, > 0.45, > 0.5, > 0.55, > 0.6000000000000001, > 0.65, > 0.7000000000000001, > 0.75, > 0.8, > 0.8500000000000001, > 0.9, > 0.9500000000000001, > 1.} > > vs. > > In[167]:= N[TabOmegaM=Table[i,{i,0,1,1/20}],$MachinePrecision] > Out[167]= { > 0, > 0.05000000000000000, > 0.1000000000000000, > 0.1500000000000000, > 0.2000000000000000, > 0.2500000000000000, > 0.3000000000000000, > 0.3500000000000000, > 0.4000000000000000, > 0.4500000000000000, > 0.5000000000000000, > 0.5500000000000000, > 0.6000000000000000, > 0.6500000000000000, > 0.7000000000000000, > 0.7500000000000000, > 0.8000000000000000, > 0.8500000000000000, > 0.9000000000000000, > 0.950000000000000, > 1.000000000000000} > > You see the difference? > > Those Units of Least Precision (ULP) differences can sometimes end up > accumulating and might cause more differences in later computation. > > Always *try* to use exact numbers, (this is the advantage of using a CAS > system, so use it), until to the very end, or until when one must use > floats (may be for speed or printing, etc...) > > > > > LxOmegalambda={}; > > Do[ > > Ol=TabOmegalambda[[k]]; > > LxOmegaM={}; > > Do[ > > Om=TabOmegaM[[j]]; > > DataGood={}; > > Do[ > > idGRB=Dataspectrum[[i,1]]; > > z=Dataspectrum[[i,2]]; > > Espectrum=Dataspectrum[[i,3]]; > > Fx=Dataspectrum[[i,4]]; > > beta=Dataspectrum[[i,5]]; > > EisonewOm=4*p*dL[z,Om,Ol,h]2*(1+z)-2*Espectrum; > > Lx=4*p*dL[z,Om,Ol,h]2*(1+z)-(1+beta)*Fx; > > AppendTo[DataGood,{EisonewOm,Lx,z,idGRB,Om,O=EF =AC}],{i,1,Length[Datas= pectrum]}]; > > CLxEiso=N[Correlation[DataGood[[All,1]],DataGood[[All,2]]]]; > > AppendTo[LxOmegaM,{Om,Ol,CLxEiso}],{j,1,Length[TabOmegaM]}]; > > If[Ol+Om<2.2,AppendTo[LxOmegalambda,{LxOmegaM}]],{k,1,Length[TabOmegala= mbda]}] > > Flatten[LxOmegalambda,2] > > ListContourPlot[Flatten[LxOmegalambda,2],PlotRange > > ->All,FrameLabel > > ->{"Omega_M ","Omega_lambda"}] > > --Nasser