% Script for solving a class of optimal control problems
% by transcription to finite-dimensional NLP.
%
% The class of problems considered is
%
% \dot x(t) = f(t,x(t),u(t))
%
% with specified initial condition
%
%    x(0) = X_initial, an N_state vector,
%
% simple bounds on the controls
%
%   lower_i  \le   u_i  \le  upper_i, i = 1,2,.. N_control.
%
% The end_time is fixed at T_final > 0
% and there are (possibly) specified equality end_conditions
%
%  \phi(x(T_f) = 0, an N_end vector
%
% The objective is to minimize a (Mayer) function of the end_states
%
%   g(x(T_f))
%
% The user has to supply .m files
%
%    Rhs.m     for the differential equations,
%    Phi_eq.m  for the end equality constraints
%    Phi_in.m  for the end inequality constraints
%    Mayer.m   for the cost functional
%
%  for analytic calculation of Jacobians user must also supply
%
%    Rhsj.m     for the differential equations,
%    Phi_eqj.m  for the end equality constraints
%    Phi_inj.m  for the end inequality constraints
%    Mayerj.m   for the cost functional
%
% along with the vectors 
%
%  X_initial, lower_i, upper_i
%
% and the scalar
%
%  T_f
%
% These values are set in a user supplied initialization routine
%
  p_name = input('Supply a problem name to set the DATA structure:  ','s'); 
  evalin('base',p_name)
%
  [UB,LB,U0,OPTIONS] = initial_post(DATA); 
%  
   tic; flops(0);               
    [U_star, Val] = ... 
      fmincon('obj_post',U0,[],[],[],[],LB,UB,'con_post',OPTIONS,DATA);
   toc; flops
