MATLAB Answers

Kurt
0

Help solving 3 ODEs

Asked by Kurt
on 22 Oct 2018
Latest activity Commented on by Kurt
on 22 Oct 2018

I'm trying to solve these 3 ODEs with ODE45.

d(xA)/d(v)=(0.2*(0.6^2)*((1-(0.375*xA)))*(((5/3)-xA)/(1-0.375*xA))))/(3);
d(xB)/d(v)=(0.2*(0.6^2)*((1-xB)/(1-(0*xB)))*(((5/3)-xB)/(1-0*xB)))/(3);
d(xC)/d(v)=(0.2*(0.6^2)*((1-xC)/(1-(0.75*xC)))*(((5/3)-xC)/(1-0.75*xC)))/(3);
v(f)=47
v(0)=0
xA(0)=0
xB(0)=0
xC(0)=0

What do I do?

  0 Comments

Sign in to comment.

Products


Release

R2018b

1 Answer

Stephan
Answer by Stephan
on 22 Oct 2018
Edited by Stephan
on 22 Oct 2018
 Accepted Answer

Hi,
try this:
syms xA(v) xB(v) xC(v)
eqn1 = diff(xA, v) == (0.2*(0.6^2)*((1-(0.375*xA)))*(((5/3)-xA)/(1-0.375*xA)))/(3);
eqn2 = diff(xB, v) == (0.2*(0.6^2)*((1-xB)/(1-(0*xB)))*(((5/3)-xB)/(1-0*xB)))/(3);
eqn3 = diff(xC, v) == (0.2*(0.6^2)*((1-xC)/(1-(0.75*xC)))*(((5/3)-xC)/(1-0.75*xC)))/(3);
[odes, vars] = odeToVectorField(eqn1, eqn2, eqn3);
fun = matlabFunction(odes,'Vars',{'t','Y'});
x0 = [0 0 0];
tspan = [0 47];
[t, sol] = ode45(fun,tspan,x0);
xA = sol(:,2);
xB = sol(:,1);
xC = sol(:,3);
plot(t,xA,t,xB,t,xC)
legend('xA','xB','xC','Location','southeast')
Note that for some reasons Matlab changes the order of the variables, so that xA = Y(2) and xB = Y(1):
odes =
((Y[1] - 5/3)*((9*Y[1])/125 - 9/125))/3
-((Y[2] - 5/3)*((27*Y[2])/1000 - 9/125))/(3*((3*Y[2])/8 - 1))
(3*(Y[3] - 1)*(Y[3] - 5/3))/(125*((3*Y[3])/4 - 1)^2)
vars =
xB
xA
xC
- dont ask me why this happens, but you have to take it into account. The result is:
.
Best regards
Stephan

  1 Comment

Kurt
on 22 Oct 2018
Thanks a lot this helps!

Sign in to comment.