Hi,
I have a function that solves the dynamic behavior of a reactor over time given certain input conditions using the ODE solver. However, I would like to be able to see what would happen if a step change in the input condition or some other variable is applied at a certain t. I believe Simulink can be used to determine the response to a step function, but I'm not sure how to pass my function to Simulink. For example, in my code below, the input condition is Tc. I would like to see the change if the variable q was changed from 150 to 100 at t = 20 if Tc is the same or if Tc was changed at t = 20.
Thanks for any help!
function ivp% Inputs
tval=0:0.01:20;Tc = [290; 300; 305; 310];% Differential Equation
Ca0=0.5; T0=350; Tc0 = 300;Int = [Ca0; T0];[t,Y1] = ode15s(@ode,tval,Int,[],Tc(1));% Plots
figure()plot(t,Y1(:,2),'r')xlabel('Time (min)'); ylabel('Reactor temperature (K)');legend('290K');figure()plot(t,Y1(:,1),'r')xlabel('Time (min)');ylabel('Reactant A concentration (mol/L)');legend('290K');endfunction [Dy] = ode(t,y,Tc)q=150; Cai=1; Ti=350; V=100; p=1000; C=0.239; H=5*10^4;ER=8750; k0=7.2*10^10; UA=5*10^4; % y(1) is Ca Dy(1) is deriv
% y(2) is T Dy(2) is deriv
Dy = zeros(2,1);Dy(1) = q/V*(Cai-y(1))-k0*exp(-ER/y(2))*y(1);Dy(2) = q/V*(Ti-y(2))+H/(p*C)*k0*exp(-ER/y(2))*y(1)+UA/(V*p*C)*(Tc-y(2));end
Best Answer