Select $x(t)$ such that it minimizes $J$, $J = \int_0^T \left[(x - e^{-t})^2 + (\dot{x} + 1)^2\right]dt$. I am given two situations, $A$ and $B$.
For $A$, the ideal $x(t)$ is $e^{-t}$ for $0 \le t \le T$.
However, for $B$, the ideal $\frac{dx}{dt}$ is $-1$ for $0 \le t \le T$.
I am to make a compromise and select $x(t)$ such that it minimizes $J$,
$$J = \int_0^T \left[(x - e^{-t})^2 + (\dot{x} + 1)^2\right]dt$$
I am asked to find a differential equation that the optimal $x(t)$, $x^*(t)$, must satisfy and solve for this $x^*(t)$ under the conditions that $T=1$, $x(0) =1$, and $x(1) = 0.5$.
What I'm trying to solve: $x''-x=-e^{-t}$.
Solution should look like: $x(t) = c_1e^{\lambda_1t} + c_2e^{\lambda_2t} + x(p)$, where $x(p)$ is a particular solution.
Let $x(p) = Ate^{-t}$. 
Then $x'(p) = Ae^{-t} - Ate^{-t}$ and $x''(p) = -2Ae^{-t} +Ate^{-t}$.
Substituting into $x''-x=-e^{-t}$ gives $-2Ae^{-t} + Ate^{-t} - Ate^{-t} = -e^{-t}$.
$\implies A = \frac{1}{2} \implies x(p) = \frac{1}{2}te^{-t}$.
Using the boundary conditions:
$x(0) = 1 \implies c_1 + c_2 = 1$ and $x(1) = \frac{1}{2} \implies c_1e + \frac{c_2}{e} + \frac{1}{2e} = \frac{1}{2}$
According to Wolphram Alpha, the values for my $c_i$ are messy.
 A: The equations you need to derive are known as Euler-Lagrange equations; assume $x(t)$ minimizes the action.  Then any sufficiently small perturbation $x(t) + \delta \phi(t)$ (with a smooth test function $\phi$) will give a larger value to the action.  Let $I$ be the action evaluated at $x(t)$ and $I_\delta$ the same action evaluated at $x(t)+\delta\phi(t)$.  If you take the limit of the ratio $|I_\delta-I|/\delta$ as $\delta\to 0$ you should get zero by the variational principle.  After some manipulation and with the fundamental lemma of the calculus of variations you will get the Euler-Lagrange equation.  I will not give details since the derivation of the Euler-Lagrange equations is contained in every book of Calculus of Variations.
Your Lagrangian is $L(t,x,v)=(x-e^{-t})^2+(v+1)^2$ so $L_x = 2(x-e^{-t})$ and $L_{v} = 2(v+1)$ giving you $$2(x-e^{-t})=2\ddot{x},$$ a linear second order non-homogeneous ODE with constant coefficients.  In more usual form, $$x''-x=-e^{-t}.$$  Do you know how to solve equations like this?
