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

\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 f_0 (x,u) = x^2 + 4ux + 8u^2

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

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

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

The co-state equation is

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

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

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

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

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

The optimal trajectory is

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

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

\displaystyle = x + \psi_1 - x

\displaystyle  = \psi_1

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

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

\displaystyle = x

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

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

which has general solution

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

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

Using the endpoint conditions

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

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

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

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

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

\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 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 u^* = \frac{1}{4}(\dot{\psi_1} - \dot{x})

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

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

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

\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)