Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*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 2004

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

Search the Archive

Re: newbie problem with NIntegrate

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49806] Re: newbie problem with NIntegrate
  • From: "David W. Cantrell" <DWCantrell at sigmaxi.org>
  • Date: Sun, 1 Aug 2004 18:48:38 -0400 (EDT)
  • References: <cei8o5$2he$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

"Xiaoxun" <dbjunxiao at hotmail.com> wrote:
> Hi, all,
>
> Please advices:
>
> Geom = (200 >=x>= 100 && 50 >= y >= -50 && -20 <= z <= 20);
> gr[x_, y_, z_] := 2 /; Geom;
> gr[x_, y_, z_] := 0 /; ! (Geom);
> N[Integrate[gr[x, y, z], {x, 0, 300}, {y, -100, 100}, {z, -30, 30}]
> This gives a result of 799995.
> However, if changing the x range to {x,0,600} results 799993.
>                                 and {x,0,900} results 0;
>
> So what could we do to ensure the right answer?

First, let me note that in problems like this, it's often good to write the
function using UnitStep. For example, in your problem, it can be written as

gr[x_, y_, z_] := 2(UnitStep[x - 100] - UnitStep[x - 200])(UnitStep[y + 50]
                   - UnitStep[y - 50])(UnitStep[z + 20] - UnitStep[z - 20])

However, doing that in your problem does not happen to be necessary. Just
get rid of the N[...]. (Did you notice the warning messages you were
getting?) In other words, the following works fine (regardless of whether
the upper limit of integration for x is 300, as shown, or 600 or 900):

In[1]:=
Geom = (200 >= x >= 100 && 50 >= y >= -50 && -20 <= z <= 20);
gr[x_, y_, z_] := 2 /; Geom; gr[x_, y_, z_] := 0 /; ! (Geom);
Integrate[gr[x, y, z], {x, 0, 300}, {y, -100, 100}, {z, -30, 30}]

Out[1]=
800000

David Cantrell


  • Prev by Date: Re: newbie problem with NIntegrate
  • Next by Date: Efficiency of algorithms which compute Fibonacci numbers using the primary formula (was: contains 1044938 decimal digits)
  • Previous by thread: Re: newbie problem with NIntegrate
  • Next by thread: Re: Re: newbie problem with NIntegrate