Hello Mark,

Thank you for the quick response. I am trying to solve an optimal control problem in which the constraints are a function of the state variables, for which I need to define an index ‘j’. Index ‘j’ represents x(1) in the upper bound constraint x_max(j,i). ‘i’ is the time index.

See below code and picture:

The upper bound x_max on variable x(2) is function of x(1).

load(‘x_max.mat’);

n = min(size(x_max)); dt=0.1; m=35000; dx=5;

cvx_begin

variable u(n)

variable x(2,n)

expressions xveh j

minimize sum(max(0,u))

subject to

x(1,1) == 0;

x(2,1) == 0;

x(1,n) == 200;

x(2,n) ==0;

-40000 <= u(1:n) <= 35000;

for i =1:n-1

x(:,i+1) == [1 dt;0 1]*x(:,i) + [0;dt/m]*u(i);

xveh = x(1,i+1);

j = xveh/dx + 1;

0<= x(2,i+1) <= x_max(j,i+1);

end

cvx_end``