Inexact Differential Equation Question $$\frac {dy}{dx}\cos x +y=\cos^{2}x$$
My method:
$A = y-\cos^{2}x$ and $B = cosx$
$\frac{\partial A}{\partial y} = 1$ and $\frac{\partial B}{\partial x} = -sinx$
$\frac{\frac{\partial A}{\partial y} -\frac{\partial B}{\partial x}}{B} = \frac{1+sinx}{cosx}$
$\int\frac{(1+\sin x)}{\cos x} dx = \ln|\frac{\sec x +\tan x}{\cos x}|$
So the Integrating Factor turns out to be $\frac{\sec x +\tan x}{\cos x}$
$$(\frac{\sec x +\tan x}{\cos x})\cos x dy = -y(\frac{\sec x +\tan x}{\cos x})dx+\cos^{2}x(\frac{\sec x +\tan x}{\cos x})dx$$
$$(\sec x +\tan x)dy = -y(\frac{\sec x +\tan x}{\cos x})dx+\cos x(\sec x +\tan x)dx$$
Integrating both sides
$$y(\sec x +\tan x)= -y(\tan x+\sec x)+x-\cos x+C$$
The final result I get is $y = \frac{x-\cos x}{2(\sec x + \tan x)} + C$
The solution manual does it like
$$\frac {dy}{dx} +y\sec x=\cos x$$
So the Integrating Factor is $ \sec x + \tan x$
The final result when we use this integrating factor is $y = \frac{x-\cos x}{(\sec x + \tan x)} + C$
Is there something wrong with my method?
 A: The problem isn't with your integrating factor, you actually get to the same equation that they get to with their integrating factor. The issue comes in when you start integrating.
Remember that we're taking total derivatives, not partials, and $y$ is a function of $x$. So when you evaluate $\int -y(\sec^2x+\sec x \tan x) dx$, you can't pull the $y$ out as a constant because it's not constant with respect to $x$.
One way to remedy this is with integration by parts: $$\int -y d(\sec x + \tan x) = -y(\sec x + \tan x) + \int \sec x + \tan x dy$$ Notice that the new integral we get should cancel out with the integral on the left-hand side. This is why your answer is off by a factor of $2$.
To avoid this in the future, I recommend that instead of breaking up the left-hand side after multiplying by the integration factor as you did here, simply rewrite the entire left-hand side as $\dfrac{d}{dx}[(\sec x + \tan x) y]$, then the integral on the left-hand side is simply $(\sec x + \tan x)y + C$. This is sort of the main idea behind the integration factor method, that you can rewrite the equation in the form $\dfrac{d}{dx}[f(x)y] = g(x)$, so I recommend you take advantage of it.
Also, be careful with your constants: you give the correct answer as $y = \dfrac{x - \cos{x}}{\tan x + \sec x} + C$, but it should be $y = \dfrac{x - \cos{x} + C}{\tan x + \sec x}$, because the entire right-hand side should be divided by $\tan x + \sec x$.
Hope this helps!
