How to add another scenario to my code?

조회 수: 1 (최근 30일)
Rebecca Reyes
Rebecca Reyes 2021년 10월 14일
댓글: Walter Roberson 2021년 10월 15일
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
Walter Roberson
Walter Roberson 2021년 10월 15일
The code I showed should work for nonnegative integer theta. It would need some adjustments for negative delay or non-integer delay

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by