MathGroup Archive 2005

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

Search the Archive

Re: NIntegrate-FindRoot acting up in version 5.1

Deliberately leaving out "fnax" makes it difficult for us to debug your code.

Beyond that, it appears that z, v, c, and r are also undefined. All of them have to be numeric, as FindRoot and NIntegrate are purely numeric functions. We can't tell whether you left their assignments out of the post, or you left one or more of them out of your NOTEBOOK.

Since you say the code ran in 4.1.1 (not with those omissions, though), it's quite possible you need Evaluate wrapped around the first argument of FindRoot, NIntegrate, or both. And you may need to define things in a couple of steps, something like:

Clear[len, f]
len[z_?NumericQ, ang_?NumericQ, b_?NumericQ] = Sqrt[z^2 + (x Cos[ang] + r Sin[
     b])^2 + (-r Cos[b] - x Sin[ang])^2];
f[z_?NumericQ, ang_?NumericQ] := (beta = b /. FindRoot[len[z, ang,
       b] == c b r/v, {b, 0}, WorkingPrecision -> 100, AccuracyGoal ->
80]; fnax)
speed = NIntegrate[f[z, ang], {ang, 0, 3Pi/2, 2Pi}, WorkingPrecision -> \
80, AccuracyGoal -> 9]

In version 5, it's sometimes more important to prevent non-numeric evaluation, and that's what the patterns above accomplish.


On Wed, 11 May 2005 05:23:58 -0400 (EDT), John Roberts <jlr-d at> wrote:

>  I originally made the input shown below in Mathematica 4.1.1. Version
> 4.1.1 ran it flawlessly and always produced the correct result from
> NIntegrate with no warnings or error messages. Now, when I run the same
> notebook with version 5.1.0 it crashes and gives the "FindRoot: :nlnum"
> message shown below:
> In1:   len = Sqrt[ (z^2 + (x Cos[ang] + r Sin[b] )^2  + (-r Cos[b] - x
> Sin[ang])^2 ] ;
> In2:  speed = NIntegrate[ (eqn = FindRoot[ len == c b r / v, {b,
> 0}, WorkingPrecision->100,
>         AccuracyGoal->80 ] ; beta = b  /.  eqn;  fnax) , {ang,  0,
> 3Pi/2,  2Pi},  WorkingPrecision->80,  AccuracyGoal->9 ]
> Out2: FindRoot: :nlnum : The function value {0. + Sqrt[0.0172266 + (0. +
> 0.05 <<1>>)^2 + (-0.125 - 0.05 Sin[<<1>>])^2]
>          is not a list of numbers with dimensions {1} at {b} = {0.}.
> As can be seen from the input shown above, NIntegrate integrates the
> expression fnax with respect to the angle ang. But fnax is also a
> function of the initial angle beta or b (beta = b), so each time
> NIntegrate calculates the value of fnax it must first use FindRoot to
> find the value of beta that corresponds to the value of ang that it is
> using. I did not include the expression for fnax here because it is
> rather large, but there is nothing exotic about fnax, it is just a lot
> of terms with Sin and Cos functions.
> All of the values z, x, r, c v are input with 120 decimal places of
> precision or with infinite precision (no decimal point).
> It should also be noted that I checked the FindRoot part alone (without
> NIntegrate) at various points along the range of integration from ang
> = 0 to ang = 2 Pi, and FindRoot got the correct value of beta at
> every point with no warnings or error messages; so the problem appears
> to be associated with how NIntegrate uses FindRoot in Mathematica 5.1
> rather than with FindRoot itself.
> Thanks in advance for any help you can give me,
> John R.

DrBob at

  • Prev by Date: Re: NIntegrate-FindRoot acting up in version 5.1
  • Next by Date: Re: Partitioning a list from an index
  • Previous by thread: NIntegrate-FindRoot acting up in version 5.1
  • Next by thread: Re: NIntegrate-FindRoot acting up in version 5.1