I should have been more specific. This is what I have in mind
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <utility>
#include <iostream>
#include <boost/math/tools/roots.hpp>
class root
{
public:
double f(double x)
{
return (x*x-1);
}
void findRoot()
{
typedef double (root::*MemFn)(double x);
std::pair<double, double> found = boost::math::tools::bisect<MemFn, double, double> (&root::f,0.0,10.0,1.e-6);
std::cout << "==> x = [" << found.first << ',' << found.second << "]\n";
}
};
int main()
{
root solve;
solve.findRoot();
return (0);
}
| |
But than I get
Invoking: GCC C++ Compiler
g++ -I/home/ppisarski/lib/bazille/boost_1_47_0 -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
/home/ppisarski/lib/bazille/boost_1_47_0/boost/math/tools/roots.hpp: In function ‘std::pair<T, T> boost::math::tools::bisect(F, T, T, Tol, uintmax_t&, const Policy&) [with F = double (root::*)(double), T = double, Tol = double, Policy = boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy>]’:
/home/ppisarski/lib/bazille/boost_1_47_0/boost/math/tools/roots.hpp:180: instantiated from ‘std::pair<T, T> boost::math::tools::bisect(F, T, T, Tol) [with F = double (root::*)(double), T = double, Tol = double]’
../main.cpp:22: instantiated from here
/home/ppisarski/lib/bazille/boost_1_47_0/boost/math/tools/roots.hpp:99: error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘f (...)’
/home/ppisarski/lib/bazille/boost_1_47_0/boost/math/tools/roots.hpp:100: error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘f (...)’
/home/ppisarski/lib/bazille/boost_1_47_0/boost/math/tools/roots.hpp:180: instantiated from ‘std::pair<T, T> boost::math::tools::bisect(F, T, T, Tol) [with F = double (root::*)(double), T = double, Tol = double]’
../main.cpp:22: instantiated from here
/home/ppisarski/lib/bazille/boost_1_47_0/boost/math/tools/roots.hpp:130: error: ‘tol’ cannot be used as a function
/home/ppisarski/lib/bazille/boost_1_47_0/boost/math/tools/roots.hpp:133: error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘f (...)’
make: *** [main.o] Error 1
And, Yes it is important for me to have the f(x) function as a member of the class that looks for its root.