4

I'm facing the following problem: Given an implicit curve given by $f(x,y)=0$ and an initial guess $(x_0,y_0)$ which is hopefully close to the curve, I want to find the point $(x,y)$ on the curve which is closest to $(x_0,y_0)$.

My attempt:

I thought of using FindRoot with the equation repeated twice, i.e.

FindRoot[{f[x,y],f[x,y]},{{x,x0},{y,y0}}]

But this fails spectacularly with $f(x,y)=y-x^2$ and initial points $(0,y_0)$ with $y_0$ large.

Is there a good way to solve this problem?

Thanks!

user1337
  • 1,068
  • 6
  • 13

1 Answers1

12

RegionNearest will do this automatically for many cases, including $y-x^2=0$:

RegionNearest[ImplicitRegion[y - x^2 == 0, {x, y}], {0, y0}]

Mathematica graphics

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263