Please, help me about bisection method in C +?
Obtain the local minimize of the function f(x) = X5-5X3-20X+5 on [-3,O] and [0,3] by bisection method >> and run it in a loop
help me++++
Please, help me about bisection method in C +?
Obtain the local minimize of the function f(x) = X5-5X3-20X+5 on [-3,O] and [0,3] by bisection method >> and run it in a loop
help me++++
: a common confusion — the bisection algorithm finds roots, not minima. To use "bisection" for minimization you apply it to the derivative f'(x) to locate stationary points, then classify the point with f''(x) or by comparing endpoint values. There is no built-in C/C++ function called "bisect"; 's prototype is just a sketch — implement the routine yourself (or use a root-finder library).
For the polynomial in your post the calculus gives an immediate answer. Analytically,
f'(x) = 5x^4 - 15x^2 - 20 = 5(x^2 - 4)(x^2 + 1),
so the only real critical points are x = -2 and x = 2. f''(x) = 20x^3 - 30x, so f''(-2) < 0 (local maximum) and f''(2) > 0 (local minimum). Evaluating f shows f(-3) = -43, f(0) = 5, f(2) = -43. Therefore the minimum on [-3,0] occurs at the endpoint x = -3 (value -43), and on [0,3] a local minimum occurs at x = 2 (value -43).
If an implementation is desired, use bisection on f'(x) with a sign change on the interval, then check f'' at the root. Example bisection routine (uses std::function):
#include <functional>
#include <cmath>
#include <stdexcept>
double bisection(std::function<double(double)> g, double a, double b,
double tol=1e-9, int maxIter=1000) {
double fa = g(a), fb = g(b);
if (fa*fb > 0) throw std::invalid_argument("g(a) and g(b) must have opposite signs");
for (int i=0; i<maxIter; ++i) {
double m = 0.5*(a+b), fm = g(m);
if (std::abs(fm) < tol || (b-a)/2 < tol) return m;
if (fa*fm <= 0) { b = m; fb = fm; } else { a = m; fa = fm; }
}
return 0.5*(a+b);
} Notes: bisection requires g(a)*g(b) <= 0. If you do not have an analytic derivative, use a robust scalar-minimization method (for unimodal intervals) such as golden-section search. See Bisection method and std::function for reference.
Jump to Post— Despairy 0int bisect(Function &F);
int bisect(Function &F);
Which library of C has this function Despairy??
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.