Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
Quadratic.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_QUADRATIC_HH
14#define OPTIMIST_TESTSET_QUADRATIC_HH
15
16#include "Optimist/TestSet.hh"
17
18namespace Optimist
19{
20
21 namespace TestSet
22 {
23
43 template <typename Real>
44 class Quadratic : public Function<Real, 1, 1, Quadratic<Real>>
45 {
46 Real m_a{1.0};
47 Real m_b{1.0};
48 Real m_c{-1.0};
49
50 public:
52
53
57 {
58 Real delta{std::sqrt(this->m_b*this->m_b - 4.0*this->m_a*this->m_c)};
59 this->m_solutions.emplace_back((-this->m_b + delta)/(2.0*this->m_a));
60 this->m_solutions.emplace_back((-this->m_b - delta)/(2.0*this->m_a));
61 this->m_solutions.emplace_back(this->m_b/(2.0*this->m_a));
62 this->m_guesses.emplace_back(0.0);
63 }
64
69 std::string name_impl() const {return "Quadratic";}
70
76 void evaluate_impl(Real x, Real & out) const {out = this->m_a*x*x + this->m_b*x + this->m_c;}
77
83 void first_derivative_impl(Real x, Real & out) const {out = 2.0*this->m_a*x + this->m_b;}
84
90 void second_derivative_impl(Real /*x*/, Real & out) const {out = 2.0*this->m_a;}
91
92 }; // class Quadratic
93
94 } // namespace TestSet
95
96} // namespace Optimist
97
98#endif // OPTIMIST_TESTSET_QUADRATIC_HH
#define OPTIMIST_BASIC_CONSTANTS(Real)
Definition Optimist.hh:70
std::vector< InputType > m_guesses
Definition Function.hh:63
std::vector< InputType > m_solutions
Definition Function.hh:62
void first_derivative_impl(Real x, Real &out) const
Definition Quadratic.hh:83
std::string name_impl() const
Definition Quadratic.hh:69
Real m_c
Definition Quadratic.hh:48
Quadratic()
Definition Quadratic.hh:56
void evaluate_impl(Real x, Real &out) const
Definition Quadratic.hh:76
Real m_a
Definition Quadratic.hh:46
void second_derivative_impl(Real, Real &out) const
Definition Quadratic.hh:90
Real m_b
Definition Quadratic.hh:47
Namespace for the Optimist library.
Definition Optimist.hh:87