MathGroup Archive 1998

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

Search the Archive

Re: Integrate vs. NIntegrate

Hi Andreas,

The simplest way to get NIntegrate and FindRoot to work together is to
give FindRoot two starting points so that it uses the Secant method
instead of Newton's method. The reason for your error message is that
when using Newton's method, Mathematica tries to evaluate the
derivative of your function. Thus,



{x -> 1.41421}

However, since Newton's method is usually preferable if possible, there
is a way to get Mathematica to use Newton's method. The trick is to
override Mathematica's calculation of the Jacobian as follows.

Define your function with NumericQ

f[x_?NumericQ] := NIntegrate[y,{y,0,x}] - 1

so that Mathematica is never tempted to evaluate the NIntegrate with a
symbolic limit. Then define the derivative

f /: D[f[x_],x_] := x

Now you can use FindRoot:

FindRoot[ f[x]==0, {x,0.25} ]


{x -> 1.41421}

Carl Woll
Dept of Physics
U of Washington

On 10 Jun 1998, Andreas Kull wrote:

> Hello all,
> who knows how I can get ride of the following type of problem with
> undefined limits in NIntegrate?
> In[1]:=FindRoot[NIntegrate[y,{y,0,x}]==1,{x,0.25}] NIntegrate::"nlim":
> "\!\(y\) = \!\(x\) is not a valid limit of integration."
> NIntegrate::"nlim": "\!\(y\) = \!\(x\) is not a valid limit of
> integration."
> NIntegrate::"nlim": "\!\(y\) = \!\(x\) is not a valid limit of
> integration."
> General::"stop": "Further output of \!\(NIntegrate :: \"nlim\"\) will be
> suppressed during this calculation." Out[1]:={x->1.41421}
> It would be nice to have the above example working like Integrate, i.e.
> In[2]:=FindRoot[Integrate[y,{y,0,x}]==1,{x,0.25}] Out[2]:={x->1.41421}
> thanks,
> Andreas

  • Prev by Date: Re: Complex Conjugation
  • Next by Date: Re: Exporting lists from Mathematica 3.0 to Excel
  • Previous by thread: RE: Integrate vs. NIntegrate
  • Next by thread: Re: Integrate vs. NIntegrate