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

differential equationsmatlab functionnonlinearode45Symbolic Math Toolbox

Joints of this two link system have consisted with springs, and whole the system is rotating around the x-axis.
I have tried to solve this by using ode45 with odeToVectorField. When I apply initial condition it dosen't give any solution.
How can this issue be solved?
eqns = [eq1_N1 eq2_N2 eq3_N3];
[V,S] = odeToVectorField(eq1_N1,eq2_N2,eq3_N3); % Reduce the second order of diffrential equations to fist-order
M = matlabFunction(V,'vars',{'t','Y'}) % Generate a MATLAB function from this system of first order diffrential equations
% Solve the System of First-Order ODEs
interval = [0 20];
Init = [0 0 0 0 0 0]; % theta_1(0) = 0, Dtheta_1(0) = 0, theta_2(0) = 0, Dtheta_2(0) = 0, theta_3(0) = 0, Dtheta_3(0) = 0,
ySol = ode45(M,interval,Init)
tValues = linspace (0,20,100)
yValues = deval(ySol,tValues,1)
plot(tValues,yValues);

Best Answer

Substitute these for what you currently have:
% Solve the System of First-Order ODEs
interval = linspace (0,20,250);
Init = [0 0 0 0 0 0]+1E-15; % theta_1(0) = 0, Dtheta_1(0) = 0, theta_2(0) = 0, Dtheta_2(0) = 0, theta_3(0) = 0, Dtheta_3(0) = 0,
[t,y] = ode45(M,interval,Init);
% tValues = linspace (0,20,100)
% yValues = deval(ySol,tValues,1)
sp = size(y,2);
figure
for k = 1:sp
subplot(sp,1,k)
plot(t, y(:,k))
title(string(S(k)))
grid
end
op = get(gcf, 'OuterPosition');
set(gcf, 'OuterPosition', op+[0 -500 0 500])