MATLAB: Using dsolve function to solve this equation

dsolveSymbolic Math Toolbox

Question: Use dsolve to solve this equation: y' − y = 2 sin(t).
Below is the code I used but I do not think I am getting the right answer.
syms y(t);
y = dsolve(diff(y) == 2*sin(t)+y)

Best Answer

For grins, I decided to see what a Laplace transform solution would produce:
syms s y(t) y0 Y
Lsin = laplace(sin(t));
Eqn1 = Y*(s-1) == Lsin;
Eqn2 = solve(Eqn1, Y);
Eqn3 = ilaplace(partfrac(Eqn2))
Eqn4 = simplify(Eqn3, 'steps',10)
Eqn3 =
exp(t)/2 - cos(t)/2 - sin(t)/2
Eqn4 =
exp(t)/2 - (2^(1/2)*sin(t + pi/4))/2