# Constancy of current value Hamiltonian and numeric computations

I am playing with a simple, continuous time optimal growth problem to learn optimal control. The social planner chooses $$c_t$$ to maximize: $$\int_0^\infty e^{-\rho t}u(c_t)dt$$ where $$\dot k_t=f(k_t)-c_t,$$ $$u$$ is CRRA, $$f(k_t)=k_t^\alpha$$ and $$k_0$$ is given.

This has straightforward solution with optimal trajectory $$(k_t,c_t)$$ converging to stationary point $$(k^*,c^*)$$.

Numeric computations using a Python implementation of Ben Moll's MATLAB algorithm yield appropriate looking consumption-capital diagrams: where the dashed vertical line represents the stationary point.

The optimization algorithm uses an approximation where, roughly speaking, there is a discrete guess for the value function, its derivative is approximated using its first difference and then approximate consumptions and costates are computed to update the value function.

The problem I am running across is when I try to evaluate the property that the current value Hamiltonian evaluated at the optimal $$k$$, $$c$$ and $$\lambda$$ should be constant. Following is a plot where values of $$\mathcal H(k,c(k),V'(k))=u(c(k))+V'(k)[f(k)-c(k)]$$ on the vertical axis depend on $$c(k)$$, the approximated optimal consumption and $$V'(k)$$, the first difference in the approximated value function. As I understand from Chiang (1992), $$\mathcal H$$ should be constant but this is clearly not reflected in my plot -- all of my other plots are spot on. Am I making a mistake in my plot of the optimized current value Hamiltonian or is there some approximation error that is being magnified in my plot?