I declared a variable x(2,N) being N the horizon time. Then I got an expression using the following portion of code:

```
cvx_begin
variable x(2,N)
expression rho_sum1
rho_sum1 = 0;
x1_limit1_pert = 5;
for i=1:N
rho_sum1 = rho_sum1 + exp(-k1*(x(1,i) - x1_limit1_pert));
end
```

%%%

%%% More code ahead…

If I want to compute the derivative of rho_sum with respect to x(1,i), I use diff(rho_sum1,x(1,i)), however it shows up an error:

Incorrect number or types of inputs or outputs for function ‘diff’.

I appreciate the help on how to properly compute the derivatives in the CVX environment. Thank you !!