【预测模型】基于matlab离散状态空间模型模拟预测控制仿真系统(单输入单输出)【含Matlab源码 1537期】

举报
海神之光 发表于 2022/05/28 23:23:28 2022/05/28
【摘要】 一、获取代码方式 获取代码方式1: 完整代码已上传我的资源: 【预测模型】基于matlab离散状态空间模型模拟预测控制仿真系统(单输入单输出)【含Matlab源码 1537期】 获取代码方式2: 通过...

一、获取代码方式

获取代码方式1:
完整代码已上传我的资源: 【预测模型】基于matlab离散状态空间模型模拟预测控制仿真系统(单输入单输出)【含Matlab源码 1537期】

获取代码方式2:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。

备注:订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);

二、部分源代码

% Testes do controlador preditivo
clear, clc
s = tf('s');
% Definição da planta
Ts = 1;
% G = c2d((50/(20*s+1)),Ts);
% num = cell2mat(G.Numerator);
% den = cell2mat(G.Denominator);
% [A,B,C,D] = tf2ss(num,den);
A = [1 1;0 1];
B = [0.5;1];
C = [1 0];
x_o = [0;0]; % Condições iniciais dos estados
y_o = 0;   % Condições iniciais das saídas

% Controle preditivo
Np = 20; Nc = 4; r_w = 0; ref = 1; Nsim = 100;
[y1, u1] = mpc_simulation_siso(A, B, C, y_o, Np, Nc, Nsim, r_w, ref);
Np = 20; Nc = 4; r_w = 1; ref = 1; Nsim = 100;
[y2, u2] = mpc_simulation_siso(A, B, C, y_o, Np, Nc, Nsim, r_w, ref);
Np = 20; Nc = 4; r_w = 100; ref = 1; Nsim = 100;
[y3, u3] = mpc_simulation_siso(A, B, C, y_o, Np, Nc, Nsim, r_w, ref);

t = 0:Nsim-1;
figure
subplot(211)
plot(t,y1,t,y2,t,y3)
grid on
xlabel('Instante de amostragem')
ylabel('Saída do processo')
legend('r_w = 0','r_w = 1','r_w = 100', 'Location', 'Southeast');
subplot(212)
plot(t,u1,t,u2,t,u3)
grid on
xlabel('Instante de amostragem')
ylabel('Sinal de controle')
legend('r_w = 0','r_w = 1','r_w = 100');
function [y, u] = mpc_simulation_siso(A_m, B_m, C_m, y_k, Np, Nc, Nsim, r_w, ref)
%



n1 = length(B_m);
% Condições iniciais:
x = zeros(n1,1); % Condições nulas mencionadas
x = [x; y_k]; % DeltaX = x(0) = [x_m(0); y(0)] - x_m(-1) = 0
u_k = 0; % u(0) = 0;

% Vetores de saídas da função
u = zeros(1,Nsim);
y = zeros(1,Nsim);

% Matrizes importantes a serem usadas
[A, B, C, Phi, F] = mpcgain(A_m, B_m, C_m, Np, Nc);

H_inv = (Phi')*Phi + r_w*eye(Nc); % Matriz Hessiana inversa
if det(H_inv) == 1e-4
    error('Hessian Matrix does not exist');
end
Mat_gain = inv(H_inv)*(Phi')*F;

% Ganhos do controlador:
K_mpc = Mat_gain(1,:); % A primeira linha de H*(Phi^T)*F
K_y = K_mpc(length(K_mpc)); % K_y = último elemento de K_mpc
fprintf('Ganhos do controlador:\nK_mpc = [');
fprintf('%f ',K_mpc);
fprintf(']\nK_y = %f\n', K_y);
fprintf('Iniciando a simulação do controlador preditivo...\n');
for k = 1:Nsim
    %Cálculo do esforço de controle Delta_u
    deltau = K_y*ref - K_mpc*x;
    u_k = deltau + u_k; %Sinal de controle do processo
    % Salvando vetor de dados
    u(k) = u_k;
    y(k) = y_k;
    % Aplicando ao processo, utilizando o modelo aumentado do sistema
    y_k = C*x; %Saída real do processo
    x = A*x + B*deltau; %Vetor de estados x(k)
end

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79

三、运行结果

在这里插入图片描述

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.

文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。

原文链接:qq912100926.blog.csdn.net/article/details/121590693

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。