Solving a higher order differential equation with ode45 (mass-spring-damper system)

PHOTO EMBED

Sat Mar 20 2021 07:39:08 GMT+0000 (Coordinated Universal Time)

Saved by @FlorianC #matlab

# where x is a vector with its first entry x(1) corresponding to the position of a given mass and its second entry x(2) correpsonding to the velocity
dxdt = @(t,x) [x(2); -x(2)-x(1)];
tLim = [0,10];
x0 = [0,1];

[tSol,xSol] = ode45(dxdt, tLim, x0);

plot(tSol, xSol(:,1));
hold on
plot(tSol, xSol(:,2));
content_copyCOPY