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
Andreas wrote:
|
|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} |
|
You gave FindRoot one starting value, so it will use Newton's method.
To use Newton's method FindRoot needs to compute
D[NIntegrate[y,{y,0,x}]-1,x]
In the line below we see Mathematica can do this, but it produces a
message each time it tries to.
In[1]:=
D[NIntegrate[y,{y,0,x}]-1,x]
NIntegrate::"nlim": "\!\(y\) = \!\(x\) is not a valid limit of
integration."
Out[1]=
x
_______________________________
To prevent this problem you can:
1- Tell the FindRoot algorithm that the derivative is (x) using the
Jacobian option.
2- Give FindRoot two starting values. This way it will use either
Brent's method or Secant method. They will not have this problem
because they don't need to compute the derivative.
3- Evaluate Off[NIntegrate::nlim], and display of the message will be
suppressed. Then you can use you initial attempt, and it will work
just fine.
- See the lines below -
_____________________________
In[2]:=
FindRoot[NIntegrate[y,{y,0,x}]==1,{x,0.25},Jacobian->x]
Out[2]=
{x\[Rule]1.41421}
In[3]:=
FindRoot[NIntegrate[y,{y,0,x}]==1,{x,0.25,0.3}]
Out[3]=
{x\[Rule]1.41421}
In[4]:=
Off[NIntegrate::nlim]
In[5]:=
FindRoot[NIntegrate[y,{y,0,x}]==1,{x,0.25}]
Out[5]=
{x\[Rule]1.41421}
___________________________
Ted Ersek
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,
FindRoot[NIntegrate[y,{y,0,x}]==1,{x,0.25,0.5}]
returns
{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} ]
returns
{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}
>
In[1]:= FindRoot[NIntegrate[y,{y,0,x}]==1,{x,0.25,5}]
Out[1]={x ->1.41421}
Kevin