# How is this formula to solve linear ODE obtained?

On my textbook, at the end, there is a very short paragraph about differential equations where the formula $$y=e^{-\int a(x) \mathrm{d}x}\bigg[\int b(x)\cdot e^{\int a(x) \mathrm{d}x}\mathrm{d}x+c\bigg]$$ is given as a solution of a linear differential equation in the form $$y'+a(x)y=b(x)$$

I can see that this formula works (by substitution in the differential equation), but I don't understand how was it obtained, can someone show me how to derive this formula?

Let us consider the differential equation $$y'+a(x)y=b(x)$$ First, we need to find the solution of $$y'+a(x)y=0$$ which is a separable equation from which we obtain $$\log(y)=-\int a(x) ~dx+ C$$ that is to say $$y=C e^{-\int a(x) ~dx}$$ Now, apply the method of the variation of the constant and arrive to $$C' e^{-\int a(x) ~dx} =b(x)$$ or $$C' =b(x)e^{\int a(x) ~dx}$$ which means that $$C=\int b(x)e^{\int a(x) ~dx}+K$$ Now, replace $C$ in $$y=C e^{-\int a(x) ~dx}$$ and simplify to get the result $$y=e^{-\int a(x) \mathrm{d}x}\bigg[\int b(x)\cdot e^{\int a(x) \mathrm{d}x}\mathrm{d}x+K\bigg]$$

Is this making things clearer ?

You use the integrating factor $e^{\int a(x)dx}$ and you see that:

$(ye^{\int a(x)dx})'=(y'+a(x)y)e^{\int a(x)dx}$

So we, multiply through by this factor to obtain:

$(ye^{\int a(x)dx})'=b(x)e^{\int a(x)dx}$

Integrate with respect to $x$:

$ye^{\int a(x)dx}=\int b(x)e^{\int a(x)dx}dx+c$

$\Rightarrow y=e^{-\int a(x)dx}(\int b(x)e^{\int a(x)dx}dx+c)$