
simulate this circuit – Schematic created using CircuitLab
Like in the case of the capacitor, there are three steps:
- Write a KVL equation which will lead to a differential equation.
- Solve the differential equation.
- Apply the initial condition of the circuit to get the particular solution.
The KVL equation can be written simply as
$$
V_i = v_L + v_R
$$
The equation for an inductor is slightly different from a capacitor however. Here, the flux is given by \$\Phi = L\cdot i\$, and the EMK generated by this flux is \$v_L = \frac{d\Phi}{dt} = L\frac{di_L}{dt}\$. Alternatively, you can also write that
$$
i_L = \frac{1}{L}\int_0^t v_L(u)du + i_L(0)
$$
The resistor and the inductor share the same current, so
$$\begin{align}
i_R &= i_L \\
&\Downarrow \\
v_R &= R\cdot i_R = R\cdot i_L \\
&\Downarrow \\
v_R &= \frac{R}{L}\int_0^t v_L(u)du + R\cdot i_L(0)
\end{align}$$
We can put this into the KVL equation:
$$\begin{align}
V_i &= v_R + v_L \\
&\Downarrow \\
V_i &= \frac{R}{L}\int_0^t v_L(u)du + R\cdot i_L(0) + v_L \\
&\Downarrow \\
V_i - R\cdot i_L(0) &= \frac{R}{L}\int_0^t v_L(u)du + v_L
\end{align}$$
We can find the solution by first integrating both sides of the equation.
$$
\frac{d(V_i - R\cdot i_L(0))}{dt} = 0 = \frac{R}{L}v_L + \frac{dv_L}{dt}
$$
We can work this out as follows:
$$\begin{align}
-\frac{R}{L}v_L &= \frac{dv_L}{dt}\\
&\Downarrow\\
-\frac{R}{L}dt &= \frac{dv_L}{v_L}\\
&\Downarrow\\
-\frac{R}{L}\int_0^tdt &= \int_{v_L(0)}^{v_L(t)} \frac{1}{v_L} dv_L\\
&\Downarrow\\
-\frac{R}{L}t &= \left[ \ln(v_L) \right]_{v_L(0)}^{v_L(t)}\\
&\Downarrow\\
-\frac{R}{L}t &= \ln\left(\frac{v_L(t)}{v_L(0)}\right)\\
&\Downarrow\\
v_L(0)e^{-\frac{R}{L}t} &= v_L(t)
\end{align}$$
\$v_L(0)\$ is the voltage across the inductor at \$t=0\$, which is equal to \$V_i - R\cdot i_L(0)\$.
So if the inductor starts out discharged, ie. \$i_L(0) = 0\$, then \$v_L(0) = V_i - R\cdot i_L(0) = V_i\$, and the fomula will turn into
$$v_L(t) = V_ie^{-\frac{R}{L}t}$$
If the inductor already had a current before, and \$V_i\$ is suddenly turned to 0, then \$v_L(0) = 0 - R\cdot i_L(0) = -R\cdot i_L(0)\$ and the solution will turn into
$$v_L(t) = -R\cdot i_L(0)\cdot e^{-\frac{R}{L}t}$$