# LQRegulatorGains

LQRegulatorGains[spsec,wts]

gives the state feedback gains for the system specification sspec that minimizes a cost function with weights wts.

LQRegulatorGains[,"prop"]

gives the value of the property "prop".

# Details and Options    • LQRegulatorGains is also known as linear quadratic regulator, linear quadratic controller or optimal controller.
• LQRegulatorGains is typically used to stabilize a system or improve its performance.
• The controller is typically given by a state feedback , where is the computed gain matrix.
• • The inputs u of sys consist of feedback inputs ufand possibly other inputs ue.
• The system specification sspec is the system sys together with the uf specification.
• LQRegulatorGains minimizes a quadratic cost function with weights q, r and p of the states x and feedback inputs uf of a linear system sys:
• continuous-time system discrete-time system
• LQ design works for linear systems as specified by StateSpaceModel:
• continuous-time system discrete-time system
• The resulting feedback gain matrix is then computed from algebraic Riccati equations:
• continuous-time system and is the solution to the continuous-time algebraic Riccati equation  discrete-time system and is the solution to the discrete-time algebraic Riccati equation .
• The submatrix bf is columns of b corresponding to the feedback inputs uf.
• The weights wts can have the following forms:
•  {q,r} cost function with no cross-coupling {q,r,p} cost function with cross-coupling matrix p
• The system specification sspec can have the following forms:
•  StateSpaceModel[…] linear control input and linear state AffineStateSpaceModel[…] linear control input and nonlinear state NonlinearStateSpaceModel[…] nonlinear control input and nonlinear state SystemModel[…] general system model <|…|> detailed system specification given as an Association
• The detailed system specification can have the following keys:
•  "InputModel" sys any one of the models "FeedbackInputs" All the feedback inputs uf
• The feedback inputs can have the following forms:
•  {num1,…,numn} numbered inputs numi used by StateSpaceModel, AffineStateSpaceModel and NonlinearStateSpaceModel {name1,…,namen} named inputs namei used by SystemModel All uses all inputs
• For nonlinear systems such as AffineStateSpaceModel, NonlinearStateSpaceModel and SystemModel, the system will be linearized around its stored operating point.
• LQRegulatorGains[,"Data"] returns a SystemsModelControllerData object cd that can be used to extract additional properties using the form cd["prop"].
• LQRegulatorGains[,"prop"] can be used to directly give the value of cd["prop"].
• Possible values for properties "prop" include:
•  "ClosedLoopPoles" poles of the linearized "ClosedLoopSystem" "ClosedLoopSystem" system csys with ue and as input and y as output {"ClosedLoopSystem", cspec} detailed control over the form of the closed-loop system "ControllerModel" model cm with and x as input and uf as output "Design" type of controller design "DesignModel" model used for the design "FeedbackGains" gain matrix κ or its equivalent "FeedbackGainsModel" model gm with x as input and as output "FeedbackInputs" inputs uf of sys used for feedback "InputModel" input model sys "InputsCount" number of inputs u of sys "OpenLoopPoles" poles of "DesignModel" "OutputsCount" number of outputs y of sys "SamplingPeriod" sampling period of sys "StatesCount" number of states x of sys
• Possible keys for cspec include:
•  "InputModel" input model in csys "Merge" whether to merge csys "ModelName" name of csys
• The diagram of the feedback gains model gm, controller model cm, and closed-loop system csys.

# Examples

open allclose all

## Basic Examples(5)

Compute the optimum feedback gain matrix for a continuous-time system:

Calculate the optimal control gains for an unstable system:

Compare the open- and closed-loop poles:

Compute the optimal state-feedback gain matrix for a discrete-time system:

Calculate the feedback gains for controlling a two-input system using the first input:

A set of feedback gains for a stabilizable but uncontrollable system:

## Scope(26)

### Basic Uses(7)

Compute the state feedback gain of a system with equal weighting for the state and input:

The closed-loop system:

Compute the gain for an unstable system:

The gain stabilizes the unstable system:

Compute the state feedback gains for a multiple-state system:

The dimensions of the result correspond to the number of inputs and the system's order:

Compute the gains for a system with 3 states and 2 inputs:

Reverse the weights of the feedback inputs:

Typically, the feedback input with the bigger weight has the smaller norm:

Compute the gains when the cost function contains cross-coupling of the states and feedback inputs:

Choose the feedback inputs for multiple-input systems:

Choose the first input:

Choose the second input:

Compute the gains for a nonlinear system:

The controller is returned as a vector and takes operating points into consideration:

The controller for the approximate linear system:

### Plant Models(6)

Continuous-time StateSpaceModel:

Discrete-time StateSpaceModel:

Descriptor StateSpaceModel:

### Properties(10)

LQRegulatorGains returns the feedback gains by default:

In general, the feedback is affine in the states:

It is of the form κ0+κ1.x, where κ0 and κ1 are constants:

The systems model of the feedback gains:

An affine systems model of the feedback gains:

The closed-loop system:

The poles of the linearized closed-loop system:

Increasing the weight of the states makes the system more stable:

Increasing the weight of the feedback inputs makes the system less stable:

The model used to compute the feedback gains:

The gains of the design model and input model:

The design method:

Properties related to the input model:

Get the controller data object:

The list of available properties:

The value of a specific property:

### Closed-Loop System(3)

Assemble the closed-loop system for a nonlinear plant model:

The closed-loop system with a linearized model:

Compare the response of the two systems:

Assemble the merged closed loop of a plant with one disturbance and one feedback input:

The unmerged closed-loop system: When merged, it gives the same result as before:

Explicitly specify the merged closed-loop system:

Create a closed-loop system with a desired name:

The closed-loop system has the specified name:

The name can be directly used to specify the closed-loop model in other functions:

The simulation result:

## Applications(3)

Compute a set of state feedback gains that stabilizes an unstable system:

The response of the closed-loop system to a step input:

The open-loop system is unstable:

Compute the Hessian of the cost function's integrand to determine the weighting matrices:

The natural response of the closed-loop system:

Without feedback, the system is highly oscillatory:

Design a regulator for the discrete-time model of a mixing tank system:

The response of the system to an impulse at the second input:

## Properties & Relations(9)

A set of feedback gains for a stabilizable but uncontrollable system:

Find the optimal feedback gains for a continuous-time system:

The same solution can be obtained from the solution to the continuous-time Riccati equation:

Find the optimal feedback gains for a discrete-time system:

The same solution can be obtained from the solution to the discrete-time Riccati equation:

Find the loop gain transfer function for an LQR design:

Its Nyquist plot lies outside the unit circle centered at :

Consequently, the gain margin and the phase margin satisfies and :

The gains associated with a state increase as its weight is increased:

The higher penalty of the second state reduces its overshoot:

Find the optimal gains for a stable system as input cost is varied:

The gain converges to zero as approaches zero, or approaches infinity:

As the gain decreases, the closed-loop poles move closer to the open-loop ones:

Find the optimal gains for an unstable system as state cost is varied:

The gain converges to a minimum as approaches zero, or approaches infinity:

As k decreases, the closed-loop poles move nearer the stable open-loop poles and mirror images of unstable ones:

When approaches infinity, or approaches zero, the gain becomes unbounded:

As the gains increase, the states are penalized more, and their values become smaller:

The optimal cost-to-go is a Lyapunov function:

The state trajectory projected on the optimal cost surface asymptotically approaches the origin:

The optimal state trajectory for a system with one state:

The co-state trajectory:

The optimal input trajectory:

The optimal cost trajectory:

The optimal cost satisfies the infinite horizon HamiltonJacobiBellman equation:

The optimal input minimizes the Hamiltonian, thus satisfying :

## Possible Issues(4)

The gain computations fail for an unstabilizable system: The gain computations fail if the control weighting matrix is not positive definite: Use a positive-definite control weighting matrix:

If has unobservable modes on the imaginary axis, there is no continuous-time solution: The zero eigenvalue is unobservable:

If has unobservable modes on the unit circle, there is no discrete-time solution: The eigenvalue 1 is unobservable: