MATLAB: Matlab Symbolic Maths – How to insert ¨y(t) +˙y(t) +y(t)= f(t) equation in symbolic Maths

controlMATLABsymbolic mathstheory

I have the above equation which is y''(t) + y'(t) + y(t) =f(t). How can I find the impulse response of this LTI system using symbolic maths? My main concern is how I can put in derviates using syms keyword. Also after I put in this equation ¨y(t) +˙y(t) +y(t)= f(t), I need to find the Laplace transform for the same.
Thanks in advance.

Best Answer

Although there are easier ways to solve this equation in MATLAB (e.g., using dsolve()), you mentioned Laplace transform in your question. The following code shows how to use it Laplace, and inverse Laplace transform to find the impulse response.
syms y(t) f(t) Ly
dy = diff(y, 1);
ddy = diff(y, 2);
ic = [0 0]; % initial condition: y(0)=0, y'(0)=0
eq = ddy + dy + y == f; % differential equation
eq_impulse = subs(eq, f(t), dirac(t)); % substitude f(t)=dirac(t) i.e., impulse input
eq_laplace = laplace(eq_impulse); % laplace transform of equation
eq_laplace = subs(eq_laplace, [y(0) dy(0) laplace(y)], [ic Ly]); % substituting initial conditions
Ly = solve(eq_laplace, Ly); % seperating the laplace(y) term
y(t) = ilaplace(Ly); % inverse laplace transform
fplot(y, [0 10]); % plot from t=0 to t=10