So here is my code: sys(m,
A0= 0.03;
m0= [0,0.1,0.3];
p0= [0.1,0.4,0.5];
mdot(1) = -m0(1) + 60*(5-A0)/(1+p0(1)^2) +A0;
mdot(2) = -m0(2) + 60*(5-A0)/(1+p0(2)^2) +A0;
mdot(3) = -m0(3) + 60*(5-A0)/(1+p0(3)^2) +A0;
mdot=[mdot(1),mdot(2),mdot(3)];
pdot(1)=-0.2*(p0(1)-m0(1));
pdot(2)=-0.2*(p0(2)-m0(2));
pdot(3)=-0.2*(p0(3)-m0(3));
pdot=[pdot(1),pdot(2),pdot(3)];
t0=0;
tspan=[0,800];
[y,t]=ode45(@odefun,tspan, m0, options);
plot(t,y);
Been staring at it for hours but it wont run.
?? ?

 Accepted Answer

Stephan
Stephan on 1 Mar 2019
Edited: Stephan on 1 Mar 2019
Hi,
try
A0= 0.03;
m0= [0,0.1,0.3];
p0= [0.1,0.4,0.5];
tspan=[0,800];
[t,y]=ode45(@(t,y)odefun(t,y,A0,m0,p0),tspan, [m0 p0]);
plot(t,y);
function y = odefun(t,y,A0,m0,p0)
mdot(1) = -m0(1) + 60*(5-A0)/(1+p0(1)^2) +A0;
mdot(2) = -m0(2) + 60*(5-A0)/(1+p0(2)^2) +A0;
mdot(3) = -m0(3) + 60*(5-A0)/(1+p0(3)^2) +A0;
mdot=[mdot(1),mdot(2),mdot(3)]';
pdot(1)=-0.2*(p0(1)-m0(1));
pdot(2)=-0.2*(p0(2)-m0(2));
pdot(3)=-0.2*(p0(3)-m0(3));
pdot=[pdot(1),pdot(2),pdot(3)]';
y = [mdot;pdot];
end
Best regards
Stephan

2 Comments

Hi Stephan, thanks for your response, however, this returns a graph of multiple different lines, but I am looking for a single function, what have I misunderstood.
Stephan
Stephan on 2 Mar 2019
Edited: Stephan on 2 Mar 2019
y contains all 3 mdot and all 3 pdot solutions in his 6 columns. if you want to plot mdot1 use:
plot(t,y(:,1))
pdot2 would be:
plot(t,y(:,5))

Sign in to comment.

More Answers (1)

Tags

Community Treasure Hunt

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

Start Hunting!