Re: hints to speed up numerical integration?
- To: mathgroup at smc.vnet.net
- Subject: [mg60138] Re: [mg60114] hints to speed up numerical integration?
- From: Chris Chiasson <chris.chiasson at gmail.com>
- Date: Sun, 4 Sep 2005 03:02:01 -0400 (EDT)
- References: <200509030606.CAA19051@smc.vnet.net>
- Reply-to: chris.chiasson at gmail.com
- Sender: owner-wri-mathgroup at wolfram.com
I can't get your code to work :-[ On 9/3/05, Ruth Lazkoz <ruth.lazkoz at ehu.es> wrote: > > 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. > > Thanks for your cooperation, > > 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} > > -- Chris Chiasson http://chrischiasson.com/ 1 (810) 265-3161
- References:
- hints to speed up numerical integration?
- From: "Ruth Lazkoz" <ruth.lazkoz@ehu.es>
- hints to speed up numerical integration?