How to add another scenario to my code?

2 Ansichten (letzte 30 Tage)
Rebecca Reyes
Rebecca Reyes am 14 Okt. 2021
Kommentiert: Walter Roberson am 15 Okt. 2021
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 Kommentare
Walter Roberson
Walter Roberson am 15 Okt. 2021
The code I showed should work for nonnegative integer theta. It would need some adjustments for negative delay or non-integer delay

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by