Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
Brown.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_BROWN_HH
14#define OPTIMIST_TESTSET_BROWN_HH
15
17
18namespace Optimist {
19
20 namespace TestSet {
21
41 template <typename Input, typename Output>
42 class Brown : public DenseSystemFunction<Input,
43 2,
44 Brown<Input, Output>,
45 Output,
46 3> {
47 public:
48 using Base =
50 using typename Base::Dense;
51 using typename Base::DenseMatrix;
52 using typename Base::Scalar;
55
60 this->add_solution(this->make({1.0e6, 2.0e-6}));
61 this->add_guess(this->make({1.0, 1.0}));
62 }
63
68 constexpr std::string name_impl() const {
69 return "Brown";
70 }
71
72 void residual(const Dense &x, Dense &F) const {
73 F(0) = x(0) - Scalar(1.0e6);
74 F(1) = x(1) - Scalar(2.0e-6);
75 F(2) = x(0) * x(1) - 2;
76 }
77
78 void jacobian(const Dense &x, DenseMatrix &J) const {
79 J << 1, 0, 0, 1, x(1), x(0);
80 }
81
82 void hessian([[maybe_unused]] const Dense &x, const Integer i, DenseMatrix &H) const {
83 H.setZero();
84 if (i == 2) {
85 H(0, 1) = 1;
86 H(1, 0) = 1;
87 }
88 }
89
90 }; // class Brown
91
92 } // namespace TestSet
93
94} // namespace Optimist
95
96#endif // OPTIMIST_TESTSET_BROWN_HH
TypeTrait< Output > OutputTrait
Definition Brown.hh:54
Utils::DenseMatrix< Input > DenseMatrix
Definition DenseFunction.hh:156
Brown()
Definition Brown.hh:59
void residual(const Dense &x, Dense &F) const
Definition Brown.hh:72
typename Input::Scalar Scalar
Definition DenseFunction.hh:154
Utils::DenseVector< Input > Dense
Definition DenseFunction.hh:155
void jacobian(const Dense &x, DenseMatrix &J) const
Definition Brown.hh:78
void hessian(const Dense &x, const Integer i, DenseMatrix &H) const
Definition Brown.hh:82
constexpr std::string name_impl() const
Definition Brown.hh:68
DenseSystemFunction< Input, 2, Brown< Input, Output >, Output, 3 > Base
Definition Brown.hh:48
TypeTrait< Input > InputTrait
Definition Brown.hh:53
Helper base class for nonlinear systems written once in terms of dense vectors (square by default).
Definition DenseFunction.hh:151
Utils::DenseMatrix< Input > DenseMatrix
Definition DenseFunction.hh:156
Utils::DenseVector< Input > Dense
Definition DenseFunction.hh:155
static Dense make(std::initializer_list< Scalar > values)
Definition DenseFunction.hh:232
Namespace for the Optimist library.
Definition Optimist.hh:90
OPTIMIST_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Optimist.hh:98
Definition Optimist.hh:105