Or login with:
| voidbracket( | double | (*f)(double)[function pointer] | |
| double& | a | ||
| double& | b | ||
| double& | c | ) |
#include <codecogs/maths/optimization/bracket.h> #include <iostream> #include <iomanip> #include <cmath> // user-defined function double f(double x) { return x * sin(x); } int main() { double a = 5, b = 4, c; Maths::Optimization::bracket(f, a, b, c); std::cout << "The bracketing triple is: " << std::endl << std::endl; std::cout << " a = 4" << std::endl << " b = 5 " << std::endl; std::cout << " c = " << std::setprecision(10) << c << std::endl; std::cout << std::endl; std::cout << "The corresponding function values are: " << std::endl; std::cout << std::endl; std::cout << " f(a) = " << f(4) << std::endl << " f(b) = " << f(5); std::cout << std::endl; std::cout << " f(c) = " << f(c) << std::endl << std::endl; return 0; }
The bracketing triple is:
a = 4
b = 5
c = 6.618034
The corresponding function values are:
f(a) = -3.027209981
f(b) = -4.794621373
f(c) = 2.174859828| f | the user-defined function |
| a | the left endpoint of the initial interval |
| b | the right endpoint of the initial interval |
| c | the third point that will complete the bracketing triple |
Source code is available when you buy a Commercial licence.
Not a member, then Register with CodeCogs. Already a Member, then Login.
You must login to leave a messge