// Progrem to demonstrate calling Brent zero-finder #include #include #include "brent.h" using namespace std; class sine_series : public brent::func_base{ public: std::vector coeff; virtual double operator() (double x); // constructor: sine_series(const std::vector& v) : coeff(v) {} }; double sine_series::operator()(double x){ double rslt(0); for (size_t ii = 1; ii < coeff.size(); ii++){ rslt += coeff[ii] * sin(ii * x); } return rslt; } int main(){ // Beware: The initializer-list on the following line // uses a c++11 language feature. // If it doesn't compile chez vous, consider upgrading your compiler // ... or rewrite this to use c++03 features. sine_series foo({0, 0.3, 0.4, 0.15}); double rslt = brent::zero(1, 2, 1e-10, foo); cout << "Root: " << rslt << " Y val: " << foo(rslt) << endl; }