MathGroup Archive 1995

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

Search the Archive

Re: Using NIntegrate[] within FindRoot[] ??

  • To: mathgroup at
  • Subject: [mg2324] Re: Using NIntegrate[] within FindRoot[] ??
  • From: rknapp (Robert Knapp)
  • Date: Tue, 24 Oct 1995 02:14:29 -0400
  • Organization: Wolfram Research, Inc.

In article <DGvx8w.B2J at> a_kowald at (Axel Kowald) writes:

> I like to use NIntegrate with FindRoot as in the following trivial example:
>             FindRoot[NIntegrate[r x,{x,0,3}] == 9, {r,1}]
> That means I want to find the value of "r" for which the integral is equal to 9.
> However, I get the error message:
>                 Integrand 1.5 r is not numerical ...
> What am I doing wrong and how am I doing it right ???
> Many thanks in advance
> 		Axel Kowald
> P.S. I know that the example is more than trivial, I just used it for 
>      illustrative purposes. I also know that I can write a function which 
>      iterates several values for r, but if I could use FindRoot its definitely
>      the most elegant way.

When you use the command you wrote above, FindRoot is obtaining the
correct result, actually you are doing it right.  The error message
comes from a symbolic evaluation of the objective function at the
beginning of the computation.  The symbolic evaluation is necessary to
find the Jacobian for Newton's method.

I see 2 simple solutions to your dilemma.

1) Ignore the message (Not always safe, but since you are getting no
messages to the same effect from FindRoot it is likely that at some
point the objective function is evaluating to a number.  You could turn off the message if you wish not to see it. (Off[NIntegrate::

2) Turn off the message.  (roughly the same as 2)

3) Prevent symbolic evaluation of the NIntegrate.  This is most easily
done by something like

nint[r_?NumberQ] := NIntegrate[r x,{x,0,3}]

but remember, FindRoot will not be able to find the Jacobian, so you
will have to give it two starting values so that it can use an
approximate Jacobian (the secant method) as in

FindRoot[nint[r] == 9, {r,1,1.1}]

Rob Knapp

  • Prev by Date: Questions on data transferring and analysis
  • Next by Date: Re: Re: Bug in interpretation of mma Series[] command?
  • Previous by thread: Re: Using NIntegrate[] within FindRoot[] ??
  • Next by thread: Re: Using NIntegrate[] within FindRoot[] ??