Mathematical modelling of elevator optimization problem I have tried to model the following problem:
"An elevator has a vertical acceleration $u(t)$ at time . Passengers would like to move from the ground level at $0$ altitude to the $16th$ floor at altitude $50$ as fast as possible, but dislike fast acceleration. Suppose that the passenger’s time is valued at $a$ dollar per unit time and furthermore suppose that the passenger is willing to pay at a rate $b*u(t)^2$  dollar per unit time to avoid fast acceleration. Formulate the problem of determining the acceleration from the time the elevator starts ascending until it reaches $16th$ floor as an optimal control problem." But, I was stuck at some point, could you give any help to model this mathematically? 
 A: Penalize acceleration and time. 
The minimization problem could be expressed as
$$
\min_u\int_0^T a + b \cdot u^2(t) \; \text{dt},
$$
as stated in the assignment.
The constraint is that you need to reach the $16^{\text{th}}$ floor (or $50$ height units):
$$
50 = \int_0^T \int_0^T u(\tau) \; \text{d}\tau \text{dt}.
$$

You could as well reformulate the above by means of a system of linear ordinary differential equations.
Cost function stays the same, but constraints are
$$
\left(
\begin{array}{c}
\dot{x}_1 \\
\dot{x}_2
\end{array}
\right)
= 
\left(
\begin{array}{cc}
0 & 1 \\
0 & 0
\end{array}
\right)
\left(
\begin{array}{c}
x_1 \\
x_2
\end{array}
\right)
+
\left(
\begin{array}{c}
0 \\
1 \\
\end{array}
\right)
u,
$$
$$
x_1(T) = 50, x_2(T) = 0,
$$
with initial conditions $x_1(0) = x_2(0) = 0$.
Note that $x_1$ represents height, while $x_2$ represents velocity.

Assume a passenger pays 30 Cent for a moderate acceleration value and 10 Cent for traveling time. 
Then it will take him 23 time units (say: seconds) to reach the $16^{\text{th}}$ floor. The acceleration function $u$ that minimizes the cost function is
$$
u(t) = 0.57735 \cdot (1 - 2t/T).
$$
For this particular problem, the solution is analytic.

The optimization problem you are dealing with has the following properties:


*

*dynamic optimization variable - here: elevator acceleration - is a function of time $u(t)$

*unbounded no restrictions opposed to $u(t)$

*free end-time end-time $T$ is not fixed; it's part of the optimization problem to find it

*end constraints we want the elevator to be in the $16^{\text{th}}$ floor at end-time, and it should stop there: $x_1(T) = 50, \; x_2(T) = 0$.


In general, this kind of problem needs iterative/numeric treatment, i.e. there is no closed solution available. It can be solved using e.g. boundary value problem solvers (if you happen to have one at your disposal).
In this special case, an analytic treatment is possible.
The necessary first-order optimality conditions are
$$
\begin{eqnarray} 
\tag{1}\label{eqn.system}
\dot{\mathbf{x}} & = & A\mathbf{x} + \mathbf{b}u \\
\tag{2}\label{eqn.lagrange}
\dot{\mathbf{\lambda}} & = & -A\mathbf{\lambda} \\
\tag{3}\label{eqn.algebraic}
0 & = & 2bu + \mathbf{b}^T \mathbf{\lambda}
\end{eqnarray},
$$
where $\mathbf{\lambda}(t) \in \mathbb{R}^2$ are Lagrange multipliers. This set of equations is obtained by partial derivation of the Hamiltonian.
Then, there are initial and end conditions
$$
x_1(0) = x_2(0) = x_2(T) = 0; \; x_1(T) = 50,
$$
and one transversal condition, due to free end-time:
$$
\tag{4}\label{eqn.transversal}
0 = a + u^2(T) + \mathbf{\lambda}(T)^T(A\mathbf{x}(T) + \mathbf{b}u(T)).
$$
You can solve this set of equations by 


*

*substituting $u$ with $-\lambda_2/(2b)$, using $\eqref{eqn.algebraic}$,

*solve the decoupled odes in $\eqref{eqn.lagrange}$ backwards in time to obtain $\lambda_1 = \text{const.}$, $\lambda_2(t) = \lambda_2(T) + \lambda_1(T - t)$,

*solve the system odes in $\eqref{eqn.system}$ to obtain $x_1(T)$, $x_2(T)$,

*form a set of three algebraic equations, nonlinear in $(\lambda_1, \lambda_2(T), T)$, using the results from step (3) and equation $\eqref{eqn.transversal}$:


$$
\begin{eqnarray}
0 & = & x_2(T) + (\lambda_2(T)T + \lambda_1T^2/2)/(2b), \\
0 & = & x_1(T) + (\lambda_2(T)T^2/2 + \lambda_1T^3/3)/(2b), \\
0 & = & a + bu^2(T) + \lambda_1x_2(T) + \lambda_2(T)u(T),
\end{eqnarray}
$$


*apply a solver to find the zeros, where $(\lambda_1, \lambda_2(T), T)^{(0)} = (-0.1, 0.1, 10)$ will do as a first guess with $a = 0.1$, $b = 0.3$,

*put the pieces together to obtain


$$
u(t) = -\lambda_2(t)/(2b) = (\lambda_1(t-T) - \lambda_2(T))/(2b) = u_0 \cdot (1 - 2t/T),
$$
where $u_0 = 0.57735$, $T = 22.79507$.
