MATLAB: How do you solve 3.5d^2x/dt^2 + 4dx/dt + 5x = 2.5 3e^-2t with matlab

laplaceode

I am trying to solve a differential equation with laplace transform. The equation is
Md^2/dx^2+Cdx/dt+kx=f+f2e^-2t
for t>0. C=4,k=5,f2=3,M=3.5,f=2.5 and initial conditions are x(t=0)=1, dx/dt(t=0)=1
I just do not know how to type this into MATLAB. Please help. Thank you.

Best Answer

syms x(t)
C = 4; k = 5; f2 = 3; M = 3.5; f = 2.5
eqn = M*(diff(x(t), t, t))+C*(diff(x(t), t))+k*x(t) == f+2*f*exp(-2*t);
sol = dsolve(eqn, x(0) == 1, subs(diff(x(t), t), t, 0) == 1);
simplify(sol, 'step', 20)