A Generic Dynamic Programming Matlab Function Example