I am using the book by M.Steele, Stochastic calculus and financial applications and came across the following solution method in chapter 9. The method is called coefficient matching and starts like:
$$dX(t) = \mu X(t)dt + \sigma X(t)dB(t) \quad \text{with } X(0) = x_0>0$$
where $B(t)$ is a Brownian motion and $\mu$ and $\sigma$ are constants. Deriving $dX(t)$ usign Ito's lemma and assuming $X(t) = f(t,B(t))$ yields
$$dX(t) = \frac{\partial f}{\partial x}dB(t) +\left(\frac{\partial f}{\partial t} + \frac{1}{2}\frac{\partial^2 f}{\partial x^2}\right)dt$$
Now matching the coefficients yields
$$\mu f = \frac{\partial f}{\partial t} +\frac{1}{2}\frac{\partial^2 f}{\partial x^2}$$
$$\sigma f = \frac{\partial f}{\partial x}$$
Now one can find the function $f(x,t)$ using the second equation which yields
\begin{equation*} \begin{split} f(t,x) & = e^{\sigma x + g(t)}\\ \end{split} \end{equation*}
Using this $f(t,x)$ for the first equation
\begin{equation*} \begin{split} g^{\prime}(t) &= \mu -\frac{1}{2}\sigma^2\\ \end{split} \end{equation*}
As the next step the book says that now we get
$$f(t,x) = x_0e^{\sigma x +(\mu -\frac{1}{2}\sigma^2)t}$$
and hence
$$X(t) = x_0e^{(\mu -\frac{1}{2}\sigma^2)t +\sigma dB(t)}$$
Could someone explain how to get the last two equations?
You have derived that $g'(t) = \mu -\frac{1}{2}\sigma^2$. Integrating both sides yields $$g(t) = \left(\mu-\frac{1}{2}\sigma^2\right)t+C,$$ where $C$ is an arbitrary constant. We can then write \begin{align} f(t,x) &= \exp\{\sigma x+g(t)\} \\ &= \exp\left\{\sigma x + \left(\mu-\frac{1}{2}\sigma^2\right)t+C \right\} \\ &= \exp\{C\} \exp\left\{\sigma x + \left(\mu-\frac{1}{2}\sigma^2\right)t \right\} \quad (*) . \end{align} The expression for $X(t)$ follows immediately by the definition $$X(t) = f(t,B(t)).$$ (Substitute $B(t)$ for $x$ in $(*)$). The value of $C$ can be determined by the initial condition. Since $X(0) = x_0$, this implies $$C = \ln(x_0).$$