MathGroup Archive 2012

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

Search the Archive

Re: FindRoot and parameters in NIntegrate

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124529] Re: FindRoot and parameters in NIntegrate
  • From: A Retey <awnl at gmx-topmail.de>
  • Date: Sun, 22 Jan 2012 07:29:10 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jfe3jq$a16$1@smc.vnet.net>

Hi,

> I am using Mathematica 8 to solve for parameters in an integral and an auxiliary equation.  A prototypical problem is
>
> FindRoot[{1 + a + b , NIntegrate[a + b x, {x, 0, 1}]}, {{a, 0}, {b, 0}}]
>
> Mathematica reports the correct answer for the parameters a and b:
>
> {a ->  1., b ->  -2.}
>
> But it also reports two error messages:
>
> NIntegrate::inumr: The integrand a+b x has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,1}}.>>
>
> NIntegrate::izero: Integral and error estimates are 0 on all integration subregions. Try increasing the value of the MinRecursion option. If value of integral may be 0, specify a finite value for the AccuracyGoal option.>>
>
> I would appreciate any advice or comments on this problem or the error messages.
>

exactly speaking these are rather to be understood as warnings than 
errors, but Mathematica doesn't make a formal distinction between these. 
Here is what you need to do:

FindRoot[{1 + a + b,
   NIntegrate[a + b x, {x, 0, 1}, AccuracyGoal -> 8]},
  {{a, 0}, {b, 0}}, Evaluated -> False
  ]

Usually FindRoot will evaluate it's argument with symbolic parameters 
(a,b) so that it can see what it's actually working on which in general 
is a good idea and allows additional optimizations. In cases like here, 
where the evaluation will cause problems for nonnumerical values of the 
parameters, you can avoid that by setting the Evaluate option to False. 
Note that:

NIntegrate[a + b x, {x, 0, 1}]

will not evaluate but return exactly the input, so the evaluation will 
not do any harm despite of the warning message.

To avoid the other warning message you need just to do what it says: 
obviously FindRoot tries a parameter set that makes the integral zero 
(presumably it just tries a=0 and b=0). That makes the integrand zero 
and that's something that NIntegrate doesn't like and it is friendly 
enough to tell you. So do what the warning tells you and everything is 
fine. Be aware that there might be other warnings arising from 
NIntegrate for different problems, but numeric integration is a 
nontrivial tasks with many pitfalls like singularities, oscillating 
functions and alike. When using NIntegrate within FindRoot it the 
probability that you accidentally hit one of these corner cases is 
nonzero even for simple cases like this one.

hth,

albert




  • Prev by Date: Re: Tips for writing correct, non trivial Mathematica Libraries
  • Next by Date: Re: Locators disappearing in LocatorPane (although working)
  • Previous by thread: Re: FindRoot and parameters in NIntegrate
  • Next by thread: Locators disappearing in LocatorPane (although working)