[Date Index]
[Thread Index]
[Author Index]
Re: NIntegrate-FindRoot acting up in version 5.1
*To*: mathgroup at smc.vnet.net
*Subject*: [mg57004] Re: [mg56943] NIntegrate-FindRoot acting up in version 5.1
*From*: Daniel Lichtblau <danl at wolfram.com>
*Date*: Thu, 12 May 2005 02:33:03 -0400 (EDT)
*References*: <200505110923.FAA23950@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
John Roberts 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.
>
I got identical garbage in 4.1 and 5.1. Which is as I would expect,
because the code is attempting numerical algorithms on nonumerical data.
Even with values for the parameters noted, it is not clear what fnax
should be. (Moral: Post the code you actually used.)
Here is a way to do this that might be what you have in mind. It gives
the same numerical result in both versions.
SeedRandom[1111];
{c,x,r,v,z} = Table[Random[Integer,{1,100}], {5}];
len = Sqrt[z^2 + (x*Cos[ang] + r*Sin[b])^2 +
(-r*Cos[b] - x*Sin[ang])^2];
integrand[ang_?NumberQ] := b /. FindRoot[len == c*b*r/v, {b,0},
WorkingPrecision->100, AccuracyGoal->80]
NIntegrate[integrand[ang], {ang,0,3*Pi/2,2*Pi},
WorkingPrecision->80, AccuracyGoal->9]
Depending on parameter values and other considerations you may be able
to dispense with or at least weaken the precision and accuracy requirements.
Daniel Lichtblau
Wolfram Research
Prev by Date:
**Re: Partitioning a list from an index**
Next by Date:
**Re: Representation and Simulation of Dynamic Systems**
Previous by thread:
**Re: NIntegrate-FindRoot acting up in version 5.1**
Next by thread:
**Re: NIntegrate-FindRoot acting up in version 5.1**
| |