Solving ODE system on matlab

I am trying to solve a system ODEs with no specific initial values and I am not sure how to go about it. Here is what I have so far. I'm trying to use ODE45 and solve with several initial conditions to have an idea of how the system ( with 3 equations) behaves. Thank you in advance!!
function Untitled
t= 1:0.5:50;
a=.004;
b=0.5;
c=1;
initial=[a b c];
[~,y]= ode45(@model,t,initial)
plot3(y(1),y(2),y(3));
end
function y=model(~,y)
y=zeros(3,1);
dy(1)=y(1)*(1-y(1)-2*y(2)-y(3)/2);
dy(2)=y(2)*(1-y(2)-2*y(3)-y(1)/2);
dy(3)=y(3)*(1-y(3)-2*y(1)-y(2)/2);
end

Risposte (1)

James Tursa
James Tursa il 21 Apr 2016
Your plot3 only picks off three points to plot ... it does not plot all of the results. Also, your model derivative function sets y to 0 and then returns that, rather than returning the dy you calculate. So with those changes maybe you can use this:
function Untitled
t= 1:0.5:50;
a=.004;
b=0.5;
c=1;
initial=[a b c];
[~,y]= ode45(@model,t,initial);
figure; plot3(y(:,1),y(:,2),y(:,3));grid on
figure; plot(t,y(:,1),t,y(:,2),t,y(:,3));grid on
end
function dy=model(~,y)
dy=zeros(3,1);
dy(1)=y(1)*(1-y(1)-2*y(2)-y(3)/2);
dy(2)=y(2)*(1-y(2)-2*y(3)-y(1)/2);
dy(3)=y(3)*(1-y(3)-2*y(1)-y(2)/2);
end

Questa domanda è chiusa.

Richiesto:

il 21 Apr 2016

Chiuso:

il 20 Ago 2021

Community Treasure Hunt

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

Start Hunting!

Translated by