MATLAB: How to solve system of two 2nd order differential equations (in quater-car model) numerically

differential equation

I have a problem as shown in figure below,
which is described be system of 2nd-order differential equations
Can you please help me with the code to solve that system (mu,ms,ku,ks,cs are know; y is road surface, which is a vector generated by a sine function)
Thank you very much!

Best Answer

Here I will show a simple example of two 2nd order ODEs. You can apply it to your equations. Consider
You can convert these ODEs to a system of 4 first-order ODE
You can then solve it like this
tspan = [0 10];
ic = [1; 0; 2; 0];
[t, X] = ode45(@odeFun, tspan, ic);
x1 = X(:,1);
x2 = X(:,2);
y1 = X(:,3);
y2 = X(:,4);
plot(t, X);
legend({'$x$', '$\dot{x}$', '$y$', '$\dot{y}$'}, 'FontSize', 16, 'Interpreter', 'latex');
function dXdt = odeFun(t, X)
% Here X(1)=x_1, X(2)=x_2, X(3)=y_1, X(4)=y_2
x1 = X(1);
x2 = X(2);
y1 = X(3);
y2 = X(4);
dx1dt = x2;
dx2dt = -2*x2 + y2 - x1;
dy1dt = y2;
dy2dt = -3*y2 + x2 - y1;
dXdt = [dx1dt; dx2dt; dy1dt; dy2dt];
end
Related Question