it was just a stupid mistake now all the result are as expected, thanks for the advice you gave me. This the code:
beta = 1.50;
g = 9.81;
z = 0.8;
w = sqrt(g/z);
Deltax = 0.001;
epsilon = 0.005;
P = 1500;
x=sdpvar(2*ones(1,P+1),ones(1,P+1));
u=sdpvar(ones(1,P+1),ones(1,P+1));
x{1}(1) = 0;
x{1}(2) = epsilon;
u{1} = 0;
Constraints = [];
for i = 1:P
Constraints=[Constraints;
x{i+1}(1) == x{i}(1)+Deltax;
x{i+1}(2) == x{i}(2) + w.^2*(x{i}(1)-u{i}) * Deltax/x{i}(2);
x{i}(2).^2>=epsilon.^2;];
end
Constraints=[Constraints;x{P+1}(1) == pref(1,P+1)];
Cost=0;
for i=1:P
Cost = Cost + (x{i}(2)-vref(1,i)).^2+beta*(u{i}-pref(1,i)).^2;
end
options = sdpsettings('verbose',1);
Problem = optimize(Constraints, Cost,options);
The only problem, unavoidable, is the execution time because the horizon is very big P = 1500