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

Re: Piecewise Integration Woes

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63445] Re: Piecewise Integration Woes
  • From: Maxim <m.r at inbox.ru>
  • Date: Sat, 31 Dec 2005 06:40:49 -0500 (EST)
  • References: <dotn06$su2$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Wed, 28 Dec 2005 09:47:50 +0000 (UTC), Bruce Colletti  
<vze269bv at verizon.net> wrote:

> Re Mathematica 5.2 under WinXP.
>
> h, g, and (presumably f) are continuous functions.
>
> So, what causes the  NIntegrate::slwcon warning?  Although continuous,  
> g(h(x)) isn't always differentiable.  Could this be the cause?
>
> Thankx.
>
> Bruce
>
> ------------
>
>
> T = {{16, 113.32}, {20, 68.11}, {900, 0.15}, {1000, 0.13}};
>
> f = Interpolation@T;
>
> h[r_] := Piecewise[{{T[[1, 2]], r < T[[
> 1, 1]]}, {f@r, T[[1, 1]] <= r < T[[-1, 1]]}}, T[[-1, 2]]];
>
> g[x_] := Piecewise at {{0.99, 29 <= x}, {0.99(x - 14.5)/(29 -
>             14.5), 14.5 <= x < 29}}
>
> NIntegrate[g[h@r], {r, 14, 40}, MaxRecursion -> 30]
>

Yes, the corner points are the cause of the problem. You can either  
increase MinRecursion as well, or, preferably, find the points where the  
integrand is not smooth. PiecewiseExpand gives us the condition 14.5 <=  
InterpolatingFunction[...] < 29. Let's find the edges of that interval:

In[5]:= a = r /. FindRoot[f[r] == 14.5, {r, 16}]

Out[5]= 24.83357

In[6:= b = r /. FindRoot[f[r] == 29, {r, 16}]

Out[6]= 23.516274

In[7]:= NIntegrate[g[h[r]], {r, 14, b, a, 40},
   AccuracyGoal -> 10, PrecisionGoal -> Infinity] // Timing

Out[7]= {0.031*Second, 10.072554}

In[8]:= NIntegrate[g[h[r]], {r, 14, 40},
   MinRecursion -> 10, MaxRecursion -> 20,
   AccuracyGoal -> 10, PrecisionGoal -> Infinity] // Timing

Out[8]= {0.203*Second, 10.072554}

In[9]:= %[[2]] - %%[[2]]

Out[9]= -1.0480505*^-11

We can see that the difference between the results is within 10^-10 as  
expected.

Maxim Rytin
m.r at inbox.ru


  • Prev by Date: How to output float in Fortran form from Mathematica high precision number
  • Next by Date: Re: How to show level of accuracy from original data FROM Re: Coefficients from Fit as a list?
  • Previous by thread: Re: Piecewise Integration Woes
  • Next by thread: Can I assign a style to a GridBox row?