Initial Conditions aren't being used/applied for Plotting System of Differential Equations
조회 수: 1 (최근 30일)
이전 댓글 표시
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/171279/image.png)
And, this is the graph MatLab is returning.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/171280/image.png)
%
댓글 수: 0
답변 (1개)
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
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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!