I’m trying to implement a problem in cvx . it looks something like this.

**summation over k ||x(k) - A*x(k-1)||^2 , k = 1,…,N**

I’ve have to find a value for A that minimizes the above function in the given the interval of N. x is a vector of dimension **n**. In cvx I declared a variable **A(n,n)** and tried to run a loop **N** times to keep on adding the problem at different time instants .i.e.

**variable A(n,n)**

**for k =1:N**

**prob = prob+norm(x(k) - A x(k-1)) * norm(x(k) - Ax(k-1)) ;**

**end**

**minimize prob**

But its throwing an error . Please help

Edit : I tried to vectorize everything. In that case, a huge block diagonal matrix of size T*n is being formed which is giving an **out of memory** error in **matlab**.