That's true, I was applying sqrtm wrongly in the comment. Sorry for that.
Thank you for your suggesting about squaring the expression about the magnitude of the velocity. It helped a lot. Now I am struggling with the solutions that the different solvers give for the same problem. I simplify it so I am not applying any new constraint, but only calculating the square of the magnitude of the velocity. The st vector is [x, y, vx, vy, v2] where v2 is a variable representing v^2 (MATLAB code attached). The constraints would look like this (note that st{1,k}(1,5) is not squared anymore):
for k = 1:Np
% Cost function
objective = objective + u{1,k}(3,1);
% If we assume the control is constant on every time step we can integrate easily this model
constraints = [constraints, st{1,k+1}(1,1) == u{1,k}(1,1)*dt^2 + st{1,k}(3,1)*dt + st{1,k}(1,1)];
constraints = [constraints, st{1,k+1}(2,1) == (u{1,k}(2,1)-env)*dt^2 + st{1,k}(4,1)*dt + st{1,k}(2,1)];
constraints = [constraints, st{1,k+1}(3,1) == u{1,k}(1,1)*dt + st{1,k}(3,1)];
constraints = [constraints, st{1,k+1}(4,1) == (u{1,k}(2,1)-env)*dt + st{1,k}(4,1)];
constraints = [constraints, st{1,k}(5,1) == st{1,k}(3,1)^2 + st{1,k}(4,1)^2]; % V^2 == Vx^2 + Vy^2
% Limits on the control
constraints = [constraints, norm([u{1,k}(1,1),u{1,k}(2,1)]) <= u{1,k}(3,1)];
constraints = [constraints, 0 <= st{1,k}(2,1)]; % The Y must be always positive
constraints = [constraints, 0 <= u{1,k}(2,1)]; % The thrust in Y must be positive semidefinite.
% constraints = [constraints, 0 <= st{1,k}(5,1) <= 100];
end
% Terminal time constraints
constraints = [constraints, st{1,Np+1}(1,1) == xf];
constraints = [constraints, st{1,Np+1}(2,1) == yf];
constraints = [constraints, st{1,Np+1}(3,1) == Vxf];
constraints = [constraints, st{1,Np+1}(4,1) == Vyf];
constraints = [constraints, st{1,Np+1}(5,1) == Vxf^2 + Vyf^2];
The results with SeDuMi and MOSEK are practically the same (the output marks it is "Successfully solved"):
As you can see, the last row, which is the v2, is not calculated, but I do not understand why. The constraint st{1,k}(5,1) == st{1,k}(3,1)^2 + st{1,k}(4,1)^2; % V^2 == Vx^2 + Vy^2 is basically a cone and Vx and Vy are defined by the constraints above.
However, if I run the code with fmincon the correct values are shown in the 5th row (the output marks it is "Maximum iterations or time limit exceeded "):
so I am not sure what I am doing wrong..
Any advise would be more than appreciated.
Thank you for all your help.