Issues with brent_find_minima

I must be missing something: the following program doesn't seem to find the right minimum (boost 1.47.0). double f(double x) { return x * cos(x); } int main(int argc, char** argv) { cout << brent_find_minima(f, 3.0, 4.0, 1e-8) << endl; return 0; } I get: 4 -2.61457 But I think the minimum is -3.28837 at x = 3.42562. Did I miss something in calling brent_find_minima?? Also, this function should be called "brent_find_minimum" since it finds a single minimum, IMHO. The singular is minimum in Latin, minima is the plural. Or can the function be called repetitively and each time return a different minimum?? Frank fastier@yahoo.com

The fourth argument should be an integer specifying the number of bits
of precision you want (not a float-tolerance).
This seems to work:
http://codepad.org/Myd5Th7W
I get:
x=4 f=-2.61457
x=3.42864 f=-3.28835
enjoy,
AW
On Fri, Aug 12, 2011 at 7:23 PM, Frank Astier
I must be missing something: the following program doesn't seem to find the right minimum (boost 1.47.0). double f(double x) { return x * cos(x); } int main(int argc, char** argv) { cout << brent_find_minima(f, 3.0, 4.0, 1e-8) << endl; return 0; } I get: 4 -2.61457 But I think the minimum is -3.28837 at x = 3.42562. Did I miss something in calling brent_find_minima?? Also, this function should be called "brent_find_minimum" since it finds a single minimum, IMHO. The singular is minimum in Latin, minima is the plural. Or can the function be called repetitively and each time return a different minimum?? Frank fastier@yahoo.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

The fourth argument should be an integer specifying the number of bits of precision you want (not a float-tolerance). This seems to work: http://codepad.org/Myd5Th7W I get: x=4 f=-2.61457 x=3.42864 f=-3.28835
Correct, the final argument is an integer - the number of bits precision - so your code was asking for 0 bits precision which is why it just returned the starting value! BTW your compiler should have warned about the conversion from double to int, which is a big hint that something is wrong ;-) HTH, John.
participants (3)
-
Anders Wallin
-
Frank Astier
-
John Maddock