We begin by considering a free-body diagram of a short portion of the beam.

This element of the beam has a length Δx.

Here is Canvas object wihch demonstrate the problem.