1.) (D^2+1)=cosx
2.) y"-3y'-4y=16x-50cos2x
The general solutions to these take the form of the general solution to the corresponding homogeneous equation plus a particular integral of the non homogeneous equation.
I will presume that you know how to solve the homogeneous equations $\displaystyle y''+y=0$ (which is what I presume your first equation id supposed to be) and $\displaystyle y''-3y'-4y=0$
For the first, as $\displaystyle \cos(x)$ is a solution of the homogeneous equation we try a trial solution $\displaystyle (Ax+B)\cos(x) + (Cx+D)\sin(x)$
For the second we try a trial solution of the form $\displaystyle (A x+ B) + C \cos(2x)+D \sin(2x) $
RonL