MATLAB: How to solve a system of second order nonlinear differential equations

differentialMATLABnonlinearode45

Hello, I am having troubles solving a system of second order nonlinear equations in MATALB
Here is the equations:
1.01 * (x'') + 0.025 * (θ'') * cos(θ) – 0.025 * (θ')^2 * sin(θ) + 200 * x^3 + 20 * (x') = 0
(x'') * cos(θ) + 2.5 * (θ'') + 9.8 * sin(θ) = 0

Best Answer

If you have the symbolic toolbox, It will make things easier as shown in following code
syms x(t) theta(t)
d1x = diff(x,1);
d2x = diff(x,2);
d1theta = diff(theta,1);
d2theta = diff(theta,2);
eq1 = 1.01*d2x + 0.025*d2theta*cos(theta) - 0.025*d1theta^2*sin(theta) + 200*x^3 + 20*d1x == 0;
eq2 = d2x*cos(theta) + 2.5*d2theta + 9.8 * sin(theta) == 0;
[F, S] = odeToVectorField(eq1, eq2);
odeFun = matlabFunction(F, 'Vars', {t, 'Y'});
[t, y] = ode45(odeFun, [0 10], [1; 0; 0.1; 0]);
plot(t, y);
legend({'$\theta$', '$\dot{\theta}$', '$x$', '$\dot{x}$'}, ...
'FontSize', 16, ...
'Interpreter', 'latex', ...
'Location', 'best');
Related Question