Re: double loop
- To: mathgroup at smc.vnet.net
- Subject: [mg113019] Re: double loop
- From: "Nasser M. Abbasi" <nma at 12000.org>
- Date: Mon, 11 Oct 2010 05:16:36 -0400 (EDT)
- References: <i8s5f9$93p$1@smc.vnet.net>
- Reply-to: nma at 12000.org
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 the
> contour plot desidered. The colours should be the different correlation
> coefficient and it is not the case.
> I will be grateful if you could help
> Maria
> Â
> 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ï?¬}],{i,1,Length[Dataspectrum]}];
> 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[TabOmegalambda]}]
> Flatten[LxOmegalambda,2]
> ListContourPlot[Flatten[LxOmegalambda,2],PlotRange
> ->All,FrameLabel
> ->{"Omega_M ","Omega_lambda"}]
>
--Nasser