MathGroup Archive 2007

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

Search the Archive

Re: If & NIntegrate

  • To: mathgroup at smc.vnet.net
  • Subject: [mg72616] Re: If & NIntegrate
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Fri, 12 Jan 2007 05:49:45 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <eo4n7p$l72$1@smc.vnet.net>

Jouvenot, Fabrice wrote:
> Hi all !
> 
> I have a problem that I cannot resolve, so I hope some one here will be able to help me.
> 
> I am doing many calculus and some of them takes very very long time and other never converged. The fact is that I integrate (NIntegrate (1 or 2 dimensional)) functions that contains a IF.
> 
> These functions calculated a result and at some point I test if one part of the calculus is either positive or negative. If it is negative, I want the result to be equal to 0.
> 
> They have this pattern :
> function[x_]:==Module[{},
>   (different calculus to calculate f)
>   If[func[a]<0, 0, func[a]];
> ];
> 
> And after :
>  b==NIntegrate[function[x],{...
> 
> So I am looking for a solution to have a quick integration of this function

<snip>

You should use the *Boole* [1] rather than an *If*: "Boole[expr] yields 
1 if expr is True and 0 if it is False."

For instance,

Boole[func[a]>0]*func[a]

Sections 3.5.9, "Integrals over Regions" [2], and 3.2.3, "Piecewise 
Functions" [3], of _The Mathematica Book_ may be of interest too.

Regards,
Jean-Marc

[1] http://documents.wolfram.com/mathematica/functions/Boole

[2] http://documents.wolfram.com/mathematica/book/section-3.5.9

[3] http://documents.wolfram.com/mathematica/book/section-3.2.3


  • Prev by Date: Re: ListDimension function
  • Next by Date: An Introduction to Programming with Mathematica, Third Edition
  • Previous by thread: If & NIntegrate
  • Next by thread: Mathematica newbie