Numerical Recipes Forum  

Go Back   Numerical Recipes Forum > Numerical Recipes Third Edition Forum > Methods: All Chapters in NR3

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-11-2011, 03:22 PM
AndyB AndyB is offline
Registered User
 
Join Date: Nov 2011
Posts: 1
Chapter 9, Brent's method

I have been reading the code in the section on Brent's method.

I can see that the code choses Inverse Quadratic Interpolation, linear interpolation and bisection for the next position. But the book keeping leaves me with a question.

Variables b and c bracket the zero and variable a (mostly) holds the last value of b. Of the two bracket values it is arranged that b is the one that has the function value closest to zero.

The code that arranges that b has the lowest function value does the following:

if (fabs(fc) < fabs(fb)){
a = b;
b = c;
c = a;
fa = fb;
fb = fc;
fc = fa;
}

which swaps b and c (and fb and fc) but also sets a to the higher of the bracket values (ie at the end a is the same as c). This is a situation where a no longer is the previous value of b.

Does anyone know why this code changes the value of a, rather than just swapping b and c?

Thanks
AndyB
Reply With Quote
 

Tags
brent's method, root solving, zero finding

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 12:34 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.