Looking over it a last time. I think this should be `dx[j+1] - x_val`. It probably never matters, because the only possible way it can normally make a difference is when the slope is 0. But, to be sure about wonky edge-cases...