You can create a 1xN vector of symbolic variables, by using
A=sym('A',[1 N]);
and then the i
-th element is accessed using A(i)
.
See here for more detail.
As for writing the sum, I can't really help. I think you may to use a for loop and specify the indices, i.e.
S=0;
for i=1:N/2
S=S+alpha*(x(2*i)-x(2*i-1)^2)+(1-x(2*i-1))^2;
end
but that doesn't simplify the answer at all. I'm not aware of a better method though.