Whichever point maximizes (minimizes) the square of the distance to the point (1,2,2) also maximizes (minimizes) the distance to the point. So the function you want to optimize is . You need to find points on the sphere where the gradient of f is a scalar multiple of the gradient of g. What you have written down is not the gradient of f, by the way. The gradient of f is the vector <2x, 2y, 2z>. The gradient of g is <2(x-1), 2(y-2), 2(z-2)>. Let one gradient be a scalar multiple of the other. This gives you 3 equations (one for each component of the vector). The fourth equation is the equation of the sphere. You have four variables (including the scalar multiple, which is usually denoted by ). I'll let you work it from here.