# dlqr

Linear-quadratic (LQ) state-feedback regulator for discrete-time state-space system

## Syntax

```[K,S,e] = dlqr(A,B,Q,R,N) ```

## Description

`[K,S,e] = dlqr(A,B,Q,R,N) ` calculates the optimal gain matrix `K` such that the state-feedback law

`$u\left[n\right]=-Kx\left[n\right]$`

`$J\left(u\right)=\sum _{n=1}^{\infty }\left(x{\left[n\right]}^{T}Qx\left[n\right]+u{\left[n\right]}^{T}Ru\left[n\right]+2x{\left[n\right]}^{T}Nu\left[n\right]\right)$`

for the discrete-time state-space model

`$x\left[n+1\right]=Ax\left[n\right]+Bu\left[n\right]$`

The default value `N=0` is assumed when `N` is omitted.

In addition to the state-feedback gain `K`, `dlqr` returns the infinite horizon solution S of the associated discrete-time Riccati equation

`${A}^{T}SA-S-\left({A}^{T}SB+N\right){\left({B}^{T}SB+R\right)}^{-1}\left({B}^{T}SA+{N}^{T}\right)+Q=0$`

and the closed-loop eigenvalues `e = eig(A-B*K)`. Note that K is derived from S by

`$K={\left({B}^{T}SB+R\right)}^{-1}\left({B}^{T}SA+{N}^{T}\right)$`

## Limitations

The problem data must satisfy:

• The pair (A, B) is stabilizable.

• R > 0 and Q − NR–1NT ≥ 0

• (Q − NR–1NT, A − BR–1NT) has no unobservable mode on the unit circle.