フィルターのクリア

Initial Conditions aren't being used/applied for Plotting System of Differential Equations

1 回表示 (過去 30 日間)
Daniel Jovin
Daniel Jovin 2018 年 3 月 15 日
コメント済み: Torsten 2018 年 3 月 15 日
I'm applying a previous code I got to work for a system of three differential equations to a system of four differential equations. MatLab isn't returning any errors when I run my code, but the plots don't start at the initial conditions I set for two of my four differential equations/functions. I'm attaching photos of the system of differential equations and the resulting plot from my code. My y(4) function, B(t) is meant to be 30000 at B(0), and my y(2) function, C(t), is meant to be 300 at C(0). But, the plot in MatLab seems to return a graph where B(0) and C(0) are both zero for some reason.
I would appreciate help understanding how to have my initial conditions translate to the graph.
Here is my code for the system/plot
%
function myODE2
s=20;
r=100;
k1=5;
md=0.2;
pc=1.8;
a=60;
k2=1000;
k3=500;
cd=0.5;
pa=3;
ad=0.5;
g=50;
bd=1.2;
y0=[10000,300,100,30000];
tspan = [0,10];
options = odeset('AbsTol',1e-10,'RelTol',1e-10);
[t,y]= ode45(@Chowattempt6,tspan,y0,options,s,r,k1,md,pc,a,k2,k3,cd,pa,ad,g,bd);
figure
yyaxis left
hold on
plot(t,y(:,1),'r',t,y(:,4),'b')
ylabel('Bacteria and Macrophage Population')
yyaxis right
plot(t,y(:,3),'g',t,y(:,2),'k')
ylabel('Cytokine Concentration')
hold off
xlabel('time (minutes)')
grid
legend('M(t)','C(t)','A(t)','B(t)')
title('Biofilm Determinants')
end
function dy = Chowattempt6(t,y,s,r,k1,md,pc,a,k2,k3,cd,pa,ad,g,bd)
dy = zeros(4,1);
dy(1) = s+((r*y(2))/(1+k1*y(2)))-md*y(1);
dy(2) = pc*y(1)*y(4)+((y(1)*y(2)*a)/((1+k2*y(2))*(1+k3*y(3))))-cd*y(2);
dy(3) = pa*y(2)*y(1)-ad*y(3);
dy(4) = g*y(4)-bd*y(1)*y(4);
end
Here is my system of equations I am trying to use
And, this is the graph MatLab is returning.
%

回答 (1 件)

Torsten
Torsten 2018 年 3 月 15 日
[t,y]= ode45(@(t,y)Chowattempt6(t,y,s,r,k1,md,pc,a,k2,k3,cd,pa,ad,g,bd),tspan,y0,options);
Best wishes
Torsten.
  4 件のコメント
Daniel Jovin
Daniel Jovin 2018 年 3 月 15 日
I feel like you misunderstood my issue. B is y(4), it's initial value is 30000, so I think it should be visible at least initially especially when M, y(1) is 10000 at t=0. y(1) and y(4) are on different axes than y(2) and y(3).
Also, C, y(2), starts at 300 while A, y(3), starts at 100. A(t) is visible on the graph even at t=0 where A(0) = 100, so I think C(t) should be visible at t=0 where C(0) = 300. So, I do't think their values are too small to be resolved.
However, I plotted my system on tspan = [0 0.001], and it showed that B(t), y(4), seems to immediately decrease to zero, and C(t), y(2), seems to initially increase and then go to zero.
How would I print the values of y(1), y(2), y(3), and/or y(4) at a certain t value?
Torsten
Torsten 2018 年 3 月 15 日
Don't plot them - print them to screen after the call to ode45.
Just type
y(1,1)
y(1,2)
y(1,3)
y(1,4)
to see the initial values at t=0.
Best wishes
Torsten.

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

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by