MathGroup Archive 1998

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

Search the Archive

Re: FindRoot accuracy/precision




Daniel Lichtblau (danl@wolfram.com) writes:
> Michael Chang wrote:
>> 
>> Hallo!
>> 
>> I'm running Mathematica 3.0 on a PC (with Windows 95).
>> 
>> I'm trying to use FindRoot to solve the roots for *seven* nonlinear
>> equations with seven variables.  I use Random to generate seven
>> (positive real) initial starting points for FindRoot, and continuously
>> run FindRoot until seven candidate (positive real) roots are found.
>> 
>> The basic text is as follows:
>> 
>> ok=0; While[ok==0,
>> ans=FindRoot[eq1==eq2,{x1,Random[Real,x1upper]},
>> {x2,Random[Real,x2upper]}, (etc.)]; If[Min[ans]>=0, ok=1; Print[ans]]]
>> 
>> In the above text, eq1 is a list of numerical values, and eq2 is a list
>> of symbolic equations. The problem is that when evaluated (i.e.
>> eq2/.ans), only *one* of my seven equations appears `close' in value;
>> this particular equation also yields the largest numerical value
>> (4*10^2), while the other values should get smaller (all the way down
>> to 10^-13).  (I know that this large spread in values is part of my
>> problem.)
>> 
>> So ... how can I get Mathematica to FindRoots more accurately?  My
>> $MachinePrecision is 16 (which cannot be changed, I believe).
>> Precision of eq1 (my numerical values) only seems to be 16.  Is this my
>> problem (i.e. should this be infinity)?  I've tried changing
>> WorkingPrecision in FindRoots, but this doesn't seem to have any
>> effect!
>> 
>> In essence, I'm trying to find out how the result of FindRoot can yield
>> 
>> eq1 (approximately=) eq2/.ans
>> 
>> Currently, this does *not* occur except for the first element of my
>> list.  The other elements are sometimes one+ order of magnitude off and
>> are decreasing in magnitude to order(10^-13).
>> 
>> I'd be grateful for any and all suggestions/advice concerning this
>> pressing problem of mine!
>> 
>> Thanks in advance!
>> 
>> Mike
> 
> 
> It is a bit difficult to understand your question; perhaps the actual
> example would be of help. Without that, I can make a suggestion or two.
> First, subtract right-hand-side from left-hand-side of each equation
> and put zero on each right-hand-side. Now you will always be comparing
> to zero. If nothing else, this will make it less likely for confusing
> terminology such as
> 
>> eq1 (approximately=) eq2/.ans
> 
> to arise.
> 
> Second, you might try to play with the options AccuracyGoal and
> MaxIterations. Raise the latter, say, to 100 (default is 15), and take
> AccuracyGoal to be, say, 20. This will make FindRoot attempt to find
> roots that give residuals around 10^(-20), if I remember correctly the
> details. In any case, FindRoot will try harder than it would by
> default, and you will be able to see if you are getting better results.

Hi!  Thanks for your response!

With regards to an example, suppose I have the following (made up on the
spur of the moment).

100==x1*x2-x3*x4;
1*10^-3==x3/x2-x1^2;
2*10^-6==x4/x1+x2*x3;
5*10^-13==x1*x4-x3/x2;

eq1={100,1*10^-3,2*10^-6,5*10^-13};
eq2={x1*x2-x3*x4, etc.}

(Note the great "spread" in numerical values.) I have four equations
with four unknowns, and eq1 and eq2 *both* have *infinite* precision. 
Because I don't know where to start my parameter space search, I try
using a random starting point.  I'm looking for positive real roots
since the 7 nonlinear equations that I'm *actually* dealing with come
about from an electrical R & C circuit. 

Hence, I try the following:

ok=0;While[ok==0, ans=FindRoot[(eq1-eq2)==0,{x1,Random[Real,x1max]},
{x2,Random[Real,x2max]},{x3,Random[Real,x3max]},
{x4,Random[Real,x4max]},MaxIterations->1000];
If[Min[{x1,x2,x3,x4}/.ans]>=0,
	ok=1; Print[ans]]]

Now since eq1 and eq2 both have infinite precision, should I be using

Rationalize[Random[Real,ximax],0]

in the above expressions?  The main problem is that the actual value of

(eq1-eq2)

is "small" (the largest residual is of order 10^-2), but not small in
percentage for the smaller valued elements.  My default for
WorkingPrecision is 16, but this doesn't seem to give (eq1-eq2) to be
order 10^-16 !  I will try increasing WorkingPrecision, but am finding
that the calculations are becoming increasingly slower. 

Once again, any suggestions and advice would be greatly appreciated!

Thanks again,

Mike



  • Prev by Date: Re: Change viewpoints in real time
  • Next by Date: Re: Histograms for 2-D Data ?
  • Prev by thread: Re: FindRoot accuracy/precision
  • Next by thread: Re: Re: FindRoot accuracy/precision