This is a constrained optimization problem, so we need Lagrange multipliers.
We are constrained to the given surface, so we'll start by writing it in level-set form:
We use the level set form because we want our gradient to produce vectors that are perpendicular to the surface. Other than that, there's nothing special about the level set and it does not change the surface at all. It's a shift in thinking: instead of dealing with z=f(x,y), we rewrite it to be 0 = f(x,y)-z = g(x,y,z).
Additionally, writing the constraint in level-set form changes it from a function of two variables [f(x,y)] to a function of three variables [g(x,y,z)], so it will now match dimensions with the function in the next section.
The function we are optimizing ("objective function") is the distance from the origin.
f(x,y,z)=√[x2+y2+z2] (a function of three variables)
This function is fine for optimization, but the square root will make our derivatives a bit messy. We can choose to optimize the square distance instead, which will preserve our maxima/minima (if we have a set of numbers arranged from smallest to largest and then square them, they will still be arranged in ascending order)
Now we can apply the Lagrange multiplier equation and solve the resulting system of equations:
∇f=λ∇g (unknowns are x, y, z, and λ, so we require 4 equations to solve)
<2x, 2y, 2z> = <2λ(x-1), 2λ(y-1), -2λz>
Set vector components equal to one another to obtain first three equations; fourth equation is the level-set constraint written earlier (g=0)
From Eqn3, we get λ=-1. Substituting this value into Eqn1 and Eqn2 give us x=1/2 and y=1/2. Then substituting those values into Eqn4 results in z=1/√2.
The point on the given surface that is closest to the origin is (1/2, 1/2, 1/√2), which is a distance of √[1/4+1/4+1/2]=√1=1 away from the origin.