MathGroup Archive 2008

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

Search the Archive

Re: NIntegrate problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84728] Re: NIntegrate problem
  • From: Norbert Marxer <marxer at mec.li>
  • Date: Fri, 11 Jan 2008 22:05:23 -0500 (EST)
  • References: <fm7dur$euo$1@smc.vnet.net>

On 11 Jan., 10:47, Outof Africa <renaysi... at gmail.com> wrote:
> Hi All
>
> I would really appreciate any help on the following code. I get errors
> (a lot of them) in the from In[6] onwards....
>
> =========================
==========================
==================
> In[1]:= ndist = NormalDistribution[0, 1];
>
> In[2]:= a = Quantile[ndist, 0.05]
>
> Out[2]= -1.64485
>
> In[3]:= f[x_?NumericQ] := 1/Sqrt[2 \[Pi]] Exp[-x^2/2]
>
> In[4]:= g[t_?NumericQ] :=
> =A0NIntegrate[f[u]*CDF[ndist, (t - u)], {u, a, \[Infinity]}]
>
> In[5]:= b = b /. FindRoot[g[b] == 0.05, {b, -1}]
>
> Out[5]= -2.03202
>
> In[6]:= h[x_?NumericQ] := =A0NIntegrate[ =A0f[u]*Exp[-(x - u)^2/2]/Sqr=
t[2 \
> [Pi]], {u, a, \[Infinity]}]
>
> In[7]:= gg[t_?NumericQ] := =A0Integrate[ =A0h[u]*CDF[ndist, (t - u)/Sq=
rt[\
> [Delta]]], {u, b, \[Infinity]}]
>
> In[8]:= c = c /. FindRoot[gg[c] == 0.05, {c, -2}]

Hello

I took your code and made two modifications:

- I set \[Delta] = 2; (because it was not set).
- I replaced Integrate by NIntegrate in the definition of gg.

Then it seems to work OK:

ndist = NormalDistribution[0, 1];
{"a", a = Quantile[ndist, 0.05]}

f[(x_)?NumericQ] := (1/Sqrt[2*Pi])*Exp[-x^2/2]
g[(t_)?NumericQ] :=
 NIntegrate[f[u]*CDF[ndist, t - u], {u, a, Infinity}]
{"b", b = b /. FindRoot[g[b] == 0.05, {b, -1}]}

h[(x_)?NumericQ] :=
 NIntegrate[f[u]*(Exp[-(x - u)^2/2]/Sqrt[2*Pi]), {u, a, Infinity}]
\[Delta] = 2;
gg[(t_)?NumericQ] :=
 NIntegrate[
  h[u]*CDF[ndist, (t - u)/Sqrt[\[Delta]]], {u, b, Infinity}]
{"c", c = c /. FindRoot[gg[c] == 0.05, {c, -2}]}


The following plots show the different functions. Note that the
calculation of the curve for gg[x] takes quite a while (some minutes
on my coomputer).

(Plot[#1[x], {x, -5, 5}, ImageSize -> 200, PlotLabel -> #1] &) /@ {f,
CDF[ndist, #1] &, g, h,gg} // Column

It would probably be a good idea (for speeding up the calculations) to
approximate these (smooth) functions by Interpolation.

Best Regards
Norbert Marxer


  • Prev by Date: Re: question from amateur, why no demonstration for intersecting
  • Next by Date: Re: Selecting dynamically from a list
  • Previous by thread: NIntegrate problem
  • Next by thread: updating colors in parametricplot3D