MathGroup Archive 2004

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

Search the Archive

Re: Re: newbie problem with NIntegrate

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49839] Re: [mg49806] Re: newbie problem with NIntegrate
  • From: Garry Helzer <gah at math.umd.edu>
  • Date: Tue, 3 Aug 2004 01:11:11 -0400 (EDT)
  • References: <cei8o5$2he$1@smc.vnet.net> <200408012248.SAA12999@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Aug 1, 2004, at 6:48 PM, David W. Cantrell wrote:

> "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
>
>

What version are you using? The last expression is returned unevaluated 
on my system ( version 5.0.1, Mac OS 10.3.4).

Garry Helzer
gah at math.umd.edu


  • Prev by Date: Re: newbie problem with NIntegrate
  • Next by Date: Re: Re: PutAppend Command and Data Output
  • Previous by thread: Re: newbie problem with NIntegrate
  • Next by thread: Re: newbie problem with NIntegrate