Mathematica 9 is now available
Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1995

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

Search the Archive

Re: Re: Problems with NIntegrate

  • To: mathgroup at
  • Subject: [mg1805] Re: [mg1692] Re: [mg1645] Problems with NIntegrate
  • From: Allan Hayes <hay at>
  • Date: Mon, 31 Jul 1995 23:08:14 -0400

(Two other ways)

In [mg1645] Problems with NIntegrate
Ian Barringer, Ian.Barringer at

> HI,
> 	I have come up against a problem in Mathematica I hope
>	someone in this group may be able to explain to me.
> 	I have defined a function as follows;
> 	fp[p_]=Sqrt[(x^2-1)/(p^2-x^2)]
> 	which I wish to integrate numerically. This I can do with
> 	integer values of p:
> 	NIntegrate[fp[6],{x,1,6}]
> 	= 5.69279
> 	However, if I set p as a real value, such as:
> 	NIntegrate[fp[6.2],{x,1,6.2}]
> 	I get an inexact arithmetic error, and no answer.

In [mg1692]  John Fulz <jfultz at>

> It *would* affect both integer and real values of p identically,  
if > it weren't for those tiny little errors computers are always  
prone > to making in the last digit of machine precision  
calculations.  I
> was able to get your answer to calculate on my machine with:
> In[24]:= NIntegrate[fp[6.2], {x, 1, 6.2 - 2 $MachineEpsilon}]
> Out[24]= 5.90009

Here are two variants that enable us to stand back a little more.
I unformat the answers to show more digits
First John's form:

NIntegrate[fp[6.2],{x,1,6.2- 2 $MachineEpsilon}]

		N[ NIntegrate[fp[6.2], {x,1,6.2}] ],

Using Unevaluated:

	Unevaluated[NIntegrate[fp[6.2], {x,1,6.2}]],
The form using Unevaluated is likely to be the most accurate  
because the rationalization is done on the atomic parts of the  
integral before evaluation (eg before 6.2^2 becomes 38.44), but it  
cannot automatically deal with symbolic constants like Pi or other  
parts that evaluate to numbers. However we could try rewriting the  
integral to get round this dificulty.

Here is how the block form copes with Pi:

		N[ NIntegrate[fp[Pi], {x,1,Pi}] ],
	2.65548 + 5.57794 10    I

Whereas with the unevaluated form we get

	Power::infy: Infinite expression -- encountered.
	Power::infy: Infinite expression -- encountered.
   	Inexact arithmetic has caused {x} to take the value {3.14159}
     	where the integrand is singular.

	NIntegrate[fp[Pi], {x, 1, Pi}]
Allan Hayes,
De Montfort University Leicester
hay at

  • Prev by Date: TeX to Mathematica ???
  • Next by Date: Re: Re: Options in self-defined functions
  • Previous by thread: TeX to Mathematica ???
  • Next by thread: Re: Re: Options in self-defined functions