MATLAB: Help solving 3 ODEs

differential equationsMATLABode45

Best 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