% Carleman MHE+MPC
% Unstable CSTR example
close all
format compact
clear
% profile on
global q CAf Tf V UA k0 ER deltaH rho Cp Tcs CAs TRs
global dt N xs us
global A C B B0 D D0
% parameters
q = 100; % liter/min
CAf = 1; % mol/liter
Tf = 350; % K
V = 100; % liter
UA = 5*10^4; % J/(min K)
k0 = 7.2*10^10; % min^-1
ER = 8750; % K
deltaH = -5*10^4; % J/mol
rho = 1000; % g/liter
Cp = 0.239; % J/(g K)
Tcs = 311.1; % K
CAs = 0.093266127453016; % mol/liter
TRs = 3.850293553820693e+02;% K
xs=[CAs;TRs];
us=Tcs;
dt=0.05;
N=3;
sim_window=2.5;
tp=sim_window/dt;
load real_noise2.mat
load carleman_matrices.mat
% load num_H.mat
w=noise;
w_es=zeros(N,tp);% keep the 1st in the sequence
x0_es=zeros(2,tp);
cx_current=zeros(2,tp+N);
x_record=zeros(2,tp+N+1);
m_input=zeros(1,tp+N);
% load the 1st window
x_record(:,1:1+N)=x_1st_window-xs;
m_input(1:N)=0*ones(1,N);
% Operating time
T=0:dt:sim_window+N*dt;
% Initial condition
x_last=[0;0];
x_real_0=x_1st_window(:,1+N);
% Prelocate Carleman matrices
Ai=zeros(5,5,5);
I=eye(5);
cx=zeros(5,N+1);
cx0=x_last;
dummy=[cx0;kron(cx0,cx0)];
cx(:,1)=dummy([1 2 3 5 6]);
for j=1:tp
% MHE
[design_var,~]=estimate_cstr(x_record(:,j:j+N),m_input(j:j+N-1),x_last,sen_noise(j:j+N));
x0_es(1,j)=design_var(1);
x0_es(2,j)=x_record(2,j)+sen_noise(j);
x_last=x0_es(:,j);
w_es(:,j)=design_var(2:4);
cx0=x0_es(:,j);
dummy=[cx0;kron(cx0,cx0)];
cx(:,1)=dummy([1 2 3 5 6]);
for k=1:1:N
Ai(:,:,k)=A+B*m_input(j+k-1)+D*w_es(k,j);
cx(:,k+1)=expm(Ai(:,:,k)*dt)*cx(:,k)+Ai(:,:,k)\(expm(Ai(:,:,k)*dt)-I)*(C+B0*m_input(j+k-1)+D0*w_es(k,j));
x_r=cx(:,k+1);
dummy=[x_r([1 2]);kron(x_r([1 2]),x_r([1 2]))];
cx(:,k+1)=dummy([1 2 3 5 6]);
end
cx_current(:,j+N)=cx(1:2,N+1);
% MPC
[u,~]=control_cstr(cx_current(:,j+N));
m_input(j+N)=u(1);
[~,x_real]=ode45(@ode_feedback_system,[dt*(j+N),dt*(j+N+1)],x_real_0,odeset,m_input(j+N)+us,noise(j+N));
x_record(:,j+N+1)=x_real(end,:)'-xs;
x_real_0=x_real(end,:);
end
% Simulate Open-loop system for comparison
x0=xs;
x_open=zeros(2,tp+N);
x_open(:,1)=x0;
for j=1:tp+N
[~,x]=ode45(@ode_open_loop_system,[dt*(j-1),dt*j],x0,odeset,noise(j));
x_open(:,j+1)=x(end,:);
x0=x(end,:);
end
figure(1)
subplot(3,1,1);
hold on
box on
plot(T(1:tp+N),x_record(1,1:tp+N)+xs(1),'b-','LineWidth',3)
plot(T(1+N:tp+N),cx_current(1,1+N:tp+N)+xs(1),'r--','LineWidth',3)
axis([0 sim_window+N*dt 0.08 0.11])
xlabel('Time [min]','FontSize', 14)
ylabel('C_A [mol/liter]','FontSize', 14)
grid on
subplot(3,1,2);
hold on
box on
plot(T(1:tp+N),x_record(2,1:tp+N)+xs(2),'b-','LineWidth',3)
plot(T(1+N:tp+N),cx_current(2,1+N:tp+N)+xs(2),'r--','LineWidth',3)
axis([0 sim_window+N*dt 384.8 385.6])
xlabel('Time [min]','FontSize', 14)
ylabel('T_R [K]','FontSize', 14)
grid on
subplot(3,1,3);
hold on
box on
plot(T(1:tp),noise(1:tp),'b-','LineWidth',3)
plot(T(1:tp),w_es(1:tp),'r--','LineWidth',3)
xlabel('Time [min]','FontSize', 14)
ylabel('w [L/min]','FontSize', 14)
grid on
figure(2)
subplot(3,1,1);
hold on
box on
plot(T(1:tp+N),x_record(1,1:tp+N)+xs(1),'b-','LineWidth',3)
plot(T(1:tp+N),x_open(1,1:tp+N),'r-','LineWidth',3)
axis([0 sim_window+N*dt 0.08 0.12])
xlabel('Time [min]','FontSize', 14)
ylabel('C_A [mol/liter]','FontSize', 14)
grid on
subplot(3,1,2);
hold on
box on
plot(T(1:tp+N),x_record(2,1:tp+N)+xs(2),'b-','LineWidth',3)
plot(T(1:tp+N),x_open(2,1:tp+N),'r-','LineWidth',3)
axis([0 sim_window+N*dt 382 387])
xlabel('Time [min]','FontSize', 14)
ylabel('T_R [K]','FontSize', 14)
grid on
subplot(3,1,3);
hold on
box on
plot(T(1:tp+N),m_input+us,'b-','LineWidth',3)
plot(T(1:tp+N),Tcs*ones(1,tp+N),'r-','LineWidth',3)
axis([0 sim_window+N*dt 303 318])
xlabel('Time [min]','FontSize', 14)
ylabel('T_c [K]','FontSize', 14)
grid on
figure(4)
hold on
box on
plot(T(1:tp+N),x_record(1,1:tp+N)+xs(1),'b-','LineWidth',3)
plot(T(1+N:tp+N),cx_current(1,1+N:tp+N)+xs(1),'r--','LineWidth',3)
axis([0 sim_window+N*dt 0.08 0.11])
yticks([0.08 0.09 0.10 0.11])
set(gca,'fontsize',20)
xlabel('Time [min]','FontSize', 20)
ylabel('C_A [mol/liter]','FontSize', 20)
grid on
figure(5)
hold on
box on
plot(T(1:tp+N),x_record(2,1:tp+N)+xs(2),'b-','LineWidth',3)
plot(T(1+N:tp+N),cx_current(2,1+N:tp+N)+xs(2),'r--','LineWidth',3)
axis([0 sim_window+N*dt 384 386])
xlabel('Time [min]','FontSize', 20)
ylabel('T_R [K]','FontSize', 20)
yticks([384 384.5 385 385.5 386])
set(gca,'fontsize',20)
grid on
% ==========Figures for Papers=============================================
figure(11)
hold on
box on
plot(T(1:tp+N),x_record(1,1:tp+N)+xs(1),'b-','LineWidth',3)
% plot(T(1:tp+N),x_open(1,1:tp+N),'r-','LineWidth',3)
axis([0 sim_window+N*dt 0.08 0.11])
set(gca,'fontsize',24)
xlabel('Time [min]','FontSize', 24)
ylabel('C_A [mol/liter]','FontSize', 24)
yticks([0.08 0.09 0.10 0.11])
grid on
figure(12)
hold on
box on
plot(T(1:tp+N),x_record(2,1:tp+N)+xs(2),'b-','LineWidth',3)
% plot(T(1:tp+N),x_open(2,1:tp+N),'r-','LineWidth',3)
axis([0 sim_window+N*dt 383 387])
set(gca,'fontsize',24)
xlabel('Time [min]','FontSize', 24)
ylabel('T_R [K]','FontSize', 24)
yticks([383 384 385 386 387])
grid on
figure(22)
subplot(2,2,1);
hold on
box on
plot(T(1:tp+N),x_record(1,1:tp+N)+xs(1),'b-','LineWidth',3)
plot(T(1:tp+N),x_open(1,1:tp+N),'r-','LineWidth',3)
axis([0 sim_window+N*dt 0.08 0.12])
set(gca,'fontsize',20)
xlabel('Time [min]','FontSize', 20)
ylabel('C_A [mol/liter]','FontSize', 20)
grid on
subplot(2,2,3);
hold on
box on
plot(T(1:tp+N),x_record(2,1:tp+N)+xs(2),'b-','LineWidth',3)
plot(T(1:tp+N),x_open(2,1:tp+N),'r-','LineWidth',3)
axis([0 sim_window+N*dt 382 387])
set(gca,'fontsize',20)
xlabel('Time [min]','FontSize', 20)
ylabel('T_R [K]','FontSize', 20)
grid on
figure(13)
subplot(2,1,1);
hold on
box on
plot(T(1:tp+N),x_record(1,1:tp+N)+xs(1),'b-','LineWidth',3)
% plot(T(1:tp+N),x_open(1,1:tp+N),'r-','LineWidth',3)
axis([0 sim_window+N*dt 0.08 0.11])
set(gca,'fontsize',20)
xlabel('Time (min)','FontSize', 20)
ylabel('C_A (mol/liter)','FontSize', 20)
grid on
subplot(2,1,2);
hold on
box on
plot(T(1:tp+N),x_record(2,1:tp+N)+xs(2),'b-','LineWidth',3)
% plot(T(1:tp+N),x_open(2,1:tp+N),'r-','LineWidth',3)
axis([0 sim_window+N*dt 383 387])
set(gca,'fontsize',20)
xlabel('Time (min)','FontSize', 20)
ylabel('T_R (K)','FontSize', 20)
grid on
figure(23)
subplot(2,1,1);
hold on
box on
plot(T(1:tp+N),x_record(1,1:tp+N)+xs(1),'b-','LineWidth',3)
plot(T(1:tp+N),x_open(1,1:tp+N),'r-','LineWidth',3)
axis([0 sim_window+N*dt 0.08 0.12])
set(gca,'fontsize',20)
xlabel('Time (min)','FontSize', 20)
ylabel('C_A (mol/liter)','FontSize', 20)
grid on
subplot(2,1,2);
hold on
box on
plot(T(1:tp+N),x_record(2,1:tp+N)+xs(2),'b-','LineWidth',3)
plot(T(1:tp+N),x_open(2,1:tp+N),'r-','LineWidth',3)
axis([0 sim_window+N*dt 382 387])
set(gca,'fontsize',20)
xlabel('Time (min)','FontSize', 20)
ylabel('T_R (K)','FontSize', 20)
grid on
figure(24)
hold on
box on
% plot(T(1:tp+N),x_record(1,1:tp+N)+xs(1),'b-','LineWidth',3)
plot(T(1:tp+N),x_open(1,1:tp+N),'r-','LineWidth',3)
axis([0 sim_window+N*dt 0.08 0.12])
yticks([0.08 0.09 0.10 0.11 0.12])
set(gca,'fontsize',20)
xlabel('Time [min]','FontSize', 20)
ylabel('C_A [mol/liter]','FontSize', 20)
grid on
figure(25)
hold on
box on
% plot(T(1:tp+N),x_record(2,1:tp+N)+xs(2),'b-','LineWidth',3)
plot(T(1:tp+N),x_open(2,1:tp+N),'r-','LineWidth',3)
axis([0 sim_window+N*dt 382 387])
yticks([382 383 384 385 386 387])
set(gca,'fontsize',20)
xlabel('Time [min]','FontSize', 20)
ylabel('T_R [K]','FontSize', 20)
grid on
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
1、资源内容:基于Matlab实现CarlemanMHE+MPC(源码+数据).rar 2、适用人群:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业或毕业设计中的部分功能,作为“参考资料”使用。 3、解压说明:本资源需要电脑端使用WinRAR、7zip等解压工具进行解压,没有解压工具的自行百度下载即可。 4、免责声明:本资源作为“参考资料”而不是“定制需求”,代码只能作为参考,不能完全复制照搬。不一定能够满足所有人的需求,需要有一定的基础能够看懂代码,能够自行调试代码并解决报错,能够自行添加功能修改代码。由于作者大厂工作较忙,不提供答疑服务,如不存在资源缺失问题概不负责,谢谢理解。
资源推荐
资源详情
资源评论
收起资源包目录
基于Matlab实现CarlemanMHE+MPC(源码+数据).rar (10个子文件)
基于Matlab实现CarlemanMHE+MPC(源码+数据)
estimate_cstr.m 643B
costf_mpc_cstr_loop.m 5KB
ode_feedback_system.m 310B
Carleman_mhe_mpc.m 8KB
control_cstr.m 567B
carleman_matrices.mat 643B
real_noise2.mat 1KB
ode_real_system.m 310B
ode_open_loop_system.m 324B
costf_mhe_cstr.m 3KB
共 10 条
- 1
资源评论
Matlab仿真实验室
- 粉丝: 2w+
- 资源: 2180
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功