hints to speed up numerical integration?

• To: mathgroup at smc.vnet.net
• Subject: [mg60114] hints to speed up numerical integration?
• From: "Ruth Lazkoz" <ruth.lazkoz at ehu.es>
• Date: Sat, 3 Sep 2005 02:06:01 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

Dear colleagues,

I would like to speed up this code, because I have to minimize the
function chi2mar defined below. I have tried Compiled -> True in the
numerical integrals but it would only make things worse.

Ruth Lazkoz

In[1]:=
datanw = {{0.0400, 36.38, 0.19}, {0.050, 36.84, 0.21}, {0.0307, 35.90,
0.20},
{0.0560, 37.31, 0.18}, {0.0331, 35.54, 0.20}, {0.0141, 34.13, 0.25},
{0.0460,
36.35, 0.21}, {0.0265, 35.64, 0.20}, {0.101, 38.73, 0.20}, {0.075,
37.77, 0.19}};

In[2]:=
ndat = 10;

In[3]:=
z = datanw[[#1, 1]] & ; mi = datanw[[#1, 2]] & ; smi
datanw[[#1, 3]] & ; SetAttributes[smi, Listable];
f[x_, om_, w_] := 1/Sqrt[om*(1 + x)^3 + ( 1 - om)*(1 + x)^(3*(1 +
w))];
rr[1, om_, w_] :=
rr[1, om, w] = NIntegrate[f[x, om, w], {x, 0, z [1]}, Compiled ->
False];
rr[i_?IntegerQ, om_, w_] :=
rr[i, om, w] =
rr[i - 1, om, w] +
NIntegrate[f[x, om, w], {x, z[i - 1], z[i]}, Compiled -> False];
ff[i_?IntegerQ, om_, w_] := 5*Log[ 10, rr[i, om, w]*(1 + z[i])]; ci =
Sum[1/smi[i]^2, {i, 1, ndat}];
chi2f2[(om_)? NumericQ, (w_)?NumericQ] :=
Module[{vec = ((mi[#1] - ff[#1, om, w])/ smi[#1] & ) /@ Range[ndat]},
vec . vec - Total[vec/smi[Range[ndat]]]^2/ci]

In[4]:=
chi2mar[w_] := -2*
Log[NIntegrate[Exp[-chi2f2[0.23 + omvar, w]/2], {omvar, -0.07, 0.07},
Compiled -> False]]

In[5]:=
chi2mar[0.1] // Timing
Out[5]=
{0.078 Second, 15.5573}

In[6]:=
chi2mar[0.3] // Timing
Out[6]=
{0.078 Second, 15.7998}

• Prev by Date: Re: Another damn simplifying problem: ArcTan
• Next by Date: Re: Re: inconsistency with Inequality testing and Floor
• Previous by thread: Re: Another damn simplifying problem: ArcTan
• Next by thread: Re: hints to speed up numerical integration?