I've been given the following unconstrained optimal control problem, but I feel like I've made a mistake at some point.
The system $\dot x = -x + u$, where u = u(t) is not subject to any constraint, is to be controlled from $x(0) = 1$ in such a way that; $$J = \frac{1}{2}x^2(2) + \frac{1}{2} \int_{0}^{2}(u^2 - 2xu)dt$$ is minimised. Find the optimal control.
To begin with, I set my Hamiltonian as follows; $$H' = xu - \frac{u^2}{2} + \lambda(u-x)$$
With the costate equation; $$\dot \lambda = \frac{- \partial H'}{\partial x} = -u + \lambda$$
Now, we want to maximise $H'$ as a function of $u$, so; $$0 = \frac{\partial H'}{\partial u} = x - u + \lambda$$
So, now, I have $u = x + \lambda$, $\dot x = -x + u$, and $\dot \lambda = -u + \lambda$.
Now, we can replace the $u$ in the latter two functions to get; $$\dot x = \lambda$$ $$\dot \lambda = -x$$
Then, we have; $$\ddot x = \dot \lambda$$ $$\implies \ddot x = -x$$ $$\implies x(t) = A \sin(t) + B \cos(t)$$ For some constants $A, B \in \Re$.
Now, we're given the initial condition $x(0) = 1$, so we can use this to show that $B = 1$.
Then, we have the following; $$x(t) = A \sin(t) + \cos(t)$$ $$\lambda(t) = A \cos(t) - \sin(t)$$
Now, because of the way my $J$ was set up, I now need to use a transversality condition; $$\lambda(t_1) = \frac{-\partial g }{\partial x}$$
Setting $t_1 = 2$, and $g = \frac{-x^2}{2}$, we get; $$\lambda(2) = -x(2)$$ $$\implies A \cos(2) - \sin(2) = -A\sin(2) - \cos(2)$$ $$\implies A = \frac{\sin(2) - \cos(2)}{\sin(2) + \cos(2)}$$
To me, this just seems overly complex?? Regardless, I can get an equation for the optimal control now;
$$u = x + \lambda = (A-1)\sin(t) + (A+1)\cos(t)$$ With the $A$ term as defined above.
Does this seem correct?? I can't really see a problem with my working, but my $A$ term just seems strange.