Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8058 > unrolled thread

FindRoot and parameters in NIntegrate

Started bygac <g.crlsn@gmail.com>
First post2012-01-21 10:21 +0000
Last post2012-01-22 12:34 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  FindRoot and parameters in NIntegrate gac <g.crlsn@gmail.com> - 2012-01-21 10:21 +0000
    Re: FindRoot and parameters in NIntegrate danl@wolfram.com - 2012-01-22 12:29 +0000
    Re: FindRoot and parameters in NIntegrate A Retey <awnl@gmx-topmail.de> - 2012-01-22 12:34 +0000

#8058 — FindRoot and parameters in NIntegrate

Fromgac <g.crlsn@gmail.com>
Date2012-01-21 10:21 +0000
SubjectFindRoot and parameters in NIntegrate
Message-ID<jfe3jq$a16$1@smc.vnet.net>
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. 

Thanks.

gac

[toc] | [next] | [standalone]


#8087

Fromdanl@wolfram.com
Date2012-01-22 12:29 +0000
Message-ID<jfgves$pk4$1@smc.vnet.net>
In reply to#8058
(1) Only let the NIntegrate work when parameters have numeric values.

(2) Specify a finite AccuracyGoal so as to avoid messages about trouble with the result and error estimates.

In[272]:= 
integ[a_?NumericQ, b_?NumericQ] := 
 NIntegrate[a + b x, {x, 0, 1}, AccuracyGoal -> 10]

In[273]:= FindRoot[{1 + a + b, integ[a, b]}, {{a, 0}, {b, 0}}]

Out[273]= {a -> 1., b -> -2.}

Daniel Lichtblau
Wolfram Research

[toc] | [prev] | [next] | [standalone]


#8098

FromA Retey <awnl@gmx-topmail.de>
Date2012-01-22 12:34 +0000
Message-ID<jfgvpd$pne$1@smc.vnet.net>
In reply to#8058
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web