Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
Cos.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2 * Copyright (c) 2025, Davide Stocco and Enrico Bertolazzi. *
3 * *
4 * The Optimist project is distributed under the BSD 2-Clause License. *
5 * *
6 * Davide Stocco Enrico Bertolazzi *
7 * University of Trento University of Trento *
8 * davide.stocco@unitn.it enrico.bertolazzi@unitn.it *
9\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
10
11#pragma once
12
13#ifndef OPTIMIST_TESTSET_COS_HH
14#define OPTIMIST_TESTSET_COS_HH
15
16#include "Optimist/Function.hh"
17
18namespace Optimist {
19
20 namespace TestSet {
21
36 template <typename Scalar>
37 requires TypeTrait<Scalar>::IsScalar
38 class Cos : public Function<Scalar, Scalar, Cos<Scalar>> {
39 public:
41
42
45 Cos() {
46 this->m_solutions.emplace_back(-M_PI / 2.0); // Zero
47 this->m_solutions.emplace_back(M_PI / 2.0); // Zero
48 this->m_solutions.emplace_back(-M_PI); // Minimum
49 this->m_solutions.emplace_back(M_PI); // Minimum
50 this->m_guesses.emplace_back(-3.0 / 8.0 * M_PI);
51 this->m_guesses.emplace_back(3.0 / 8.0 * M_PI);
52 }
53
58 constexpr std::string name_impl() const {
59 return "Cos";
60 }
61
68 bool evaluate_impl(const Scalar x, Scalar &out) const {
69 out = std::cos(x);
70 return std::isfinite(out);
71 }
72
79 bool first_derivative_impl(const Scalar x, Scalar &out) const {
80 out = -std::sin(x);
81 return std::isfinite(out);
82 }
83
90 bool second_derivative_impl(const Scalar x, Scalar &out) const {
91 out = -std::cos(x);
92 return std::isfinite(out);
93 }
94
95 }; // class Cos
96
97 } // namespace TestSet
98
99} // namespace Optimist
100
101#endif // OPTIMIST_TESTSET_COS_HH
#define OPTIMIST_BASIC_CONSTANTS(Scalar)
Definition Optimist.hh:70
typename InputTrait::Scalar Scalar
Definition Function.hh:53
std::vector< Scalar > m_guesses
Definition Function.hh:79
std::vector< Scalar > m_solutions
Definition Function.hh:77
bool evaluate_impl(const Scalar x, Scalar &out) const
Definition Cos.hh:68
bool first_derivative_impl(const Scalar x, Scalar &out) const
Definition Cos.hh:79
Cos()
Definition Cos.hh:45
bool second_derivative_impl(const Scalar x, Scalar &out) const
Definition Cos.hh:90
constexpr std::string name_impl() const
Definition Cos.hh:58
Namespace for the Optimist library.
Definition Optimist.hh:90