Lagrange Multipliers
Military Trouble Spots Example

(* Three unit vectors on the sphere *)
p[1] = {5/13,12/13,0};
p[2] = {12/13,5/13,0};
p[3] = {3/13,4/13,12/13};
{Norm[p[1]],Norm[p[2]],Norm[p[3]]}

(* First we do burrowing through the Earth distance-squared *)
D1[x_,y_,z_] := 13 Sum[(x-p[i][[1]])^2 + (y - p[i][[2]])^2+(z-p[i][[3]])^2,{i,1,3}]

D[x,y,z]
Expand[D1[x,y,z]]

Expand[{D[D1[x,y,z],x], D[D1[x,y,z],y], D[D1[x,y,z],z]}]

Solve[{{-40+78 x,-42+78 y,-24+78 z} == 2 w {x, y, z}, x^2 + y^2 + z^2 == 1}, {w,x,y,z}]

D1[4. (Sqrt[(5/197)]),(21/(Sqrt[985])),(12/(Sqrt[985]))]
D1[-4. (Sqrt[(5/197)]),-(21/(Sqrt[985])),-(12/(Sqrt[985]))]
Sqrt[D1[4. (Sqrt[(5/197)]),(21/(Sqrt[985])),(12/(Sqrt[985]))] / 13]

N[p[1]]
N[p[2]]
N[p[3]]
opt1 = N[{4. (Sqrt[(5/197)]),(21/(Sqrt[985])),(12/(Sqrt[985]))}]

Plot3D[{x,y,Abs[Sqrt[1-x^2-y^2]]}, {x,0,1}, {y,0,Abs[Sqrt[1-x^2]]}]

(* Second we do burrowing through the Earth distance- what a mess! *)
D2[x_,y_,z_] := Sum[Sqrt[(x-p[i][[1]])^2 + (y - p[i][[2]])^2+(z-p[i][[3]])^2],{i,1,3}]
Expand[{D[D2[x,y,z],x], D[D2[x,y,z],y], D[D2[x,y,z],z]}]

?FindMinimum

FindMinimum[{D2[x,y,z], x^2 + y^2 + z^2 == 1}, {{x,.6},{y,.6},{z,.3}}]

(* Third method: 
measure distance by 1 - cos(angle) *)
D3[x_,y_,z_] :=2  * 13 *  Sum[(1 - {x,y,z}.p[i]), {i,1,3}]

Expand[D3[x,y,z]]

lambda = Sqrt[20^2+21^2+12^2]

20./Sqrt[985]

D3[20./Sqrt[985], 21./Sqrt[985], 12./Sqrt[985]]

(* Fourth method: 
measure distance by sin(angle) *)
D4[x_,y_,z_] := 13^2 *  Sum[Cross[{x,y,z},p[i]] . Cross[{x,y,z},p[i]], {i,1,3}]

Expand[D4[x,y,z]]

329 (x^2)-264 x y+322 (y^2)-72 x z-96 y z+363 (z^2)

Expand[{D[D4[x,y,z],x], D[D4[x,y,z],y], D[D4[x,y,z],z] }]

NSolve[{{658 x-264 y-72 z,-264 x+644 y-96 z,-72 x-96 y+726 z} == 2 w {x,y,z}, x^2+y^2+z^2 == 1}, {w,x,y,z}]

D4[0.6984499726061706`,-0.7095179344272434`,0.09355178508471927`]
D4[0.6593007671819094`,0.6887724929072444`,0.30152106295860254`]

(* Fifth method: 
correct anglular distance) *)
D4[x_,y_,z_] :=   Sum[ArcCos[p[i].{x,y,z}], {i,1,3}]
FindMinimum[{D4[x,y,z], x^2+y^2+z^2 == 1}, {x,y,z}]

FindMinimum[{D4[x,y,z],(x^2)+(y^2)+(z^2)==1},{{x,.6},{y,.6},{z,.3}}]

{1.8497561696418874`,{x->0.6594408561324766`,y->0.7137805980311105`,z->0.23591315169660107`}}

D[ArcCos[x],x]