Dynamic Optimization Problem Matlab Code