MATLAB: Projection of a point onto a closed convex

projection

I have a point P(50, 5000) and a curve (x.^2 – 2*x – 1) with x = [0:100]. How do I find the closest point on that curve to point P?
Thank you.

Best Answer

Q=[50;5000];
% Projection candidates on x.^2-2*x-y-1 = 0
P=ConicPrj(Q,[1 0; 0 0],[-2;-1],-1);
% Find the closest
[~,loc]=min(sum((P-Q).^2,1));
P=P(:,loc);
x=P(1)
y=P(2)
The projection is
x = 71.723733062992125
y = 4.999846418365362e+03