Eigen-Contrib  5.0.1-dev+master
 
Loading...
Searching...
No Matches
Eigen::DiscreteAlgebraicRiccatiSolver< MatrixType_ > Class Template Reference

#include <contrib/Eigen/src/Riccati/DiscreteAlgebraicRiccatiSolver.h>

Detailed Description

template<typename MatrixType_>
class Eigen::DiscreteAlgebraicRiccatiSolver< MatrixType_ >

Solves the discrete-time algebraic Riccati equation (DARE)

Template Parameters
MatrixType_the type of the solution matrix \( X \), a square matrix of real or complex scalars; this is expected to be an instantiation of the Matrix class template.

This class computes the stabilizing solution \( X \) of the discrete-time algebraic Riccati equation

\[ A^* X A - X - (A^* X B) (R + B^* X B)^{-1} (B^* X A) + Q = 0 \]

or of its generalized version

\[ A^* X A - E^* X E - (A^* X B + S) (R + B^* X B)^{-1} (B^* X A + S^*) + Q = 0, \]

where \( A \) and \( E \) are \( m \times m \), \( B \) and \( S \) are \( m \times n \), \( Q \) is \( m \times m \) selfadjoint, \( R \) is \( n \times n \) selfadjoint and \( E \) is nonsingular. \( R \) itself does not need to be invertible.

For a solution to exist, the eigenvalues of \( A \) outside the unit disc have to be controllable and the associated symplectic pencil (see below) must not have eigenvalues on, or too close to, the unit circle.

The solver follows the generalized eigenvalue approach of [1]: it forms the extended symplectic pencil

\[H - \lambda J = \begin{bmatrix} A & 0 & B \\ -Q & E^* & -S \\ S^* & 0 & R \end{bmatrix} - \lambda \begin{bmatrix} E & 0 & 0 \\ 0 & A^* & 0 \\ 0 & -B^* & 0 \end{bmatrix}, \]

optionally balances it as in [3], deflates it by the columns of \( R \), computes its generalized Schur form (RealQZ or ComplexQZ) and reorders it such that the eigenvalues inside the unit circle come first. The leading \( m \) Schur vectors \( [U_1; U_2] \) span the stable deflating subspace and \( X = U_2 U_1^{-1} \) (for the generalized equation, \( U_1 \) is first replaced by \( E U_1 \)). The computation is reported as failed if the pencil does not have exactly \( m \) eigenvalues inside the unit circle, if \( U_1 \) is numerically singular or so small that \( \|X\| \) (of the balanced problem) would exceed about \( 0.2 / \varepsilon \), or if \( U_1^* U_2 \) is far from selfadjoint, which happens when the pencil has eigenvalues too close to the unit circle [2]. A stabilizing solution that large cannot be told apart from an unstable mode that \( B \) does not reach, for which none exists.

Balancing is essential for some badly scaled problems, but it can cost accuracy for others, notably when \( B \) is very small compared to the other matrices. With balancing enabled (the default), the solver therefore checks the backward error of the balanced solution whenever balancing changed the pencil; if it is large, or the balanced computation fails, the unbalanced pencil is solved as well and the more accurate solution is returned. compute(..., false) never balances.

The algorithm follows SciPy's scipy.linalg.solve_discrete_are, with these differences: the generalized equation combines the stable subspace with the balanced \( E \) (SciPy uses the original one, which is wrong when balancing scales the pencil), the unbalanced pencil serves as a fallback (see above), and the number of stable eigenvalues is checked.

Example: a discrete-time LQR controller for a sampled double integrator.

// SPDX-FileCopyrightText: The Eigen Authors
// SPDX-License-Identifier: MPL-2.0
#include <contrib/Eigen/Riccati>
#include <iostream>
using namespace Eigen;
int main() {
// Discrete-time LQR for a double integrator sampled with period h:
// minimize sum_k x_k^T Q x_k + u_k^T R u_k subject to x_{k+1} = A x_k + B u_k.
const double h = 0.1;
A << 1, h, 0, 1;
Vector2d B(h * h / 2, h);
Matrix2d Q = Matrix2d::Identity();
R << 0.1;
if (dare.info() != Success) {
std::cout << "The Riccati equation could not be solved.\n";
return 1;
}
const Matrix2d& X = dare.solution();
std::cout << "The stabilizing solution X is:\n" << X << "\n\n";
// The optimal state feedback u_k = -K x_k.
const RowVector2d K = (R + B.transpose() * X * B).ldlt().solve(B.transpose() * X * A);
std::cout << "The optimal gain K is:\n" << K << "\n\n";
std::cout << "The closed-loop eigenvalues of A - B K are:\n" << (A - B * K).eigenvalues() << "\n";
}
DiscreteAlgebraicRiccatiSolver()=default
Default constructor; the solver is initialized by calling compute().
Matrix< double, 2, 1 > Vector2d
Matrix< double, 2, 2 > Matrix2d
Matrix< double, 1, 2 > RowVector2d
Namespace containing all symbols from the Eigen library.

Output:

The stabilizing solution X is:
13.3172 3.20156
3.20156 4.60351

The optimal gain K is:
 2.5857 3.44344

The closed-loop eigenvalues of A - B K are:
 (0.89917,0)
(0.743558,0)

References:

  • [1] P. Van Dooren, "A Generalized Eigenvalue Approach For Solving Riccati Equations", SIAM J. Sci. Stat. Comput., 2(2), 1981.
  • [2] A. J. Laub, "A Schur Method for Solving Algebraic Riccati Equations", MIT LIDS-R-859, 1978.
  • [3] P. Benner, "Symplectic Balancing of Hamiltonian Matrices", SIAM J. Sci. Comput., 22(5), 2001.
See also
class RealQZ, class ComplexQZ

Public Member Functions

template<typename InputTypeA, typename InputTypeB, typename InputTypeQ, typename InputTypeR>
DiscreteAlgebraicRiccatiSolver & compute (const EigenBase< InputTypeA > &A, const EigenBase< InputTypeB > &B, const EigenBase< InputTypeQ > &Q, const EigenBase< InputTypeR > &R, bool balance=true)
 Solves \( A^* X A - X - (A^* X B) (R + B^* X B)^{-1} (B^* X A) + Q = 0 \).
 
template<typename InputTypeA, typename InputTypeB, typename InputTypeQ, typename InputTypeR, typename InputTypeE, typename InputTypeS>
DiscreteAlgebraicRiccatiSolver & compute (const EigenBase< InputTypeA > &A, const EigenBase< InputTypeB > &B, const EigenBase< InputTypeQ > &Q, const EigenBase< InputTypeR > &R, const EigenBase< InputTypeE > &E, const EigenBase< InputTypeS > &S, bool balance=true)
 Solves \( A^* X A - E^* X E - (A^* X B + S) (R + B^* X B)^{-1} (B^* X A + S^*) + Q = 0 \).
 
 DiscreteAlgebraicRiccatiSolver ()=default
 Default constructor; the solver is initialized by calling compute().
 
template<typename InputTypeA, typename InputTypeB, typename InputTypeQ, typename InputTypeR>
 DiscreteAlgebraicRiccatiSolver (const EigenBase< InputTypeA > &A, const EigenBase< InputTypeB > &B, const EigenBase< InputTypeQ > &Q, const EigenBase< InputTypeR > &R, bool balance=true)
 Constructor; solves the discrete-time algebraic Riccati equation.
 
template<typename InputTypeA, typename InputTypeB, typename InputTypeQ, typename InputTypeR, typename InputTypeE, typename InputTypeS>
 DiscreteAlgebraicRiccatiSolver (const EigenBase< InputTypeA > &A, const EigenBase< InputTypeB > &B, const EigenBase< InputTypeQ > &Q, const EigenBase< InputTypeR > &R, const EigenBase< InputTypeE > &E, const EigenBase< InputTypeS > &S, bool balance=true)
 Constructor; solves the generalized discrete-time algebraic Riccati equation.
 
ComputationInfo info () const
 Reports whether the last computation was successful.
 
const MatrixType & solution () const
 

Constructor & Destructor Documentation

◆ DiscreteAlgebraicRiccatiSolver() [1/2]

template<typename MatrixType_>
template<typename InputTypeA, typename InputTypeB, typename InputTypeQ, typename InputTypeR>
Eigen::DiscreteAlgebraicRiccatiSolver< MatrixType_ >::DiscreteAlgebraicRiccatiSolver ( const EigenBase< InputTypeA > & A,
const EigenBase< InputTypeB > & B,
const EigenBase< InputTypeQ > & Q,
const EigenBase< InputTypeR > & R,
bool balance = true )
inline

Constructor; solves the discrete-time algebraic Riccati equation.

This is equivalent to calling compute(const EigenBase<InputTypeA>&, const EigenBase<InputTypeB>&, const EigenBase<InputTypeQ>&, const EigenBase<InputTypeR>&, bool).

◆ DiscreteAlgebraicRiccatiSolver() [2/2]

template<typename MatrixType_>
template<typename InputTypeA, typename InputTypeB, typename InputTypeQ, typename InputTypeR, typename InputTypeE, typename InputTypeS>
Eigen::DiscreteAlgebraicRiccatiSolver< MatrixType_ >::DiscreteAlgebraicRiccatiSolver ( const EigenBase< InputTypeA > & A,
const EigenBase< InputTypeB > & B,
const EigenBase< InputTypeQ > & Q,
const EigenBase< InputTypeR > & R,
const EigenBase< InputTypeE > & E,
const EigenBase< InputTypeS > & S,
bool balance = true )
inline

Member Function Documentation

◆ compute() [1/2]

template<typename MatrixType_>
template<typename InputTypeA, typename InputTypeB, typename InputTypeQ, typename InputTypeR>
DiscreteAlgebraicRiccatiSolver & Eigen::DiscreteAlgebraicRiccatiSolver< MatrixType_ >::compute ( const EigenBase< InputTypeA > & A,
const EigenBase< InputTypeB > & B,
const EigenBase< InputTypeQ > & Q,
const EigenBase< InputTypeR > & R,
bool balance = true )
inline

Solves \( A^* X A - X - (A^* X B) (R + B^* X B)^{-1} (B^* X A) + Q = 0 \).

Parameters
[in]Asquare \( m \times m \) matrix
[in]B\( m \times n \) matrix
[in]Qselfadjoint \( m \times m \) matrix
[in]Rselfadjoint \( n \times n \) matrix
[in]balancewhether the symplectic pencil is balanced before the QZ decomposition, see the class documentation
Returns
a reference to *this

The result of the computation is reported by info().

◆ compute() [2/2]

template<typename MatrixType_>
template<typename InputTypeA, typename InputTypeB, typename InputTypeQ, typename InputTypeR, typename InputTypeE, typename InputTypeS>
DiscreteAlgebraicRiccatiSolver & Eigen::DiscreteAlgebraicRiccatiSolver< MatrixType_ >::compute ( const EigenBase< InputTypeA > & A,
const EigenBase< InputTypeB > & B,
const EigenBase< InputTypeQ > & Q,
const EigenBase< InputTypeR > & R,
const EigenBase< InputTypeE > & E,
const EigenBase< InputTypeS > & S,
bool balance = true )
inline

Solves \( A^* X A - E^* X E - (A^* X B + S) (R + B^* X B)^{-1} (B^* X A + S^*) + Q = 0 \).

Parameters
[in]Asquare \( m \times m \) matrix
[in]B\( m \times n \) matrix
[in]Qselfadjoint \( m \times m \) matrix
[in]Rselfadjoint \( n \times n \) matrix
[in]Enonsingular \( m \times m \) matrix
[in]S\( m \times n \) matrix
[in]balancewhether the symplectic pencil is balanced before the QZ decomposition, see the class documentation
Returns
a reference to *this

Pass the identity for E or zero for S to leave out one of the generalized terms. The result of the computation is reported by info().

◆ info()

template<typename MatrixType_>
ComputationInfo Eigen::DiscreteAlgebraicRiccatiSolver< MatrixType_ >::info ( ) const
inline

Reports whether the last computation was successful.

Returns
Success if the computation was successful, InvalidInput if an input matrix is not finite, Q or R is not selfadjoint, or E is numerically singular, NoConvergence if the QZ iteration did not converge, and NumericalIssue if the stable deflating subspace of the symplectic pencil could not be isolated (no stabilizing solution exists, the pencil has eigenvalues too close to the unit circle, or the solution would be too large to compute, see the class documentation).

◆ solution()

template<typename MatrixType_>
const MatrixType & Eigen::DiscreteAlgebraicRiccatiSolver< MatrixType_ >::solution ( ) const
inline
Returns
the stabilizing solution \( X \) of the Riccati equation, which is selfadjoint.
Precondition
The solver has been initialized and info() returns Success.

The documentation for this class was generated from the following file: