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`}."\) > > Thanks in advance. > > 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[26]:= Clear[f] In[27]:= f[y_Real] := NIntegrate[y^2*x^2, {x, 0, 3}] In[28]:= 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[28]= {y -> 1.49071} In[32]:= InputForm[f[y/.root]-20] Out[32]//InputForm= -3.552713678800501*^-15 In[37]:= g[y_] := Integrate[y^2*x^2, {x, 0, 3}] In[38]:= NSolve[g[y]==20, y] Out[38]= {{y -> -1.49071}, {y -> 1.49071}} Daniel Lichtblau Wolfram Research
- References:
- How to evaluate a NIntegrate expression properly
- From: Yong Xiao <hardes@MIT.EDU>
- How to evaluate a NIntegrate expression properly