CVX constraints - real affine but doesn't work?

I am trying to solve the following problem here.

Given z_0,z_g \in \mathbb{R}^n

\textbf{minimize} \|z-z_g\|

\text{subject to} \quad 0 \leq \sum_{i=1}^k (z_{0,i}-z_i) \leq C \quad \forall k = 1,2,...,n

Where C is a constant scalar. There are other constraints too but this constraint is the one CVX is complaining about, despite how it solved the problem once before.

Can anybody help?

The complain reads:

The following error occurred converting
from cvx to double:
Error using double
Conversion to double from cvx is not

Error in myfun (line 39)
        V(k) = dx*sum(z0(1:k)-z(1:k));

I think if you pre-declare V as an expression using the expression command you will find that it works. The reason for this is somewhat hard to describe, but basically V is a standard MATLAB vector, and you can’t assign a CVX variable to it. Pre-declaring V will fix that.

Excelllent - thank you! :slight_smile: