Artifact c1b48b3999a9f65ad3f00bf5275c72bf7eb06f19
- File
_lib/typical/ternery.cpp
- 2011-02-23 09:21:16 - part of checkin [4fd800b3a8] on branch trunk - Copied from private svn repository. (user: kinaba) [annotate]
- File
lib/typical/ternery.cpp
- 2011-02-23 11:18:09 - part of checkin [23dfcca431] on branch trunk - renamed _lib to lib (user: kinaba) [annotate]
// ternery search (for shita-ni-totsu) { double x = ~min~; double w = ~max~; for(int i=0; i<~iteration~; ++i) // or, while( w-x > ~eps~ ) be careful for precision! { double y = 2*x/3 + w/3; double z = x/3 + 2*w/3; double fx = f(x); double fy = f(y); double fz = f(z); double fw = f(w); if( fx < fy ) w = y; else if( fz > fw ) x = z; else if( fy < fz ) w = z; else x = y; } }