线性矩阵不等式LMI是控制领域的一个强有力的设计工具,许多控制理论及分析与综合问题都可简化为相应的LMI问题,通过构造有限的计算机算法求解,Lyapunov方程、Schur补引理以及交叉项放大在非线性矩阵不等式与LMI的转化过程中起着极为重要的作用。本章是对基于扰动观测器的控制系统进行仿真,使用YALMIP工具箱求解LMI,用simulink的S函数编写控制器和受控对象的程序,结合MATLAB画图函数plot实现系统的仿真。。。
附有 YALMIP下载网址
以下仿真程序都是用MATLAB来编写的
clear all
clc
J = 1/133; b = 25/133;
A = [0 1; 0 -b/J];
B = [0 1/J]';
P1 = sdpvar(2,2,'symmetric');
Q1 = sdpvar(2,2,'symmetric');
K1 = sdpvar(1,2);
R1 = sdpvar(1,2);
alfa = 100;
sigma1 = 10;
Fai = [A * Q1 + B * R1 + (A * Q1 + B * R1)' + alfa * Q1 B; B' -(K1*B + B' * K1') + sigma1 + alfa];
L = [Fai < 0, Q1 > 0];
solvesdp(L)
K1 = double(K1);
Q1 = double(Q1);
R1 = double(R1);
P1 = inv(Q1);
K = R1 * P1
function [sys,x0,str,ts] = plant(t,x,u,flag)
switch flag
case 0
[sys,x0,str,ts]=mdlInitializeSizes;
case 1
sys=mdlDerivatives(t,x,u); % dx
case 3
sys=mdlOutputs(t,x,u); % y
case {2,4,9}
sys = [];
otherwise
error(['Unhandled falg = ',num2str(flag)])
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 2;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 0; % at least one sample time is needed
sys = simsizes(sizes);
x0 = [1 0];
str = [];
ts = [];
function sys=mdlDerivatives(t,x,u)
A = [0 1 ; 0 -25];
B = [0 133]';
ut = u(1);
dt = 5 * sin(0.1* t);
dx = A * x + B * (ut + dt);
sys(1) = dx(1);
sys(2) = dx(2);
function sys=mdlOutputs(t,x,u)
dt = 5 * sin(0.1* t);
sys(1) = x(1);
sys(2) = x(2);
sys(3) = dt;
function [sys,x0,str,ts] = ctrl(t,x,u,flag)
switch flag
case 0
[sys,x0,str,ts]=mdlInitializeSizes;
case 1
sys=mdlDerivatives(t,x,u); % dx
case 3
sys=mdlOutputs(t,x,u); % y
case {2,4,9}
sys = [];
otherwise
error(['Unhandled falg = ',num2str(flag)])
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 1;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 2;
sizes.NumInputs = 3;
sizes.DirFeedthrough =1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
x0 = [0];
str = [];
ts = [0 0];
function sys=mdlDerivatives(t,x,u)
x1 = u(1);
x2 = u(2);
X = [x1 x2]';
K = [ -55.6261 -0.7457];
A = [0 1 ; 0 -25];
B = [0 133]';
z = x(1);
K1 = [0 2.7568];
dp = z + K1 * X;
ut = K * X - dp;
sys(1) = -K1 * (A * X + B * (ut + dp));
function sys=mdlOutputs(t,x,u)
x1 = u(1);
x2 = u(2);
X = [x1 x2]';
K1 = [0 2.7568];
K = [ -55.6261 -0.7457];
z = x(1);
dp = z + K1 * X;
ut = K * X -dp;
sys(1) = ut;
sys(2) = dp;
figure(1)
subplot(2,1,1)
plot(t,x(:,1),'r','linewidth',2)
xlabel('time(s)')
ylabel('x1 response')
subplot(2,1,2)
plot(t,x(:,2),'b','linewidth',2)
xlabel('time(s)')
ylabel('x2 response')
figure(2)
plot(t,ut(:,1),'r','linewidth',2)
xlabel('time(s)')
ylabel('ut')
figure(3)
plot(t,ut(:,2),'r',t,x(:,3),'k','linewidth',2)
xlabel('time(s)')
ylabel('d,dp')
figure(1)
figure(2)
figure(3)
出现“ matlab plot方法只能用于单时序对象 ”怎么解决?
需要修改simulink中的to workspace
(1)save format 改为array
(2)save 2-D signals as 改为Inherit from input (this choice will be removed - see release notes)
双击to workspace修改如下: