lqrpid(sys,Q,R,varargin)
lqrpid: LQR-based PID output-feedback controller design for LTI ss systems.
[F,P,E] = lqrpid(sys,Q,R,N) calculates the optimal (if l=n/2) or the
sub-optimal (if l~=n/2) output-feedback PID (Proportional-Integral
-Derivative) gain matrix F = [Kp,Ki,Kd], such that:
* For a continuous-time state-space model SYS, the output-feedback
law:
u = - Kp y - Ki Integral y dt - Kd dy/dt,
minimizes the cost function:
J = Integral {x'Qx + u'Ru + 2x'Nu} dt
Subject to the system dynamics dx/dt = Ax + Bu; y = Cx
INPUTS:
REQUIRED
SYS - state-space LTI system (ss: sys.a,sys.b,sys.c...)
Q - weighting matrix related to states (Q >= 0 if N == 0)
R - positive definite weighting matrix (R > 0)
OPTIONAL
N - The matrix N is set to zero when omitted.
If N~=0 then Q-N*inv(R)*N'>=0 (use eig to check)
OUTPUTS:
F - static output-feedback gain matrix containing the
PID gains F = [Kp,Ki,Kd]
P - Lyapunov matrix
E - Closed-loop system eigen values
ASSUMPTIONS:
- The pair ([A,0;C,0],[B;0]) is stabilizable,
- R > 0 and Q-N*inv(R)*N' >= 0,
- Q-N*inv(R)*N' and A-B*inv(R)*N' have no unobservable mode on the
imaginary axis
OTHER INFO:
- The size of the weighting matrices is AUGMENTED:
Q(n+l,n+l), R(m,m), N(n+l,m)
where
n - number of states,
m - number of inputs,
l - number of outputs,
because the system is augmented with additional state variable(s)
for the PID controller design.
- Optimal solution is for l=n/2. If l~=n/2, an approximation is
calculated and tested for stability.
REQUIREMENTS:
Matlab:
- control system toolbox installed
Octave:
- control package installed and loaded
This function is based on:
S. Mukhopadhyay: P.I.D. equivalent of optimal regulator,
Electronics Letters, Vol. 14, No. 25, pp. 821-822, 1978.
Tested with Matlab 2014b/Octave 4.0
Cite As
Adrian Ilka (2025). lqrpid(sys,Q,R,varargin) (https://www.mathworks.com/matlabcentral/fileexchange/62117-lqrpid-sys-q-r-varargin), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
