MATLAB中的LQR函数用法
以倒立摆控制器的设计为例:
A = [0 1 0 0
0 0 -1 0
0 0 0 1
0 0 9 0];
B = [0;0.1;0;-0.1];
C = [0 0 1 0]; %观测角度
D = 0;
Q = [1 0 0 0
0 1 0 0
0 0 10 0
0 0 0 10
];
R = 0.1;
%由上面这个系统,可以计算出K
K = lqr(A,B,Q,R);
Ac = A - B*K;
%对系统进行模拟
x0 = [0.1;0;0.1;0]; %初始状态
t = 0:0.05:20;
u = zeros(size(t));
[y,x]=lsim(Ac,B,C,D,u,t,x0);
plot(t,y);
扩展资料
matlab中LQR的使用:
sys_c=ss(Ac,Bc,Cc,Dc);
[Y,T,X]=lsim(sys_c,U,T);
释义:
sys_c=ss(Ac,Bc,Cc,Dc);以Ac,Bc,Cc,Dc作为参数,创建一个状态空间模型。状态空间(ss)是MATLAB控制系统工具箱中非常重要的一种模型形式,和传递函数(tf)、零极点(zpk)可以互相转换。
[Y,T,X]=lsim(sys_c,U,T);使用lsim函数对系统进行仿真。lsim可以接受任意形式的输入信号,不过,就现在的输入信号而言,使用的是单位阶跃信号,其实也可以改用step函数:[Y,T,X]=step(sys_c);结果完全相同。
LQR Linear-quadratic regulator design for state space systems.
[K,S,E] = LQR(SYS,Q,R,N) calculates the optimal gain matrix K
such that:
* For a continuous-time state-space model SYS, the state-feedback
law u = -Kx minimizes the cost function
J = Integral {x'Qx + u'Ru + 2*x'Nu} dt
subject to the system dynamics dx/dt = Ax + Bu
* For a discrete-time state-space model SYS, u[n] = -Kx[n] minimizes
J = Sum {x'Qx + u'Ru + 2*x'Nu}
subject to x[n+1] = Ax[n] + Bu[n].
The matrix N is set to zero when omitted. Also returned are the
the solution S of the associated algebraic Riccati equation and
the closed-loop eigenvalues E = EIG(A-B*K).
[K,S,E] = LQR(A,B,Q,R,N) is an equivalent syntax for continuous-time
models with dynamics dx/dt = Ax + Bu
广告 您可能关注的内容 |