I just started using boost today and found this post to be extremely helpful. I am attempting to use boost::bisect to solve a parametric equation for a series of values. The following works if I want to solve for a value of 0.8:
#include <boost/math/tools/roots.hpp>
//declare constants
const double Y_r = 0.2126;
const double Y_g = 0.7152;
const double Y_b = 0.0722;
struct FunctionToApproximate {
double operator() (double x) {
return (pow (x, 2.4) * Y_r) + (pow ((x*0.6)+0.4, 2.4) * Y_g) + (1 * Y_b) - 0.8;
}
};
struct TerminationCondition {
bool operator() (double min, double max) {
return fabs(min - max) <= t_c;
}
};
using boost::math::tools::bisect;
std::pair<double, double> result = bisect(FunctionToApproximate(), 0.0, 1.0, TerminationCondition());
double root = (result.first + result.second) / 2;
I would like to wrap this in a loop so I could solve for values other than 0.8. How would I go about this?
Many thanks!