# Numeric quadrature vs summation of running costs in model predictive control

Usually, an MPC consists of discretizing the optimal control problem in time using some numerical quadrature scheme. So the infinite-dimensional OCP reads \begin{aligned}J(\vec{u}) &= \varphi\left(\vec{x}(t_i+t_{hor})\right) + \int_{t_i}^{t_i+t_ {hor}}l(\vec{x},\vec{u})\text{d}t \\ \text{s.t.}\\ \dot{\vec{x}}&=\vec{f}(\vec{x},\vec{u}), \quad \vec{x}(t_i)=\hat{\vec{x}}_i\end{aligned} which can be transcribed to a static nonlinear program using, e.g., the trapezoidal rule for the integral and some other (or does it have to be the same?) integration scheme, e.g., the explicit Euler for the ODE, i.e. \begin{aligned} c(\vec w) &= \varphi\left(\vec{x}_N\right)+\frac{t_{hor}}{N}\sum_{k=0}^{N-1}\frac{l(\vec{x}_k,\vec{u}_k)+l(\vec{x}_{k+1},\vec{u}_{k+1})}{2}\\ \text{s.t.}\\ \vec{x}_{k+1}&=\vec{x}_{k}+\frac{t_{hor}}{N}\vec{f}(\vec{x}_k,\vec{u}_k), \qquad k=0,...,N-1\\ \vec{x}_0&=\vec{\hat{x}}_i \end{aligned} where $$\vec{w}=[\vec{x}_0^T\ ... \ \vec{x}_N^T \ \vec{u}_0^T\ ... \ \vec{u}_N^T ]^T$$ are the decision variables, $$t_{hor}$$ is the MPC horizon, and $$N$$ is the number of discretization steps. But often it can be observed that instead of the above sum, the cost function simply reads $$c(\vec w) = \varphi\left(\vec{x}_N\right)+ \sum_{k=0}^{N}l(\vec{x}_k,\vec{u}_k).$$ My question is, under what conditions is this possible? Can I always do this? I guess that it depends on whether the actual value of the integral matters or not but this implies that the integration does not change the optimal decision variables $$\vec w^\ast$$ since it involves just a scaling of the cost function? I could also imagine that it has to do with the function $$l(\cdot)$$ itself. Maybe this only works if $$l(\cdot)$$ is at most quadratic in the decision variables? Although I have seen this notation in nonlinear MPC.

EDIT 1: added ODE equality constraint and final costs

EDIT 2: Adding the final cost, I can see that one might need to have both discretizations to be the same or non at all for the continuous integral? Since in the discretized version, $$\varphi\left(\vec{x}_N\right)$$ depends on the final state which is the result of the ODE integration which, in this example, was done using the explicit Euler while the continuous integral has been approximated using the trapezoidal rule leading to different accuracies in the solution when they should probably be of the same order of accuracy? Therefore, just using the second sum leads to just adding up the values of the running cost term evaluated at the discretized steps which, in turn, depend on the ODE discretization. So this seems to make more sense to me than having two different integration schemes.

• How do I interpret $x_k$ and $u_k$? does this mean the continuous-time state value at time instance $k$ or is it the discretized state using some sampling time $T_s$ evaluated at $k$? Why do you multiply the equation with $\frac{t_{hor}}{N}?$ Why does the sum start at $k=0$ and not at $k=t_i$? Nov 9 '20 at 15:45
• I did not want to put the focus on the discretization of the state and input signals, but this is meant to be the discretized state and input as is usual in a discretized OCP. The $\frac{t_{hor}}{N}$ comes from the trapezoidal rule (which could be simplified here, because of a fixed, equidistant time step). The $k=0$ is to be understood relative to the current time $t_i$, i.e., the prediction at time step $k$ in "real time" is $t_k=t_i+k\frac{t_{hor}}{N}$ with $k=0,...,N$.
Nov 10 '20 at 7:41

MPC finds the optimal input $$u^*$$ which is the input that minimizes the cost function $$J$$ or $$c$$. This means that regardless of what this actual value is, its proven to be its minimum. As such, multiplying the cost function with any constant value does not change this minimum, it just scales the value. Therefore, $$\frac{t_{hor}}{N}$$ does not affect the optimal input and can be eliminated. If there is a terminal cost present, the terminal state should also be computed using this trapezoidal rule and is also multiplied with this constant.

Secondly, taking the cost over actual sampled values of $$x_k$$ or taking the average between two samples seems nearly a matter of perspective. In fact, if you write out both sums, you discover that the difference is something like this: $$\frac{1}{2}\sum_{k=0}^{N-1}l(x_k,u_k) + l(x_{k+1}, u_{k+1}) = \frac{1}{2}(l(x_0,u_0)+ l(x_{N}, u_{N})) + \sum_{k=1}^{N-1}l(x_k,u_k)$$ Additionally, if this cost function happens to have a initial cost term and terminal cost term you can imagine it begin fully equal to the other one. (albeit having a different initial and terminal cost value). However, if this $$l(.)$$ in your cost function is a continuous time one (I assume its not really linear in the states and inputs), I should not that the standard cost function probably uses $$l(.)$$ in a discretized way.

Hope this got you somewhere, I have not encountered your trapezoidal approach ever, so that makes it kinda interesting.

• You mention what I also suspect, that this "scaling" does not change the optimal decision variables. However, I am not sure what you mean with "$l(\cdot)$ [...] in a discretized way". For example if $l(\boldsymbol{x},\boldsymbol{u})=\boldsymbol{u}^2$, then $l(\boldsymbol{x}_k,\boldsymbol{u}_k)=\boldsymbol{u}_k^2$. Nevertheless, I could maybe make this more clear by adding the ODE to the question. My trapezoidal approach is just a way to approximate the integral term in order to "discretize" the continuous integral.
Nov 10 '20 at 12:14
• I added a final cost and the ODE to the question. I think you answered the question in my second edit, too, because the terminal cost should be calculated with the same integration scheme as you say. Thanks!