You use the integrating factor when the differential equation is not exact.

1. First Order Linear Ordinary Differential Equations

If the differential equation is in the form $\frac{\mathrm{d} y}{\mathrm{d} x}+f(x)\cdot y=g(x)$, you could use the integrating factor, $\mu(x)$. Keep this form in mind.

Remember the product rule? It’s $\frac{\mathrm{d} }{\mathrm{d} x}(f\cdot g)=f’\cdot g+f\cdot g’$.

Let’s replace $f$ with the $y$ and $g$ with a function that we don’t know $\mu(x)$, so that it satisfies $\frac{\mathrm{d} }{\mathrm{d} x}(\mu(x)\cdot y)=\mu’(x)\cdot y+\frac{\mathrm{d} y}{\mathrm{d} x}\cdot \mu(x)$, so that you can get a form that’s similar with $\frac{\mathrm{d} y}{\mathrm{d} x}+f(x)\cdot y=g(x)$.

If you multiply everything by the integrating factor, you get $\mu(x)\frac{\mathrm{d} y}{\mathrm{d} x}+\mu(x)\cdot f(x)\cdot y=\mu(x) \cdot g(x)$.

From above:

$\frac{\mathrm{d} }{\mathrm{d} x}(\mu(x)\cdot y)=\mu’(x)\cdot y+\frac{\mathrm{d} y}{\mathrm{d} x}\cdot \mu(x)$ $\mu(x)\frac{\mathrm{d} y}{\mathrm{d} x}+\mu(x)\cdot f(x)\cdot y=\mu(x) \cdot g(x)$

Comparing where the $y$’s are: $\mu(x)\cdot f(x)=\mu’(x)$

$\frac{\mu’(x)}{\mu(x)}=f(x)$

$\int \frac{\mu’(x)}{\mu(x)}\mathrm{d}x =\int f(x)\mathrm{d}x$

$\mathrm{ln}|\mu(x)|=\int f(x)\mathrm{d}x$

$\mu(x)=e^{\int f(x)\mathrm{d}x}$. Do not worry about plus-minus - you only need one integrating factor.

So, substitute this $\mu(x)$ into $\mu(x)\frac{\mathrm{d} y}{\mathrm{d} x}+\mu(x)\cdot f(x)\cdot y=\mu(x) \cdot g(x)$ and you notice: the left hand side is $\frac{\mathrm{d} }{\mathrm{d} x}(\mu(x)\cdot y)$

$\frac{\mathrm{d} }{\mathrm{d} x}(\mu(x)\cdot y)=\mu(x)\cdot g(x)$

You can then solve the equation from there.

For reference: $y \cdot e^{f(x)}=\int g(x)\cdot \mu(x)\mathrm{d}x +c$

1.1. Example

$\frac{\mathrm{d} y}{\mathrm{d} x}+\frac{2}{5}y=3e^{-x}$ , $y(0)=5$

Recall that your integrating factor $\mu(x)$ is $e^{\int f(x) \mathrm{d}x}$, so in this case, $\mu(x)=e^{\int \frac{2}{5} \mathrm{d}x}$.

$e^{\frac{2}{5}x}\frac{\mathrm{d} y}{\mathrm{d} x}+\frac{2}{5}e^{\frac{2}{5}x}y=3e^{-\frac{3}{5}x}$

$\frac{\mathrm{d} }{\mathrm{d} x}(e^{\frac{2}{5}x}y)=3e^{-\frac{3}{5}x}$

$e^{\frac{2}{5}x}y=-5e^{-\frac{3}{5}x}+c$

$y=e^{-x}(ce^{\frac{3}{5}x}-5)$

Let’s plug in the initial conditions to find the constant $c$: $5=e^{-0}(ce^{\frac{3}{5}\cdot 0}-5)$

$c=10$

$y=5e^{-x}(2e^{\frac{3}{5}x}-1)$

2. First Order Non-Exact Differential Equations

Use $\mu(x)=e^{\int \frac{\frac{\partial f}{\partial y}-\frac{\partial g}{\partial x}}{g} \mathrm{d}x}$ for when you have the form $f \mathrm{d}x+g \mathrm{d}y=0$, and the equation is not exact.

Like before, find $\mu(x)$ and multiply everything by $\mu(x)$.

2.1. Example

$(4 \sin y + \frac{6}{x})\mathrm{d}x+x\cos y \mathrm{d}y=0$

As you can see, the functions $f$ and $g$ are both functions of both $x$ and $y$, so we must use partial differentials. Don’t be scared - this just means you need to take the partial derivative of the function.

Using the formula, $f=4 \sin y + \frac{6}{x}$ and $g= x\cos y$.

Take the partial derivative of $f$ with respect to $y$, and the partial derivative of $g$ with respect to $x$. When you are taking the partial derivative of one variable, all the other variables are considered constants. $\frac{\partial f}{\partial y}=4\cos y$ and $\frac{\partial g}{\partial x}=\cos y$.

Therefore, $\mu(x)=e^{\int \frac{4\cos y -\cos y}{x \cos y}\mathrm{d}x}=x^3$.

Multiply every term by $\mu (x)$: $(4x^3 \sin y + 6x^2)\mathrm{d}x+x^4 \cos y \mathrm{d}y=0$.

Now this is just an exact equation you can solve. Let $F$ be the general solution to the equation and that $F=\frac{\partial F}{\partial x}\mathrm{d}x+\frac{\partial F}{\partial y}\mathrm{d}y=0$.

$f=\frac{\partial F}{\partial x}=4x^3 \sin y +6x^2$, $g=\frac{\partial F}{\partial y}=x^4 \cos y$

Using $\frac{\partial F}{\partial x}=4x^3 \sin y +6x^2$, integrate: $F=x^4 \sin y+2x^3+f(y)$.

Then differentiate: $\frac{\partial F}{\partial y}=x^4 \cos y+f’(y)$.

Compare: Therefore $f’(y)=0$, so $f(y)=c$.

Substitute into $F$: $F=x^4 \sin y+2x^3+c$, and recall that $F=0$, so $ x^4 \sin y+2x^3=c$.