Trying to graph two ode45 functions on a single plot

Hello I am working with this windkessel model with different parameters
%% Defining Physiological Parameters
clc,clear;
% Defining parameters for 2 element model
R = 1.08; %systemic peripheral resistance (mmHg/cm^3/sec)
C = 1.1; %systemic arterial compliance in (cm^3/mmHg)
% Heart rate and cycle times
HR = 60; %beats per minute
Tc = 60/HR; %Length of one cardiac cycle (in seconds)
Ts = (2/5)*Tc; %Length of systole is 40% of the cardiac cycle
InCond = 80; %pressure during diastole (80mmHg)
Timespan=[0 Tc];
twoelemmodel = @(t,P) (1/C).*(QF(t,HR)-(P./R));
[t,P] = ode45(twoelemmodel,Timespan,InCond);
plot(t,P,'r')
title('2 Element Windkessel Model (Physiological Parameters)');
xlabel('time (in seconds)');
ylabel('Pressure (in mmHg)');
%% %% Defining Theoretical Parameters
% Defining parameters for 2 element model
R = 1.3; %systemic peripheral resistance (mmHg/cm^3/sec)
C = 1.1; %systemic arterial compliance in (cm^3/mmHg)
% Heart rate and cycle times
HR = 120; %beats per minute
Tc = 60/HR; %Length of one cardiac cycle (in seconds)
Ts = (2/5)*Tc; %Length of systole is 40% of the cardiac cycle
InCond = 80; %pressure during diastole (80mmHg)
Timespan=[0 Tc];
twoelemmodel = @(t,P) (1/C).*(QF(t,HR)-(P./R));
[t,P] = ode45(twoelemmodel,Timespan,InCond);
plot(t,P,'b')
title('2 Element Windkessel Model (Theoretical Parameters)');
xlabel('time (in seconds)');
ylabel('Pressure (in mmHg)');
Functions I am using:
% Functions
function Qout = QF(t,HR)
HR = 60;%Heart Rate in beats per minute
Tc = 60/HR; %Length of one cardiac cycle (in seconds)
Ts =(2/5)*Tc; %Length of systole is 40% of the cardiac cycle
if HR == 60
Qo = 260;
else
Qo = 520;
end
if t > Ts
Qo = 0;
end
Qout = Qo.*sin((2.*pi.*t/Tc));
function dqdt = dQf(t,HR)
Tc = 60/HR; %Length of one cardiac cycle (in seconds)
Ts = (2/5)*Tc; %Length of systole is 40% of the cardiac cycle
if HR == 60
Qo = 260;
else
Qo = 520;
end
if t > Ts
Qo = 0;
end
dqdt = (2.*pi/Tc).*Qo.*cos((2.*pi.*t)/Tc);
I can't seem to get the two grpahs to plot together.
Hold on functions seem to work, but the plots seem identical.
Any idea?

 採用された回答

Star Strider
Star Strider 2019 年 4 月 27 日

0 投票

For the first integration, save the outputs as:
[t{1},P{1}] = ode45(twoelemmodel,Timespan,InCond);
and the second as:
[t{2},P{2}] = ode45(twoelemmodel,Timespan,InCond);
and delete the existing plot calls, then plot the integration results as:
figure
plot(t{1}, P{1})
hold on
plot(t{2}, P{2})
hold off
grid
legend('Physiological Parameters', 'Theoretical Parameters')
title('2 Element Windkessel Model')
xlabel('time (in seconds)');
ylabel('Pressure (in mmHg)');
See the documentation on the hold (link) function for details.

1 件のコメント

Walter Roberson
Walter Roberson 2019 年 4 月 27 日
Or just
plot(t{1}, P{1}, 'r', t{2}, P{2}, 'b')

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

製品

質問済み:

2019 年 4 月 27 日

コメント済み:

2019 年 4 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by