10 #include "gtest/gtest.h" 23 return std::log(1.0 +
x) * std::tanh(
x / 3.0) +
x / 4.0 - 3;
32 auto func = [](
Real x) {
return f(
x); };
39 EXPECT_LT(
f(x1) *
f(x2), 0.0);
46 FAIL() <<
"missing expected exception";
48 catch (
const std::exception & e)
50 std::string msg(e.what());
51 ASSERT_TRUE(msg.find(
"Bad initial range (0) used in BrentsMethod::bracket") !=
53 <<
"failed with unexpected error: " << msg;
60 auto func2 = [](
Real x) {
return f(
x) + 4.0; };
63 FAIL() <<
"missing expected exception";
65 catch (
const std::exception & e)
67 std::string msg(e.what());
69 msg.find(
"No bracketing interval found by BrentsMethod::bracket after 50 iterations") !=
71 <<
"failed with unexpected error: " << msg;
81 auto func = [](
Real x) {
return f(
x); };
92 FAIL() <<
"missing expected exception";
94 catch (
const std::exception & e)
96 std::string msg(e.what());
97 ASSERT_TRUE(msg.find(
"Root must be bracketed in BrentsMethod::root") != std::string::npos)
98 <<
"failed with unexpected error: " << msg;
const std::vector< double > x
Real f(Real x)
Test function for Brents method.
Real root(std::function< Real(Real)> const &f, Real x1, Real x2, Real tol=1.0e-12)
Finds the root of a function using Brent's method.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Brent's method is used to find the root of a function f(x), i.e., find x such that f(x) = 0...
TEST(BrentsMethod, bracket)
void bracket(std::function< Real(Real)> const &f, Real &x1, Real &x2)
Function to bracket a root of a given function.