Given a fixed $T > 0$ and the ODE $$\dot{x}(t) = a u(t)$$ where $x(t)$ is the state and $u(t)$ is the control input, find the optimal pair $(x^{\ast}(t), u^{\ast}(t))$
$$\begin{array}{ll} \text{minimize} & \displaystyle\int^{T}_{0} \left( u^2(t) + x^2(t) \right) \, \mathrm d t\\ \text{subject to} & x(0)=1\\ & x(T) \text{ is free}\\ & u(t) \in [0,1]\end{array}$$
If $a>0$, I can find the optimal pair. However, if $a<0$, I don't know how to solve this problem.
Here is my approach to solve this problem by optimal control theory.
The Hamiltonian is $H=-(u^2+x^2)+pau$, thus $H^{\prime}_{u}=-2u+pu$.
$H$ is a concave function in $u$, so $u^{\ast}=\frac{pa}{2}$ is a candidate for optimality. Then we can get $$u^{\ast}=\frac{1}{1+e^{2aT}}(e^{at}-e^{2aT}e^{-at})$$
It can be verified that $u^{\ast} \in(0,1)$ . So $u^{\ast}$ satisfied all conditions. We conclude that $u^{\ast}$ is the optimal control.