Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
PowellSingular.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2 * Copyright (c) 2026, 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_POWELL_SINGULAR_HH
14#define OPTIMIST_TESTSET_POWELL_SINGULAR_HH
15
17
18namespace Optimist {
19
20 namespace TestSet {
21
39 template <typename Vector>
41 : public DenseSystemFunction<Vector, 4, PowellSingular<Vector>> {
42 public:
44 using typename Base::Dense;
45 using typename Base::DenseMatrix;
46 using typename Base::Scalar;
47
52 this->add_solution(Dense::Zero(4));
53 this->add_guess(this->make({3.0, -1.0, 0.0, 1.0}));
54 }
55
56 constexpr std::string name_impl() const {
57 return "PowellSingular";
58 }
59
60 void residual(const Dense &x, Dense &F) const {
61 const Scalar s5{std::sqrt(Scalar(5))}, s10{std::sqrt(Scalar(10))};
62 F(0) = x(0) + 10 * x(1);
63 F(1) = s5 * (x(2) - x(3));
64 F(2) = (x(1) - 2 * x(2)) * (x(1) - 2 * x(2));
65 F(3) = s10 * (x(0) - x(3)) * (x(0) - x(3));
66 }
67
68 void jacobian(const Dense &x, DenseMatrix &J) const {
69 const Scalar s5{std::sqrt(Scalar(5))}, s10{std::sqrt(Scalar(10))};
70 const Scalar a{x(1) - 2 * x(2)}, b{x(0) - x(3)};
71 J.setZero();
72 J(0, 0) = 1;
73 J(0, 1) = 10;
74 J(1, 2) = s5;
75 J(1, 3) = -s5;
76 J(2, 1) = 2 * a;
77 J(2, 2) = -4 * a;
78 J(3, 0) = 2 * s10 * b;
79 J(3, 3) = -2 * s10 * b;
80 }
81
82 void hessian([[maybe_unused]] const Dense &x, const Integer i, DenseMatrix &H) const {
83 const Scalar s10{std::sqrt(Scalar(10))};
84 H.setZero();
85 if (i == 2) {
86 H(1, 1) = 2;
87 H(1, 2) = -4;
88 H(2, 1) = -4;
89 H(2, 2) = 8;
90 } else if (i == 3) {
91 H(0, 0) = 2 * s10;
92 H(0, 3) = -2 * s10;
93 H(3, 0) = -2 * s10;
94 H(3, 3) = 2 * s10;
95 }
96 }
97
98 }; // class PowellSingular
99
100 } // namespace TestSet
101
102} // namespace Optimist
103
104#endif // OPTIMIST_TESTSET_POWELL_SINGULAR_HH
Helper base class for nonlinear systems written once in terms of dense vectors (square by default).
Definition DenseFunction.hh:151
void add_guess(const Dense &x)
Definition DenseFunction.hh:225
Utils::DenseMatrix< Vector > DenseMatrix
Definition DenseFunction.hh:156
typename Vector::Scalar Scalar
Definition DenseFunction.hh:154
Utils::DenseVector< Vector > Dense
Definition DenseFunction.hh:155
void add_solution(const Dense &x)
Definition DenseFunction.hh:218
static Dense make(std::initializer_list< Scalar > values)
Definition DenseFunction.hh:232
constexpr std::string name_impl() const
Definition PowellSingular.hh:56
void hessian(const Dense &x, const Integer i, DenseMatrix &H) const
Definition PowellSingular.hh:82
DenseSystemFunction< Vector, 4, PowellSingular< Vector > > Base
Definition PowellSingular.hh:43
void jacobian(const Dense &x, DenseMatrix &J) const
Definition PowellSingular.hh:68
void residual(const Dense &x, Dense &F) const
Definition PowellSingular.hh:60
PowellSingular()
Definition PowellSingular.hh:51
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