Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6845981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:34:02+00:00 2026-05-27T00:34:02+00:00

Yesterday I had problems with another boost functions but luckily you guys helped me

  • 0

Yesterday I had problems with another boost functions but luckily you guys helped me to solve them. Today I would need to know how to use bisection function properly.

So here is how I think it should work but never the less it seems that I’m getting this also wrong. Okay so I would like to use:

template <class F, class T, class Tol>
 std::pair<T, T> 
 bisect(
    F f, 
    T min, 
    T max, 
    Tol tol);

from here but my problem is with tolerance because I don’t know how to set it right. I’ve tried

double value = boost::math::tools::eps_tolerance<double>(0.00001);

and how to I return the value when the bisection has found ? Should the result be pair of numbers as std::pair in the function and after that just calculate min+max/2?

Thanks !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:34:03+00:00Added an answer on May 27, 2026 at 12:34 am

    This is an example use of bisect. Consider solving the equation x^2 - 3x + 1 = 0:

    struct TerminationCondition  {
      bool operator() (double min, double max)  {
        return abs(min - max) <= 0.000001;
      }
    };
    
    struct FunctionToApproximate  {
      double operator() (double x)  {
        return x*x - 3*x + 1;  // Replace with your function
      }
    };
    
    // ...
    using boost::math::tools::bisect;
    double from = 0;  // The solution must lie in the interval [from, to], additionally f(from) <= 0 && f(to) >= 0
    double to = 1;
    std::pair<double, double> result = bisect(FunctionToApproximate(), from, to, TerminationCondition());
    double root = (result.first + result.second) / 2;  // = 0.381966...
    

    EDIT: Alternatively, this is how you can use it with custom functions:

    double myF(double x)  {
      return x*x*x;
    }
    
    double otherF(double x)  {
      return log(abs(x));
    }
    
    // ...
    std::pair<double, double> result1 = bisect(&myF, from, to, TerminationCondition());
    std::pair<double, double> result2 = bisect(&otherF, 0.1, 1.1, TerminationCondition());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys i had an idea yesterday. Can you help me with this. Here
After posting a question yesterday I thought I had this cleared up but I'm
I had implemented the possibilty for multiple textures for while now... but yesterday I
Seems like just yesterday I had this same problem with Play! v1. After trying
We had a terrible problem/experience yesterday when trying to swap our staging <--> production
Yesterday i had a question in an interview which i thought i could find
Yesterday I had seen question concerning how to get file space information. I tried
Up until yesterday I had a perfectly working app on my iPhone. I made
In an programming interview I had yesterday, one of the programs I had to
I have been trying since yesterday to get google like paging, but each time

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.