Error while minimizing a summation with respect to a matrix

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) - Ax(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.

I’ll leave vectorization for someone else to worry about.

You did not initialize prob (to zero).
The first iteration through the for loop references x(0), which is illegal in MATLAB.
I’ll let you determine whether N is the same as n.