SOPT
Sparse OPTimisation
Typedefs | Functions | Variables
bisection_method.cc File Reference
#include <catch2/catch_all.hpp>
#include <random>
#include <Eigen/Dense>
#include "sopt/bisection_method.h"
#include "sopt/types.h"
+ Include dependency graph for bisection_method.cc:

Go to the source code of this file.

Typedefs

using Scalar = sopt::t_real
 
using t_Vector = sopt::Vector< Scalar >
 
using t_Matrix = sopt::Matrix< Scalar >
 

Functions

 TEST_CASE ("Bisection x^3")
 
 TEST_CASE ("Bisection f(x) = x")
 
 TEST_CASE ("Bisection exp()")
 

Variables

constexpr Scalar a = -0.5
 
constexpr Scalar b = 1.
 
constexpr Scalar tol = 1e-4
 

Typedef Documentation

◆ Scalar

Definition at line 9 of file bisection_method.cc.

◆ t_Matrix

Definition at line 11 of file bisection_method.cc.

◆ t_Vector

Definition at line 10 of file bisection_method.cc.

Function Documentation

◆ TEST_CASE() [1/3]

TEST_CASE ( "Bisection exp()"  )

Definition at line 31 of file bisection_method.cc.

31  {
32  using namespace sopt;
33  std::function<Scalar(Scalar)> const func = [](const Scalar &x) -> Scalar { return std::exp(-x); };
34  constexpr Scalar x0 = 1;
35  const Scalar x0_est = bisection_method(func(x0), func, a, b, tol);
36  CHECK(std::abs(x0_est - x0) <= tol);
37 }
constexpr Scalar tol
constexpr Scalar b
sopt::t_real Scalar
constexpr Scalar a
std::enable_if< std::is_same< t_real, K >::value, K >::type bisection_method(const K &function_value, const std::function< K(K)> &func, const K &a, const K &b, const t_real &rel_convergence=1e-4)
Find root to a function within an interval.

References a, b, sopt::bisection_method(), and tol.

◆ TEST_CASE() [2/3]

TEST_CASE ( )

Definition at line 24 of file bisection_method.cc.

24  {
25  using namespace sopt;
26  std::function<Scalar(Scalar)> const func = [](const Scalar &x) -> Scalar { return x; };
27  constexpr Scalar x0 = 0.23235104239409;
28  const Scalar x0_est = bisection_method(func(x0), func, a, b, tol);
29  CHECK(std::abs(x0_est - x0) <= tol);
30 }

References a, b, sopt::bisection_method(), and tol.

◆ TEST_CASE() [3/3]

TEST_CASE ( "Bisection x^3"  )

Definition at line 16 of file bisection_method.cc.

16  {
17  using namespace sopt;
18  sopt::logging::set_level("debug");
19  std::function<Scalar(Scalar)> const func = [](const Scalar &x) -> Scalar { return x * x * x; };
20  constexpr Scalar x0 = 0;
21  const Scalar x0_est = bisection_method(func(x0), func, a, b, tol);
22  CHECK(std::abs(x0_est - x0) <= tol);
23 }
void set_level(const std::string &level)
Method to set the logging level of the default Log object.
Definition: logging.h:154

References a, b, sopt::bisection_method(), sopt::logging::set_level(), and tol.

Variable Documentation

◆ a

constexpr Scalar a = -0.5
constexpr

◆ b

constexpr Scalar b = 1.
constexpr

◆ tol

constexpr Scalar tol = 1e-4
constexpr