time dependent constant to solve 1st order ODE via ode45
Show older comments
I am able to solve my diff eq with ode45, however, I need one of my constants to change value once the output reaches a certain value. For context, this is to solve for the temperature in a simple energy balance for a stirred tank.
I need Tw to change to 15C once T reaches 34.7C
Code is as follows:
function diffeqs= ode_sys(t,var)
T=var(1);
dH=1200;
M=2300;
cp=4.2;
F=0.125;
Tw=20;
Tin=25;
U=3.4;
A=2.8;
diffeqs(1,1)=((F*cp*(Tin-T))+(F*cp*(Tin-T))+(F*dH)-(U*A*(T-Tw)))/(M*cp)
end
***NEW SCRIPT***
tspan=[0:9000];
IC=(25); %initial Temp
[t,y]=ode45(@ode_sys,tspan,IC);
figure
plot(t,y,'-')
title('Temperature in CSTR')
xlabel('time/s')
ylabel('Temperature/C')
1 Comment
Merwyn Pinto
on 28 Jul 2020
Edited: Merwyn Pinto
on 28 Jul 2020
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!