M
Markus S
Hi,
I guess there is a good reason for this, a function from the Boost
library (which finds the minima of given function) has the following
synopsis:
template <class F, class T>
std:air<T, T> brent_find_minima(F f, T min, T max, int bits);
Calling it the following way works (inside main, with a top-level
function TrickyFunc):
double min = 1;
double max = 100;
int bits = 50;
std:air<double, double> result = brent_find_minima(TrickyFunc, min,
max, bits);
Calling it with the arguments directly given, compiles and runs 'fine'
but fails to iterate and just returns the upper boundary (max).
std:air<double, double> result = brent_find_minima(TrickyFunc, 1, 100, bits);
Below is a compilable example (found on the net).
Thanks,
Markus
#include <boost/math/tools/minima.hpp>
#include <iostream>
#include <cmath>
using namespace std;
// Standard C function
double TrickyFunction(double x)
{
return exp(x) + 0.01/x;
}
int main()
{
// Tricky function
double min = 0.0001;
double max = 1.0;
int bits = 50;
boost::uintmax_t maxIter = 1000;
std:air<double, double> result =
boost::math::tools::brent_find_minima(TrickyFunction, min, max,
bits);//, maxIter);
cout << "Abscissa, value f(x) Tricky function: " << result.first << ",
" << result.second << endl;
return 0;
}
I guess there is a good reason for this, a function from the Boost
library (which finds the minima of given function) has the following
synopsis:
template <class F, class T>
std:air<T, T> brent_find_minima(F f, T min, T max, int bits);
Calling it the following way works (inside main, with a top-level
function TrickyFunc):
double min = 1;
double max = 100;
int bits = 50;
std:air<double, double> result = brent_find_minima(TrickyFunc, min,
max, bits);
Calling it with the arguments directly given, compiles and runs 'fine'
but fails to iterate and just returns the upper boundary (max).
std:air<double, double> result = brent_find_minima(TrickyFunc, 1, 100, bits);
Below is a compilable example (found on the net).
Thanks,
Markus
#include <boost/math/tools/minima.hpp>
#include <iostream>
#include <cmath>
using namespace std;
// Standard C function
double TrickyFunction(double x)
{
return exp(x) + 0.01/x;
}
int main()
{
// Tricky function
double min = 0.0001;
double max = 1.0;
int bits = 50;
boost::uintmax_t maxIter = 1000;
std:air<double, double> result =
boost::math::tools::brent_find_minima(TrickyFunction, min, max,
bits);//, maxIter);
cout << "Abscissa, value f(x) Tricky function: " << result.first << ",
" << result.second << endl;
return 0;
}