Newton’s Method in n dimensions.
A worked example: inverse kinematics.

Step 1. The form of the Newton iteration.

Suppose we have a function (OverVector[F]): (ℝ^n)-> (ℝ^n), and we want to find points (OverVector[x]) where 

(OverVector[F])((OverVector[x])) = (OverVector[0])

The Newton iteration is

(Subscript[(OverVector[x]), i+1 ])=(Subscript[(OverVector[x]), i])-(((D (Subscript[(OverVector[F]), (Subscript[(OverVector[x]), i])])))^(-1))((OverVector[F])((Subscript[(OverVector[x]), i]))) 

which really is the vector analogue of the scalar Newton iteration

(Subscript[x, i+1])= (Subscript[x, i ])- ((f((Subscript[x, i])))/(f'((Subscript[x, i]))))

especially if we (deliberately) confuse the notation for “-1st power” and “inverse” and write the scalar Newton iteration as

(Subscript[x, i+1 ])= (Subscript[x, i])- (((f'((Subscript[x, i]))))^(-1))f((Subscript[x, i])).

A more applied example: a robot arm.

Suppose that we have a robot arm in the plane with two rotary joints. We know that the end position of the arm is given by the two joint angles:

ArmPos[{θ1_,θ2_}] := {Cos[θ1],Sin[θ1]} + {Cos[θ2],Sin[θ2]};

ArmGraphic[{θ1_,θ2_}] := Graphics[{FaceForm[Gray],EdgeForm[Black],
Rotate[Rectangle[{-0.05,-0.05},{1.05,0.05},RoundingRadius->0.05],θ1,{0,0}],
Translate[Rotate[Rectangle[{-0.05,-0.05},{1.05,0.05},RoundingRadius->0.05],θ2,{0,0}],{Cos[θ1],Sin[θ1]}],
{PointSize[Large],Black,Point[ArmPos[{θ1,θ2}]],Point[{Cos[θ1],Sin[θ1]}],Point[{0,0}]},{Dotted,Red,Circle[{0,0},2]}},Axes->True,PlotRange->{{-2,2},{-2,2}},ImageSize->Large];

Manipulate[ArmGraphic[{θ1,θ2}],{θ1,0,2π},{θ2,0,2π}]

The inverse kinematics problem.

Usually, we don’t think about joint angles that we’d like the robot to adopt, but rather positions that we’d like for the end of the arm.
So we’d like to solve the “inverse kinematics” problem of finding joint angles which result in the end of the arm being at a particular target location ((Subscript[t, x]),(Subscript[t, y])) in the plane. We can write this problem in “Newton form” by writing it as the equation

 ArmError((Subscript[θ, 1]),(Subscript[θ, 2]);(Subscript[t, x]),(Subscript[t, y])) = ArmPos((Subscript[θ, 1]),(Subscript[θ, 2])) - ((Subscript[t, x]),(Subscript[t, y])) 
 
 If we fix (Subscript[t, x]) and (Subscript[t, y]) then the resulting function
 
 ArmError((Subscript[θ, 1]),(Subscript[θ, 2])) : (ℝ^2)-> (ℝ^2)
 
 and we can apply Newton’s method to find solutions of 
 
 ArmError((Subscript[θ, 1]),(Subscript[θ, 2])) = (0,0)

ArmError[{θ1_,θ2_},{tx_,ty_}] := ArmPos[{θ1,θ2}] - {tx,ty};

To write down the Newton iteration, we need to compute D(ArmError) which should be a 2x2 matrix.
We could do this by hand, but why bother when we have Mathematica!

D[ArmError[{θ1,θ2},{tx,ty}],{{θ1,θ2}}] // MatrixForm

We can invert this symbolically:

FullSimplify@Inverse[D[ArmError[{θ1,θ2},{tx,ty}],{{θ1,θ2}}]] // MatrixForm

Solving for the Newton iteration as a linear system.

But in practice, you may not be given the Jacobian of the function as a formula, just as piece of code that you can call. To handle this, we return to the basic equation

(OverVector[h])= -(((D (Subscript[(OverVector[F]), (Subscript[(OverVector[x]), i])])))^(-1))((OverVector[F])((Subscript[(OverVector[x]), i])))

and realize that if we apply D (Subscript[(OverVector[F]), (Subscript[(OverVector[x]), i])]) to both sides of the equation, we get the linear system of equations:

(D (Subscript[(OverVector[F]), (Subscript[(OverVector[x]), i])])) (OverVector[h]) = -(OverVector[F])((Subscript[(OverVector[x]), i])) 

This means that given

ArmErrorJacobian[{θ1_,θ2_},{tx_,ty_}] := {{-Sin[θ1],-Sin[θ2]},{Cos[θ1],Cos[θ2]}};

we can write the Newton iteration as

ArmNewtonIteration[{θ1_,θ2_},{tx_,ty_}] := {θ1,θ2} + LinearSolve[ArmErrorJacobian[{θ1,θ2},{tx,ty}],-ArmError[{θ1,θ2},{tx,ty}]];

Just to check it out, we try reaching for a spot that ought to be well within range: {1.2,1.2}.

Nest[ArmNewtonIteration[#,{1.2,1.2}]&,{0.0,1.0},19]

ArmPos[%]

Solving the problem dynamically

Now the beauty of Newton iteration is that it’s very good at adjusting a solution as the problem changes continuously, after all, the current solution to the problem is an excellent starting point for the iteration for a slightly different problem. So we can first define:

ArmUpdate[{θ1_,θ2_},{tx_,ty_}] := 
Nest[ArmNewtonIteration[#,{tx,ty}]&,{θ1,θ2},20];

This converges in a few thousandths of a second on my laptop

ArmUpdate[{0.0,1.0},{1.2,1.2}] // Timing

Now we’ll make a little demonstration using this principle.

Now we can update this as we change the location of the point. We’ll start by setting some base angles.

θold = {0.22779933669791172`,1.342996990096985`};

Now we can write a Manipulate which updates the arm angles every time we move the point:

Manipulate[
θnew = ArmUpdate[θold,pt];
θold= θnew;
ArmGraphic[θnew],
{{pt,{1.2,1.2}},Locator}]