Given differential equation is of the form dxdy+Py=Q where P=−1 and Q=cosx
Therefore, IF=e∫−1dx=e−x
On multiplying both sides of equation by IF, we get e−xdxdy−e−xy=e−xcosx
or dxdy(ye−x)=e−xcosx
On integrating both sides w.r.t. x, we get ye−x=∫e−xcosxdx+C.....(i)
Let I=∫e−xcosxdx =cosx(−1e−x)−∫(−sinx)(−e−x)dx =−cosxe−x−∫sinxe−xdx =−cosxe−x−[sinx(−e−x)−∫cosx(−e−x)dx] =−cosxe−x+sinx⋅e−x−∫cosx⋅e−xdx ⇒I=−e−xcosx+sinxe−x−I ⇒2I=(sinx−cosx)e−x ⇒I=2(sinx−cosx)e−x
Substituting the value of I in Eq. (i), we get ye−x=(2sinx−cosx)e−x+C ⇒y=(2sinx−cosx)+Cex
which is the general solution of the given differential equation.