We present a novel method to solve the Bagley-Torvik equation by transforming it into ordinary differential equations (ODEs). This method is based on the equivalence between the Caputo-type fractional derivative (FD) of order 3/2 and the solution of a diffusion equation subjected to certain initial and boundary conditions. The key procedure is to approximate the infinite boundary condition by a finite one, so that the diffusion equation can be solved by separation of variables. By this procedure, the Bagley-Torvik and the diffusion equations together are transformed to be a set of ODEs, which can be integrated numerically by the Runge-Kutta scheme. The presented method is tested by various numerical cases including linear, nonlinear, nonsmooth, or multidimensional equations, respectively. Importantly, high computational efficiency is achieved as this method is at the expense of linearly increasing computational cost with the solution domain being enlarged.