Optimal control problem with state and control constraints We need to solve the following the optimal control task:
$$\int^T_0 (\dot{x}^2 - x^2)dt \rightarrow \inf \\
 x(0) = x(T) = 0, |\dot{x}| \leqslant 1, T \in const$$
First question: is there any tool, that can automatically solve this task?
I got the next a bound value problem by using the Maximum Principle:
$$\begin{cases}
  \dot{x}(t) = u(t), ~~~ \dot{p}(t) = -x(t) \qquad \forall t \in [0,T];\\
  u(t) \equiv \begin{cases}
   1, & p(t) > 0 \\
   -1, & p(t) < 0 \\
   \forall u \in [-1, 1], & p(t) = 0
  \end{cases} \\
  x(0) = x(T) = 0;
 \end{cases}$$
Second question: do you have any ideas how to solve this boundary value problem? Maybe somebody seen a similar example of the optimal control task?
 A: In general, you may use the matlab command BVP4C for solving boundary value problems, ..(One of the options)
$X(0)=X(T)=0$, so the initial and final value of the state are the same?
A skeletal code for using Matlab function bvp4c is given below for your reference, see more details in  http://www.mathworks.com/help/matlab/ref/bvp4c.html.
    function functionnamhere
tlow=0;thigh=5;% mention initial time t0 and final time T
%solinit = bvpinit(x, yinit, params) is a structure
solinit=bvpinit(linspace(tlow,thigh,100),[50;45;44;-10;-10;-10]);
sol=bvp4c(@bvp4ode,@bvp4bc,solinit);
tint=linspace(tlow,thigh,200);
stint=deval(sol,tint);

%-------------------------------------------------
%%%%%% Differential equations to be satisfied
%-------------------------------------------------
function dydt=bvp4ode(t,y)
define global variables if any
define ode such as xdot=ax+bu

%--------------------------------------------------------------
%% Residual in the boundary conditions
%--------------------------------------------------------------
function res=bvp4bc(ya,yb)
%assign boudary conditions
% such as res=[ya(1);ya(2);yb(4)-1;yb(5)];

In the second segment of your question, by $p(t)$ you mean the lagrangian multiplier?
