Find all $f(x)$ so that $[y(x)]^2\cos x + y(x)f(x)y'(x)=0$ is exact Finde all functions $f(x)$, so that the ODE is exact...
$$[y(x)]^2\cos x + y(x)f(x)y'(x)=0$$
First I rewrote the ODE slightly...
\begin{align*}
    &[y(x)]^2\cos x + y(x)f(x)y'(x)=0 \\
    \Longrightarrow \quad & [y(x)]^2\cos x + y(x)f(x)\frac{dy}{dx}=0 \\
    \Longrightarrow \quad & ([y(x)]^2\cos x)dx + y(x)f(x)dy=0 \\
\end{align*}
Then I identified $P$ and $Q$...
\begin{align*}
    &P_x(x,y) = [y(x)]^2\cos x\\
    &Q_y(x,y) = y(x)f(x) \\ 
    \\
    \Longrightarrow \quad &P_{x,y}(x,y) = 2y(x)\cos x \\
    \Longrightarrow \quad &Q_{x,y}(x,y) = y'(x)f(x) + y(x)f'(x) \\
\end{align*}
Since $P_{x,y}$ must be equal to $Q_{x,y}$ for the ODE to be exact, I put them equal to find out $f(x)$ but following equations doesn't look solveable...
\begin{align*}
    y'(x)f(x) + y(x)f'(x) \overset{!}{=}2\cos(x) y(x)
\end{align*}
Any suggestions where I went wrong?
 A: At your fourth step :

$[y^2\cos x] dx+[y f(x)]dy=0$

This implies $M(x,y)=y^2\cos x$ and $N(x,y)=yf(x)$ both are functions of $x$ and $y$. Intuitively,  $N$ is the direct output for inputs $x$ and $y$.


If you still consider $y$ as an output from $x$ then it results in function composition $N\circ y(x)$ which suggests you to compute the ordinary derivative $\left (N\circ y(x)\right )'=\frac{dN}{dy}\times\frac{dy}{dx}$ using chain rule rather than the actually required partial derivative $\frac{\partial M}{\partial x}=yf'(x)$.


A: Basically, partial w.r.t $x$ treats $y$ as a constant. In long, assume ODE is an exact differential:
\begin{align}
y^2(x)\cos x+y(x)f(x)\frac{\mathrm dy}{\mathrm dx}&=\frac{\mathrm d}{\mathrm dx}\lambda(x,y)=\frac{\partial \lambda}{\partial x}+\frac{\partial \lambda}{\partial y}\frac{\mathrm dy}{\mathrm dx},
\end{align}
Equate like terms
\begin{align}
y^2\cos x&=\frac{\partial \lambda}{\partial x}\\
yf(x)&=\frac{\partial \lambda}{\partial y},
\end{align}
Integrate the first (arbitrary which of the two you choose, and you can also differentiate the two for the same result, as you did),
\begin{align}
-y^2\sin x+g(y)=\lambda,
\end{align}
take a derivative and set equal to the latter,
\begin{align}
-2y\sin x+\frac{\mathrm dg}{\mathrm dy}=yf(x),
\end{align}
we care about $f(x)$ so let $g(y)$ be zero, and
\begin{align}
f(x)=-2\sin x.
\end{align}
Notice that if I took second order partial derivatives and set them equal to each other I would end up with
\begin{align}
2y\cos x=y\frac{\mathrm df}{\mathrm dx},
\end{align}
A: We need to verify that the mixed partial derivatives are equal for the ODE to be exact, or in other words, it needs to hold that
$$
\frac{\partial}{\partial y} \left[y^2 \cos(x)\right] = 2y \cos(x) = y f'(x) = \frac{\partial}{\partial x} \left[yf(x)\right]
$$
Which in turn implies
$$
f'(x) = \frac{df}{dx} = 2 \cos(x)
$$
assuming $y(x)$ is not the trivial $0$ solution. From here you just integrate
$$
f(x) = \int 2 \cos(x) \ dx = \boxed{2 \sin(x) + C}
$$

In your solution, you incorrectly used the chain rule on $\frac{\partial}{\partial x} \left[yf(x)\right]$. The reason it's wrong is that in the exact ODE method you assume that you have a parent function $F(x,y)$ of which $x$ and $y$ are independent variables, so when you take the total derivative of $F$ you get
$$
dF = F_x  dx + F_y dy
$$
where here $F_x = P_x$ and $F_y = Q_y$. In turn, if this $F$ exists (and if it's smooth enough) its mixed partials should be equal, in other words
$$
F_{x,y} = F_{y,x} \color{blue}{\implies}  P_{x,y} = Q_{y,x}
$$
which is the reason we equal the partial derivatives.
