The system $\displaystyle \dot{x} = x + 4u$ where$\displaystyle u = u(t)$ is not subject to any constraint, is to be controlled from $\displaystyle x(0) = 1$ to $\displaystyle x(t_1) = 2$ where $\displaystyle t_1$ is unspecified in such a way that

$\displaystyle \displaystyle J = \int_0^{t_1} (x^2 + 4ux + 8u^2) dt$ is minimized. Find the optimal control.

I have a solution, is there anyone who could check it and see if I have gone wrong somewhere?

Let $\displaystyle f_0 (x,u) = x^2 + 4ux + 8u^2$

Let $\displaystyle \displaystyle f_1(x,u) = x + 4u $

Then $\displaystyle \displaystyle H = \psi_0 f_0 + \psi_1 f_1$ where $\displaystyle \displaystyle \psi_0 = -1$

$\displaystyle \displaystyle = -x^2 - 4ux - 8u^2 + \psi_1 (x + 4u)$

The co-state equation is

$\displaystyle \displaystyle \dot{\psi_1} = - \frac{\partial H}{\partial x} = 2x + 4u - \psi_1 $

By pmp, $\displaystyle \displaystyle u^{*}$ maximizes $\displaystyle H$ as a function of $\displaystyle u$

$\displaystyle \displaystyle \frac{\partial H }{\partial u} = -4x - 16u + 4 \psi_1 = 0 $

$\displaystyle \displaystyle \Rightarrow u^{*} = \frac{\psi_1}{4} - \frac{x}{4}$

$\displaystyle \displaystyle \frac{\partial^2 H}{\partial u^2} = -16 \leq 0$

The optimal trajectory is

$\displaystyle \displaystyle \dot{x} = x + 4u^* $

$\displaystyle \displaystyle = x + 4 (\frac{\psi_1}{4} - \frac{x}{4})$

$\displaystyle \displaystyle = x + \psi_1 - x$

$\displaystyle \displaystyle = \psi_1$

and $\displaystyle \displaystyle \dot{\psi_1} = 2x + 4u - \psi_1$

$\displaystyle \displaystyle = 2x + \psi_1 - x - \psi_1 $

$\displaystyle \displaystyle = x$

$\displaystyle \displaystyle \Rightarrow \ \ddot{x} = \dot{\psi_1} = x$

$\displaystyle \displaystyle \Rightarrow \ \ddot{x} - x = 0 $

which has general solution

$\displaystyle \displaystyle x = Ae^t + Be^{-t}$

$\displaystyle \displaystyle \dot{x} = Ae^t - Be^t$

Using the endpoint conditions

$\displaystyle \displaystyle x(0) = 1$, $\displaystyle \displaystyle x(t_1) = 2 $

$\displaystyle \displaystyle x(0) = 1 = A - B \Rightarrow \ A = 1 + B $

$\displaystyle \displaystyle x(t_1) = 2 = Ae^{t_1} + Be^{-t_1} $

$\displaystyle \displaystyle 2 = (1 + B) e^{t_1} + Be^{-t_1}$

$\displaystyle \displaystyle 2 = e^{t_1} + Be^{t_1} + Be^{-t_1} $

$\displaystyle \displaystyle B = - \frac{-2 + e^{t_1}}{e^{t_1} + e^{-t_1}} \ \Rightarrow \ A = 1 + B = \frac{e^{-t_1} + 2}{e^{t_1} + e^{-t_1}}$

Therefore

$\displaystyle \displaystyle x(t) = \frac{e^{-t_1} + 2}{e^{t_1} + e^{-t_1}} e^t - \frac{-2 + e^{t_1}}{e^{t_1} + e^{-t_1}} e^{-t} $

Then, recalling that

$\displaystyle \displaystyle u^* = \frac{1}{4}(\dot{\psi_1} - \dot{x})$

We have
$\displaystyle = \displaystyle \frac{1}{4} (x - \dot{x})$ (recalling from above that $\displaystyle \dot{\psi_1} = x$ from above)

$\displaystyle = \displaystyle \frac{1}{4} (Ae^t + Be^{-t} - Ae^t + Be^t)$

$\displaystyle = \displaystyle \frac{1}{4} (Be^{-t} + Be^t)$

$\displaystyle \displaystyle = \frac{1}{4} \big( -{\frac {-2+{{\rm e}^{t_1}}}{{{\rm e}^{t_1}}+{{\rm e}^{-t_1}}}} e^{-t} -{\frac {-2+{{\rm e}^{t_1}}}{{{\rm e}^{t_1}}+{{\rm e}^{-t_1}}}} e^t\big)$