       Re: How to evaluate a NIntegrate expression properly

• To: mathgroup at smc.vnet.net
• Subject: [mg39730] Re: [mg39698] How to evaluate a NIntegrate expression properly
• From: Daniel Lichtblau <danl at wolfram.com>
• Date: Mon, 3 Mar 2003 23:50:46 -0500 (EST)
• References: <200303030924.EAA20679@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Yong Xiao wrote:
>
> Hi,
> I have a problem regarding to how to use NIntegrate and NSolve together.
> A sampe is as follwing:
>
> f[y_] := NIntegrate[y^2*x^2, {x, 0, 3}]
> NSolve[f[y] == 20, y]
>
> Complaint:
> \!\(NIntegrate::"inum" \(\(:\)\(\ \)\) "Integrand \!\(2.25`  \\\\  y\^2\)
> is
>     not numerical at \!\({x}\) = {1.5`}."\)
>
>
> X.Y.

You really cannot use that pair together because NSolve wants explicit
polynomial input whereas NIntegrate cannot return a symbolic result,
polynomial or otherwise. You can use together either NIntegrate and
FindRoot or Integrate and NSolve. I illustrate both possibilities below.

In:= Clear[f]

In:= f[y_Real] := NIntegrate[y^2*x^2, {x, 0, 3}]

In:= root = FindRoot[f[y]==20, {y,0}]

NIntegrate::ploss:
Numerical integration stopping due to loss of precision. Achieved
neither
the requested PrecisionGoal nor AccuracyGoal; suspect one of the
following: highly oscillatory integrand or the true value of the
integral
is 0. If your integrand is oscillatory try using the option
Method->Oscillatory in NIntegrate.

FindRoot::symd:
Unable to automatically compute the symbolic derivative of {-20 +
f[y]}
with respect to the arguments {y}
. Numerical approximations to derivatives will be used instead.

NIntegrate::ploss:
Numerical integration stopping due to loss of precision. Achieved
neither
the requested PrecisionGoal nor AccuracyGoal; suspect one of the
following: highly oscillatory integrand or the true value of the
integral
is 0. If your integrand is oscillatory try using the option
Method->Oscillatory in NIntegrate.

Out= {y -> 1.49071}

In:= InputForm[f[y/.root]-20]
Out//InputForm= -3.552713678800501*^-15

In:= g[y_] := Integrate[y^2*x^2, {x, 0, 3}]

In:= NSolve[g[y]==20, y]
Out= {{y -> -1.49071}, {y -> 1.49071}}

Daniel Lichtblau
Wolfram Research

```

• Prev by Date: RE: ugly Plot Eigenvalues ?
• Next by Date: simulation and sampling with Mathematica
• Previous by thread: How to evaluate a NIntegrate expression properly
• Next by thread: Re: How to evaluate a NIntegrate expression properly