Jump to content
  • Advertisement
Sign in to follow this  
davidcoleman

Boost - brent_find_minima problem

This topic is 3121 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This works (although with predefined values)
void CtestDlg::OnBnClickedButton1()
{
	doSomething();
}

double sinc(double x) {
	static const double PI = 3.14159265358979323846264338327950288419716939937510;
	return (x == 0.0) ? 1.0 : sin( PI * x ) / ( PI * x );
}

double x(double t) {
	static double vals[6] = { 5.0, 14.0, 60.0, 111.0, 100.0, 37.0 };
	double result = 0;
	for (int i = 0; i < 6; i++) result += vals * sinc(t-i);
	return -result;
}

typedef std::pair<double, double> Range;

void CtestDlg::doSomething()
{
std::pair<double, double> mm = boost::math::tools::brent_find_minima(x, 0.0, 6.0, 64);
}



But if I make those functions class members and try to pass values like this
void CtestDlg::OnBnClickedButton1()
{
	vals[0]=5.0;
	vals[1]=14.0;
	vals[2]=60.0;
	vals[3]=111.0;
	vals[4]=100.0;
	vals[5]=37.0;
	doSomething();
}

typedef std::pair<double, double> Range;

void CtestDlg::doSomething()
{
std::pair<double, double> mm = boost::math::tools::brent_find_minima(x, 0.0, 6.0, 64);
}

double CtestDlg::sinc(double x) {
	static const double PI = 3.14159265358979323846264338327950288419716939937510;
	return (x == 0.0) ? 1.0 : sin( PI * x ) / ( PI * x );
}

double CtestDlg::x(double t) {
	//static double vals[6] = { 5.0, 14.0, 60.0, 111.0, 100.0, 37.0 }; -THIS CANCLED OUT
	double result = 0;
	for (int i = 0; i < 6; i++) result += vals * sinc(t-i);
	return -result;
}



I get errors: Error 1 error C3867: 'CtestDlg::x': function call missing argument list; use '&CtestDlg::x' to create a pointer to member Error 2 error C2780: 'std::pair<T,T> boost::math::tools::brent_find_minima(F,T,T,int,boost::uintmax_t &)' : expects 5 arguments - 4 provided and if I do type there &CtestDlg::x instead of just x I get error in boost itself Error 1 error C2064: term does not evaluate to a function taking 1 arguments c:\program files\boost\boost_1_39\boost\math\tools\minima.hpp How can I fix it? (The program uses this values to define Y of the curve and mm is the x value where the curve has maximum)

Share this post


Link to post
Share on other sites
Advertisement
The problem is that a member function must be converted to a functor before being able to be passed as a variable. The keyword here is binding (std::bind1st() etc.).

I found a forum topic elsewhere that has an answer to exactly your question: http://www.velocityreviews.com/forums/t690259-function-that-requires-a-function-as-an-argument-brent_find_minima.html

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!