.Modelica_LinearSystems2.StateSpace.Design.lqr

Information

Syntax

(K, sslqr, X, ev) = StateSpace.lqr(ss, Q, R, true)

Description

The optimal and stabilizing gain matrix K for a state-feedback law u = -K*x is designed such that the cost function

J = Integral {x'*Q*x + u'*R*u} dt

of the continuous time case or

Jd = Sum {x'k*Q*xk + u'k*R*uk}

of the discrete time case is minimized. The cases are chosen by the input iscontinuousSystem This is done by solving the continuous-time algebraic Riccati equation (CARE)

Q + A'*X + X*A - X*B*R-1*B'*X = 0

or the discrete-time algebraic Riccati equation (DARE)

X - A'*X*A + A'*X*B*(R + B'*X*B)-1*B'*X*A - Q = 0

for X using the Schur vector approach. See care and dare respectively for more details.

The gain matrix K of the continuous-time case is calculated from

K = R-1*B'*X

or from

K = (R + B'*X*B)-1*B'*X*A

for the discrete-time case. The output state space system sslqr represents the closed loop system

  .
  x = [A - BK] x + Bu

  y = [C - DK] x + Du

The output S is the solution of the Riccati equation

The eigenvalues of the closed loop system A - B*K are computed as complex output ev.

Example

  StateSpace ss=StateSpace(
    A=[0, 1, 0, 0; 0, 0, 39.2, 0; 0, 0, 0, 1; 0, 0, 49, 0],
    B=[0; 1; 0; 1],
    C=[1, 0, 0, 0],
    D=[0]);
  Real Q[:,:]=identity(4);
  Real R[:,:]=identity(1);
  Real K[size(ss.B, 2),size(ss.A, 1)];

algorithm
  K := StateSpace.Design.lqr(ss, Q, R);

// K = [-1, -3.63271, 108.763, 18.3815]

Interface

encapsulated function lqr
  import Modelica;
  import Complex;
  import Modelica_LinearSystems2;
  import Modelica_LinearSystems2.StateSpace;
  import Modelica_LinearSystems2.Math;
  input StateSpace ss "Open loop system in state space form";
  input Real Q[size(ss.A, 1), size(ss.A, 2)] = identity(size(ss.A, 1)) "State weighting matrix";
  input Real R[size(ss.B, 2), size(ss.B, 2)] = identity(size(ss.B, 2)) "Input weighting matrix";
  output Real K[size(ss.B, 2), size(ss.A, 1)] "Feedback gain matrix";
  output StateSpace sslqr(redeclare Real A[size(ss.A, 1), size(ss.A, 2)], redeclare Real B[size(ss.B, 1), size(ss.B, 2)], redeclare Real C[size(ss.C, 1), size(ss.C, 2)], redeclare Real D[size(ss.D, 1), size(ss.D, 2)]) "closed loop system";
  output Real S[size(ss.A, 1), size(ss.A, 1)] "solution of the Riccati equation";
  output Complex ev[:] "Eigenvalues of the closed loop system";
end lqr;

Revisions

Date Author Comment
2010-05-31 Marcus Baur, DLR-RM Realization

Generated at 2024-12-26T19:25:54Z by OpenModelicaOpenModelica 1.24.3 using GenerateDoc.mos