MATLAB: How to write the code for open luup nd closed luup

closed looplabopen loop

To simulate the open loop and closed loop dynamic behavior of STHE

Best Answer

The answer for open luup is :-
clc
close all
clear all
h = 0.5; %in minutes
run_count = 201; %time count
%FIXED PARAMETERS
cp = 1; %cal/gm C

rho = 1e6; %gm/cubic meters

cpc = 1; %cal/gm C
rhoc = 1e6; %gm/cubic meters
a = 1.41e5;
b = 0.5;
Tcs = 25;
%VARYING PARAMETERS
v = 3.5; %cubic meters
fs = 0.085; %cubic meters/min

fcs = 0.44; %cubic meters/min
Ths= 150;
alp = fs/v;
beta1 = a*fcs^(b+1)/(rho*cp*v);
beta2 = a*fcs^b/(2*rhoc*cpc);
beta = beta1/(fcs + beta2);
Ts = (alp*Ths + beta*Tcs)/(alp + beta);
Tc = Tcs; %constant
Th = Ths*ones(run_count,1); %disturbance

f = fs*ones(run_count,1); %disturbance
fc = fcs*ones(run_count,1); %manipulated variable
t = zeros(run_count,1);
T = Ts*ones(run_count,1);
noise_std = 0.07;
Tm = zeros(run_count,1);
Tm(1) = T(1) + noise_std*randn;
%introduction of disturbance
n = input('Specify the variable for introducing step change. \n Enter 1 for coolant flow rate. \n Enter 2 for inlet stream temperature.\n');
step_time = 21;
if n == 1
delta_fc = 0.1*fcs; % introducing +10% change in flow rate
fc(step_time:end) = delta_fc + fc(step_time:end);
else
delta_t = +10; %introducing a +10 deg. C change in inlet temperature
Th(step_time:end) = Th(step_time:end) + delta_t;
end
for k = 1:run_count-1
alp_ = f(k)/v;
beta1_ = a*fc(k)^(b+1)/(rho*cp*v);
beta2_ = a*fc(k)^b/(2*rhoc*cpc);
beta_ = beta1_/(fc(k) + beta2_);
T(k+1) = T(k) + h*[alp_*(Th(k) - T(k)) - beta_*(T(k) - Tc)];
Tm(k+1) = T(k+1) + noise_std*randn;
t(k+1)=k*0.5;
end
set(0,'DefaultLineLineWidth',2)
set(0,'DefaultaxesLineWidth',2)
set(0,'DefaultaxesFontSize',16)
set(0,'DefaultTextFontSize',16)
set(0,'DefaultaxesFontName','arial')
figure(1), plot(t, T,'b', t, Tm, 'g',t, Ts*ones(run_count,1),'r'), grid;
xlabel('Time (min)')
ylabel('STHE Temperature (deg C)')
title('Controlled Output (T)')
legend('True Temperature','Measured Temperature','Initial S.S. Temperature')
figure(2), stairs(t, fc), grid;
xlabel('Time (min)')
ylabel('Coolant Flow (cubic meters/min)')
title('Manipulated Input (F_c)')
figure(3), stairs(t, Th), grid;
xlabel('Time (min)')
ylabel('Inlet Stream Temperature (deg C)')
title('Disturbance (T_h)')
diff = [mean(Tm(end-10:end))-mean(Tm(1:10))];
delta = 0.63*diff*ones(run_count,1);
figure(4), plot(t, Tm - Ts,'b' ,t, delta,'r'), grid;
xlabel('Time (min)')
ylabel('Deviation STHE Temperature (deg C)')
title('Deviation Controlled Output (T)')
legend('Measured Output','63.2% of Change in Output')
figure(5), stairs(t, fc-fcs), grid;
xlabel('Time (min)')
ylabel('Deviation Coolant Flow (cubic meters/min)')
title('Deviation Manipulated Input (Fc)')
figure(6), stairs(t, Th - Ths), grid;
xlabel('Time (min)')
ylabel('Deviation Inlet Temperature (deg C)')
title('Deviation Disturbance (T)')
clc
if n == 1
K_mani = diff/delta_fc
else
K_dist = diff/delta_t
end