- If $x_1=0,1,4,5$, then $u_0=-5, -4, -1, 0$. $$\ \sum_{k=0}^3 x_k^2 + u_k^2\ge x_0^2+(u_0^2+x_1^2)\ge 5^2 + 17$$
- If $x_1=3, x_1=2$, then $u_0=-2, -3$. $$\ \sum_{k=0}^3 x_k^2 + u_k^2= 5^2 + 4 + 9 + (u_1^2+x_2^2 + u_2^2 + x_3^2+u_3^2)\\=5^2 + 13 + (u_1^2+x_2^2 + u_2^2 + x_3^2)\ge 5^2 + 13 + 3=5^2+16,$$ where the last inequality holds as among the numbers $u_1, x_2, u_2$, either all of them are $1$ or $-1$, or one of them is bigger than $1$ or smaller than $-1$, i.e., a number whose square is no less than $2^2=4$. $\checkmark$$$\ \sum_{k=0}^3 x_k^2 + u_k^2= 5^2 + 4 + 9 + (u_1^2+x_2^2 + u_2^2 + x_3^2+u_3^2)\\=5^2 + 13 + (u_1^2+x_2^2 + u_2^2 + x_3^2)\ge 5^2 + 13 + 3=5^2+16.$$
Why does the last inequality hold? We know $x_1\ge2$. Among the numbers $u_1, x_2, u_2, x_3$, there are at least 3 numbers that are either $1$ or $-1$, or one of them is bigger than $1$ or smaller than $-1$, i.e., a number whose square is no less than $2^2=4$. $\checkmark$
Tracing the proof above, we can see that the optimal control sequence is $u_0^*=-3$, $u_1^*=-1$, $u_2^*=-1$, $u_3^*=0$.sequences are
- $u_0^*=-3$, $u_1^*=-1$, $u_2^*=-1$, $u_3^*=0$ (as shown above).
- $u_0^*=-3$, $u_1^*=-1$, $u_2^*=0$, $u_3^*=0$.
min_cost = 999999999999999999 # a number too big
x0 = 5
control_sequence = []
for x1 in range(6):
cost0 = x0 ** 2 + (x1 - x0) ** 2
for x2 in range(6):
cost1 = cost0 + x1 ** 2 + (x2 - x1) ** 2
for x3 in range(6):
cost2 = cost1 + x2 ** 2 + (x3 - x2) ** 2
for x4 in range(6):
cost3 = cost2 + x3 ** 2 + (x4 - x3) ** 2
if min_cost > cost3:
min_cost = cost3
print(min_cost) # 41
# or an expanded one-liner.
import from itertools import product
min_cost = min(
sum(x[k] ** 2 +control_sequence (x[k= +[[x1 1]- x0, x2 - x[k])x1, **x3 2- x2, x4 - x3]]
for k in range(4)) elif min_cost == cost3:
for x in product([5], range control_sequence.append(6)[x1 - x0, range(6)x2 - x1, range(6)x3 - x2, range(6))x4 - x3])
print(min_cost)
# 41
print("Optimal againControl sequences: ", control_sequence)
# [[-3, -1, -1, 0], [-3, -1, 0, 0]]
To find the optimal control sequence, keep track of the choices of the variables made for each $f(s,t,x)$ in the loop.