```
A=[1,0.1,0,0,0,0,0,0,0,0;
```

0,1,1,0,0,0,0,0,0,0;

0,0,1,0.1,0,0,0,0,0,0;

0,0,0,1,0,0,0,0,0,0;

0,0,0,0,1,0.1,0,0,0,0;

0,0,0,0,0,1,1,0,0,0;

0,0,0,0,0,0,1,0.1,0,0;

0,0,0,0,0,0,0,1,0,0;

0,0,0,0,0,0,0,0,1,0.1;

0,0,0,0,0,0,0,0,0,1];

B=[0,0,0,0;

0,0,0,0;

0,0,0,0;

-4.116e-10,0,4.116e-10,0;

0,0,0,0;0,0,0,0;0,0,0,0;

0,-4.116e-10,0,4.116e-10;

0,0,0,0;

1.818e-07,1.818e-07,1.818e-07,1.818e-07];

C=[0;0;0;0;0;0;0;0;0;-1];

x0 = [120 -1 0 0 100 -2 0 0 500 -5]’;

xd = [0 0 0 0 0 0 0 0 0 0]’;

%

cvx_begin

cvx_solver

cvx_solver sedumi

variable x(10,500)

variable u(4,499)

% minimize( vec(u)’ * eye(4 * 500)*vec(u) )

minimize( vec(x)’ * eye(10 * 500)*vec(x) + vec(u)’ * eye(4 * 499) * vec(u) )

subject to

for i=1:499

x(:,i+1) == A * x(:,i) - B * u(:,i) + C;

end

x(:,500) == xd

x(:,1) == x0

x(9,: ) >= 0

0 <= u <= 2e6

cvx_end

I get weird solutions for this problem using sedumi solver in which u will be the same in each column. However, it would get infeasible solution using default solver.

This is a dynamic system with a linear state function X(t+1)=A*X(t)+B*U(t)+C. Trying to constrain the initial and final state X1 and X500, while minimizing the cost.

I have been trying to get it done in CVX for days…lol. Don’t know why. Can anyone have a look. Thanks in advance.