Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

speed up numerical integration

  • To: mathgroup at smc.vnet.net
  • Subject: [mg59129] speed up numerical integration
  • From: "Ruth Lazkoz" <ruth.lazkoz at ehu.es>
  • Date: Sat, 30 Jul 2005 01:25:03 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

Let us suppose that chi2f2[om,w] is a previously (and efficiently) 
defined complicated function. Is there a way to speed up this other 
function?

chimar[(w_)?NumericQ] := -2Log[NIntegrate[Exp[-chi2f2[ 0.23 + omvar, 
w]]/2, {omvar, -0.07, 0.07}]]

The whole code would be for instance (thanks to Peter Pein)

In[1]:=
Nn = 50; z = #1 & ; mi = #1^2 & ; smi = #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, 1}];
rr[zz_, om_, w_] :=
rr[zz, om, w] = NIntegrate[f[x, om, w], {x, zz - 1, zz}] +
rr[zz - 1, om, w];
ff[zz_, om_, w_] := 5*Log[10, rr[zz, om, w]*(1 + zz)];
ci = Sum[1/smi[i]^2, {i, 1, Nn}];
chi2f2[(om_)?NumericQ, (w_)?NumericQ] :=
Module[{vec = ((mi[#1] - ff[z[#1], om, w])/smi[#1] & ) /@ Range[Nn]},
vec . vec - Total[vec/smi[Range[Nn]]]^2/ci];

In[2]:=chimar[(w_)?NumericQ] := -2Log[NIntegrate[Exp[-chi2f2[ 0.23 + 
omvar, w]]/2, {omvar, -0.07, 0.07}]]

In[3]:=
Timing[chimar[0.2]]
Out[3]=
{0. Second, chimar[0.2]}

Thanks so many.


  • Prev by Date: Re: silly questions?
  • Next by Date: Modeling and Array Problem
  • Previous by thread: Re: Mathematica 5.2 and mathssh
  • Next by thread: pairs and subsets challenge