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