1.对于一个单输入单输出的系统来说:
其误差e_error = |y(t) - u(t)|
设计以下两种积分:
cost function:
其中q,r为可调节参数:q>>r看重误差,q<
cost function:
其中Q、R为调节矩阵
3.对于离散模型
cost function:
最后一项为横截误差。
离散状态下进行推导:
在k时刻:
得(1)式:
得(2)式
将(1)带入(2)得:
%mpc模型预测控制建议去看B站up主DR_CAN的视频
function [M,C,Q_bar,R_bar,G,E,H,U_k]=mpc_1(A,B,N,x_k,Q,R,F)
%N是第n步预测
n=size(A,1);
p=size(B,2);
M=[eye(n);zeros(N*n,n)];
C=zeros((N+1)*n,N*p);
tmp=eye(n);
for i=1:N
rows=i*n+(1:n);
C(rows,:)=[tmp*B,C(rows-n,1:end-p)];
tmp=A*tmp;
M(rows,:)=tmp;
end
S_q=size(Q,1);
S_r=size(R,1);
Q_bar=zeros((N+1)*S_q,(N+1)*S_q);
for i=0:N
Q_bar(i*S_q+1:(i+1)*S_q,i*S_q+1:(i+1)*S_q)=Q;
end
Q_bar(N*S_q+1:(N+1)*S_q,N*S_q+1:(N+1)*S_q)=F;
R_bar=zeros(N*S_r,N*S_r);
for i=0:N-1
R_bar(i*S_r+1:(i+1)*S_r,i*S_r+1:(i+1)*S_r)=R;
end
G=M'*Q_bar*M;
E=C'*Q_bar*M;
H=C'*Q_bar*C+R_bar;
f=(x_k'*E')';
U_k=quadprog(H,f);
end
%计算演示:
A =
1.0000 0.1000
0 2.0000
B =
0
0.5000
N =
3
x_k =
5
5
Q =
1 0
0 1
R =
0.1000
F=Q
[M,C,Q_bar,R_bar,G,E,H,U_k]=mpc_1(A,B,N,x_k,Q,R,F) %调用mpc计算模块,可得以下结果
M =
1.0000 0
0 1.0000
1.0000 0.1000
0 2.0000
1.0000 0.3000
0 4.0000
1.0000 0.7000
0 8.0000
C =
0 0 0
0 0 0
0 0 0
0.5000 0 0
0.0500 0 0
1.0000 0.5000 0
0.1500 0.0500 0
2.0000 1.0000 0.5000
Q_bar =
1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 1
R_bar =
0.1000 0 0
0 0.1000 0
0 0 0.1000
G =
4.0000 1.1000
1.1000 85.5900
E =
0.2000 21.1200
0.0500 10.0350
0 4.0000
H =
5.3750 2.5075 1.0000
2.5075 1.3525 0.5000
1.0000 0.5000 0.3500
U_k =
-18.0330
-3.7563
-0.2540