Re: FindRoot[ NIntegrate[...] ...] works but generates "NIntegrate::nlim"

*To*: mathgroup at smc.vnet.net*Subject*: [mg72500] Re: FindRoot[ NIntegrate[...] ...] works but generates "NIntegrate::nlim"*From*: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>*Date*: Wed, 3 Jan 2007 01:15:06 -0500 (EST)*Organization*: The Open University, Milton Keynes, UK*References*: <end7ko$iek$1@smc.vnet.net>

William McHargue wrote: > Hello, > > I wish to solve for an integration result to equal a given value while > varying the upper limit of the integration. It seems a straightforward > thing to do, and in fact it finds the numerical answer, but it > generates an error message at the beginning of the root solving > operation. I create a function to perform a numerical integration with > a passed upper limit of integration: > > In[1]:= integralFunction[upperLimit_] := NIntegrate[x, {x, 0, > upperLimit}] > > > Then I create a function to find a result of this integration that > equals a supplied value with the upper limit of integration as the > independent variable: > > In[2]:= rootOfIntegralFunction[solveForValue_] := > FindRoot[integralFunction[u] == solveForValue, {u, 1}, > EvaluationMonitor :> Print[u]] > > > (I use the EvaluationMonitor to print the value of "u" as it searches > for the solution.) > > When I execute the following I get an error message, yet it finds the > correct result: > > In[3]:= rootOfIntegralFunction[12.5] > > NIntegrate::nlim : x = u is not a valid limit of integration. > More... > > 1. > > 13. > > 2.2 > > 6.78182 > > 4.3982 > > 5.04117 > > 5.00017 > > 5. > > 5. > > Out[3]= {u->5.} > > > > If anyone has any insight into this behavior please let me know. Thank > you! > > Bill. > Hi Bill, The function integralFunction is called regardless of the type of the argument u. To prevent that, modify the definition as follows: integralFunction[upperLimit_?NumberQ] := NIntegrate[x, {x, 0, upperLimit}] Happy New Year, Jean-Marc