MathGroup Archive 2007

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg72494] Re: [mg72493] FindRoot[ NIntegrate[...] ...] works but generates
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Wed, 3 Jan 2007 00:50:59 -0500 (EST)
  • Reply-to: hanlonr at cox.net

Restrict the definition of integralFunction to numeric arguments.

integralFunction[upperLimit_?NumericQ] :=
    NIntegrate[x, {x, 0, upperLimit}];


Bob Hanlon

---- William McHargue <William at McHargue.Org> 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.
> 

--

Bob Hanlon
hanlonr at cox.net



  • Prev by Date: Is there Options for a variable
  • Next by Date: default format for importing data into mathematica
  • Previous by thread: Re: Is there Options for a variable
  • Next by thread: default format for importing data into mathematica