How to add another scenario to my code?
2 views (last 30 days)
Show older comments
I am struggling to include a scenario to my code.
This is the original code
clear; clc;
y0=[5, 120, 120]; %input problems specification
t=linspace(0,100,101); %Generate the value of t sing linspace
%Call ode45 and store solution in soln
[t, y]=ode45(@f,t,y0,odeset('RelTol', 1.E-6, 'AbsTol', 1.E-6, 'PelTol));
% y1=deval(t,soln)); %Retieve value of y(1) from soln Scenario 2
% y2=deval(t,soln)); %Scenario 1
plot(t,y(:,2),'r',t,y(:,3),'b','Linewidth',2);
xlabel ('t (min)'); ylabel('Outlet Temp (deg C)');
legend('Scenario 2', 'Scenario 1');
grid on; %Add grid to plot
title('ode45 S2'); %Add title to plot
%
%User specified function for dydt for each dependent variable
%
function dydt=f(t,y)
V=30; p=62.4; Tin=60; F=5; Q=1000; tauTs=1.25; tauTv=.17;
dydt(1)=(5-y(1))/tauTv;
dydt(2)=((p*F*(1))*(Tin-y(2))+Q)/(p*V*(1));
dydt(3)=(y(2)-y(3))/tauTs;
dydt=dydt'
it gives me two lines in one graph. I'd like to add another scenario to it. This is the code I wish to incorporate somehow
s3=[]; theta=1;
for j=1:length(s2)
if (t-theta)<=0
s3(j)=s2(0)
else
s3(j)=s2(t-theta)
end
end
4 Comments
Walter Roberson
on 15 Oct 2021
The code I showed should work for nonnegative integer theta. It would need some adjustments for negative delay or non-integer delay
Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!