We propose a computational model for noncontact atomic force microscopy (AFM) in which the atomic force between the cantilever tip and the surface is calculated using a molecular dynamics method, and the macroscopic motion of the cantilever is modeled by an oscillating spring. The movement of atoms in the tip and surface is connected with the oscillating spring using a recently developed coupling method. In this computational model, the oscillation energy is dissipated, as observed in AFM experiments. We attribute this dissipation to the hysteresis and nonconservative properties of the interatomic force that acts between the atoms in the tip and sample surface. The dissipation rate strongly depends on the parameters used in the computational model.