Answer
See below
Work Step by Step
We are given that $y'-3y=f(t)$
and $y(0)=2$
Let's decide $f(t)=\sin t(1-u_1(t))+u_1(t)\\
=\sin t+(1-\sin t)u_1(t)$
We take the Laplace transform of both sides of the differential
equation to obtain:
$[sY(s)-y(0)]-3Y(s)=\frac{1}{s^2+1}+e^{-s}(\frac{1}{s}-\frac{1}{s^2+1})$
Substituting in the given initial values and rearranging terms yields
$Y(s)(s-3)-2=\frac{1}{s^2+1}+e^{-s}(\frac{1}{s}-\frac{1}{s^2+1})\\
Y(s)(s-3)=\frac{1}{s^2+1}+e^{-s}(\frac{1}{s}-\frac{1}{s^2+1})+2$
Thus, we have solved for the Laplace transform of $y(t)$. To find y itself, we must take the inverse Laplace transform. We first decompose the right-hand side into partial fractions to obtain:
$Y(s)=\frac{1}{(s^2+1)(s-3)}+\frac{2}{s-3}+e^{-s}[\frac{1}{s(s-3)}-\frac{1}{(s-3)(s^2+1)}]\\
=\frac{1}{10(s-3)}-\frac{s}{10(s^2+1)}-\frac{3}{10(s^2+1)}+e^{-s}[\frac{s-2}{3s}-(\frac{1}{10(s-3)}-\frac{s+3}{10(s^2+1})]$
Now,$f(t)= L^{-1}[\frac{1}{10(s-3)}-\frac{s}{10(s^2+1)}-\frac{3}{10(s^2+1)}+e^{-s}[\frac{s-2}{3s}-(\frac{1}{10(s-3)}-\frac{s+3}{10(s^2+1})]]\\
=\frac{1}{10}e^{3t}-\frac{1}{10}\cos t-\frac{3}{10}\sin t+2e^{3t}+\frac{1}{3}e^{3(t-1)}u_1(t)+[\frac{1}{10}e^{3(t-1)}-\frac{1}{10}\cos (t-1)-\frac{3}{10}\sin (t-1)]u_1(t)$