Chapter 26

Numerical Solutions to Nonlinear Systems: Newton’s Method

26.1 Introduction

Having derived some of the most common methods for solving linear systems of equations, we will now turn to a significantly more common problem, i.e., finding solutions to nonlinear systems of equations. In these equations the independent variables are given in the form of nonlinear equations, e.g., as sine or cosine functions, polynomials, and exponentials. Again, we will encounter a system of equations of the form

f0(x0,x1,,xn)=0f1(x0,x1,,xn)=0f2(x0,x1,,xn)=0fn(x0,x1,,xn)=0

si1_e  (Eq. 26.1)

where fn are nonlinear functions. Again, we are interested in the solution vectors xisi2_e (which are commonly referred to as roots) that will turn the vector function fsi3_e into the zero vector

f(xi)=0

si4_e

This problem has been studied by countless mathematicians, but the methods are commonly associated with Newton who studied methods for finding roots of polynomials using these methods [1]. The first known application of what was to be referred to as Newton’s method was introduced by Simpson1 in 1740 [2].

26.2 An Example: The Loran System

As we have seen, linear systems of equation usually do not require numerical methods to solve them, as there are several convenient methods by which they can be solved. However, if a system of equations contains nonlinear terms, it becomes significantly harder to solve. For example, consider the following set of equations with the two independent unknowns x and y:

(x+200)2+y2(x200)2+y2=96.84(x+200)2+y2(x200)2+(y+100)2=77.75

si5_e

We will momentarily discuss where these equations come from. Note that in theory this system of equations is solvable because we have two equations for two unknowns. However, both of these unknowns occur in a nonlinear form. In order to solve such equations, one generally has to default to numerical methods because analytical solutions are usually not possible.

We will briefly outline where this example stems from before we derive suitable solutions for it. These equations are used by the long range navigation (LORAN) system, which is a radio system used for determining position at sea. The system is actually very simple and can be quickly explained. It is based on beacons with known geopositions that emit distinctive radio signals. These beacons are typically installed on islands and along the coastlines, although there are also stations inland that allow obtaining position on land as well. A vessel that wants to determine its positions will receive the signals. Each sender can be identified by a distinct code in the transmission signal, thus the receiver knows which beacon is currently received. The signals of the beacons are synchronized, i.e., they are broadcasted with a universally synchronized time stamp that allows the receiver to determine exactly how long the signal has been traveling. Therefore the receiver will receive signals from beacons farther away a little delayed in comparison to beacons that are closer.

Please note that although the LORAN system is considered outdated, the mechanism of position determination is almost identical to the concept used by global positioning system (GPS). Here the beacons are geostationary satellites. The mathematics for determining the position is identical to the one used by LORAN.

One-Beacon Configuration. A single beacon emits a signal that is received in a radius around the beacon. The signal forms an expanding circle around the beacon. A receiver who is closer to the beacon will receive the signal faster than a receiver that is further away. Because the speed at which the signal travels (which is roughly the speed of light) is known, this delay in receiving can be transferred to a distance dM to this beacon. We will suppose a universal reference coordinate system and assume that our beacon is located at the position xM = −200 and yM = 0 given in arbitrary units. If we determine all points in this coordinate system that are dM away from this beacon, we will end up with a circle equation given by

dM=(x+200)2+y2

si6_e  (Eq. 26.2)

So if a vessel receives the signal from this first beacon, which is usually referred to as “master beacon” (thus the index M), the vessel knows that it must be at one of the pairs (x, y), for which Eq. 26.2 is fulfilled. Unfortunately, it is not possible to determine dM from just one signal. As stated, the system makes use of the delay between two signals. This difference in receiving the signals can be translated to a distance. Therefore we need a second beacon.

Two-Beacon Configuration. We therefore add a second beacon that we term A. Its position is xA = 200 and yA = 0. Here again we derive a circle equation given by

dA=(x200)2+y2

si7_e  (Eq. 26.3)

Now a receiver can detect the time difference between receiving a signal from the master beacon M and from the second beacon A. This distance in time can be converted to a distance in space assuming the speed of light as the travel speed of the signal. This value is given as dAM, which is the difference in distance between dM and dA:

dAM=dMdA=(x+200)2+y2(x200)2+y2

si8_e  (Eq. 26.4)

Let us assume that the value determined is dAM = 96.84. Now Eq. 26.4 gives us one equation. In order to solve both x and y, we need another equation. However, we can already determine all pairs of (x, y) for which Eq. 26.4 is fulfilled, as illustrated in Fig. 26.1a. Here we depicted the master beacon M as well as the beacon A. In this image we have already revealed the location of the vessel S, which we still need to actually determine. In this graph you can see the equidistance lines for Eq. 26.4. For a given value of dAM, we can determine on which line the ship will be, although we cannot determine the position more precisely at this moment.

f26-01-9781455731411
Fig. 26.1 Example of a nonlinear system: the LORAN system. The system uses a master beacon M and two additional beacons A and B in order to determine the positions of a ship or vessel S. Comparing the signals of M and A allows determining the difference in distance between the master beacon and beacon A, from which an equidistance map can be created (a). The values indicated are differences in relative distance in increments of 50 with positive values indicating the vessel is closer to A than to M and v.v. Using beacon B, we can create a second equidistance map (b). The vessel will be located at the intersection of the two equidistant lines.

Three-Beacon Configuration. This we can do only by adding a third beacon B for which we choose the coordinates xB = 220 and yB = −100. This beacon is shown in Fig. 26.1. Again, we find a circle equation given by

dB=(x220)2+(y+100)2

si9_e  (Eq. 26.5)

As for beacon A, we can determine the relative difference in signal receiving between the master beacon and beacon B from which we can derive the difference in distance dBM between dM and dB as

dBM=dMdB=(x+200)2+y2(x220)2+(y+100)2

si10_e  (Eq. 26.6)

For our example, we assume this value to be determined as dBM = 77.75. Eq. 26.6 gives us the second equation. Alone it will allow us to draw another equidistance map, which is shown in Fig. 26.1b. The location of the vessel will then be at the intersection of the equidistance line for dAM = 96.84 shown in Fig. 26.1a and the equidistance line for dBM = 77.75 shown in Fig. 26.1b. The intersection of these two lines is shown in Fig. 26.2. However, we will determine the intersection, i.e., location of the vessel, mathematically. Therefore we are left with the two equations Eq. 26.4 and Eq. 26.6

f26-02-9781455731411
Fig. 26.2 The two equidistance lines determined from the difference in distances between the master beacon M and beacon A as well as for the master beacon and beacon B. In this example dAM = 96.84 and dBM = 77.75. The location of the vessel (or ship S) is at the intersection of the two equidistance lines. In this example the vessel is located at (50, −50).

(x+200)2+y2(x200)2+y2=96.84

si11_e  (Eq. 26.7a)

(x+200)2+y2(x200)2+(y+100)2=77.75

si12_e  (Eq. 26.7b)

which are the equations shown at the beginning of this section.

26.3 Newton’s Method

26.3.1 Derivation

In general, Newton’s method uses the same vector notation as already introduced for linear systems. In this case we find a set of n nonlinear equations for n independent unknowns according to Eq. 26.1. We now consider our unknowns as vector xsi13_e and our functions as a vector function according to

x=(x0x1x2xn),f=(f0f1f2fn)

si14_e

Please note that in contrast to the matrix notation that we used in section 25.2.1.1, we cannot simply create a matrix here because fsi3_e is a function vector, i.e., a vector with a function for each entry. This vector is not (as we are used to working with) a vector with fixed numbers as entries. We can now rewrite our original system of equations as

f(x)=0

si16_e

Because fsi3_e is given, we need to find a vector xsi13_e to which we apply the vector function and obtain in the zero vector 0si19_e, which is a vector with a 0 in all vector entries.

26.3.2 Finite Difference

One-Dimensional Case. In vector notation the finite difference is given as

Δxn=xn+1xn

si20_e  (Eq. 26.8)

We also know that for the linear case we can derive the value of the function f at xn+1 by linearization. For this we take the derivative of the function at xn, i.e., dfdx|xnsi21_e and multiply it by ∆xn given by xn+1− xn

f(xn+1)=f(xn)+dfdx|xn(xn+1xn)

si22_e  (Eq. 26.9)

Please note that this equation stems directly from the definition of the derivative (see Fig. 3.2a). For ∆xn 0 we will obtain the definition of the derivative (see Eq. 3.9).

n-Dimensional Case. Because we have an n-dimensional problem here, we need to take into account the changes of each individual equation fi of our function vector with respect to each variable xj. We therefore require the Jacobian matrix of the function vector fsi3_e. For consistency we will denote the matrix as D, finding

D=(f1x1f1x2f1xnf2x1f2x2f2xnfnx1fnx2fnxn)

si24_e  (Eq. 26.10)

We already encountered the Jacobian matrix during coordinate system transformations (see section 7.5). This matrix effectively represents the changes of our function vector fsi3_e with respect to all independent variables. We will then apply the same linearization as for the one-dimensional case (see Eq. 26.9) in vector notation, finding

f(xn+1)=f(xn)+f|xn(xn+1xn)=f(xn)+D(xn)(xn+1xn)

si26_e  (Eq. 26.11)

Eq. 26.11 gives the analytical correlation between the solution xnsi27_e and the (improved) subsequent solution xn+1si28_e.

Solving forxn+1si28_e. In Newton’s method we are seeking the solution xsi13_e that makes f(x)=0si16_e We can therefore rewrite Eq. 26.11 as

f(xn+1)=f(xn)+D(xn)(xn+1xn)=0

si31_e

which we solve for xn+1si28_e finding

f(xn)+D(xn)(xn+1xn)=0

si32_e  (Eq. 26.12)

D(xn)(xn+1xn)=f(xn)D1(xn)D(xn)(xn+1xn)=D1(xn)f(xn)xn+1=xnD1(xn)f(xn)

si33_e  (Eq. 26.13)

Eq. 26.13 will give the exact solution to our problem. Unfortunately, it requires the inverse of the matrix D, which we are not even sure exists. We therefore need to circumvent this problem.

26.3.3 Simplification of the Newton’s Method: Quasi-Newton Method

A number of methods essentially simplify Eq. 26.13 such that the inverse matrix D1 that is required for evaluating D1 (xnsi27_e) need not be calculated. All of these methods are referred to as quasi-Newton methods because they use the underlying concept of the Newton method but simplify this step. Several noteworthy methods are commonly used, but we will focus on the most simple one. For this we use Eq. 26.12 instead of Eq. 26.13. We rewrite this equation to

D(xn)(xn+1xn)=D(xn)Δxn=f(xn)

si35_e  (Eq. 26.14)

Since we can calculate D and we know xnsi27_e, we obtain a system of n equations from Eq. 26.14 that we solve for n unknowns. The matrix D will contain all nonlinear terms of our problem, which will be converted to numbers once we apply the (known) vector xnsi27_e to it. We are then left with a set of linear equations that we can solve using one of the methods outlined in section 25.2. Solving these equations will give us the vector xn+1si28_e, which we can apply iteratively to Eq. 26.14. We terminate the process once the change in the solutions Δxn=xn+1xnsi20_e is below a certain threshold.

26.3.4 Applying the Newton’s Method to Our Example

We will now demonstrate the Newton’s method for the example of the position determination in LORAN. For this we rewrite Eq. 26.7 to a function vector

f=((x+200)2+y2(x200)2+y296.84(x+200)2+y2(x220)2+(y+100)277.75)

si40_e

Obviously the solution vector is

x=(xy)

si41_e

Calculating the Matrix D. We also require the matrix D for Eq. 26.14. This we find according to Eq. 26.10

D=(fxxfxyfyxfyy)

si42_e

which we carry out to find

D=(x+200(x200)2+y2x200(x200)2+y2y(x+200)2+y2y(x200)2+y2x+200(x200)2+(y+200)2x200(x200)2+(y+100)2y(x+200)2+y2y+200(x+220)2+(y+100)2)

si43_e  (Eq. 26.15)

First Guess. We are now ready to start the numerical solving process. We first require an initial guess for xsi13_e. For the sake of simplicity, we will assume

x0=(00)

si45_e

Next we find D (x0si46_e) for the first estimate x0si46_e which is

D(x0)=(201.910.41)

si48_e  (Eq. 26.16)

Next we find f(x0)si49_e to be

f(x0)=(96.84119.41)

si50_e

Using Eq. 26.14, we carry out the matrix/vector multiplication

(201.910.41)(x10)=(100.910.41)(x1y1)=f(xn)=(96.84119.41)

si51_e  (Eq. 26.17)

from which we derive the two equations

2x1=96.84

si52_e  (Eq. 26.18a)

1.91x10.41y1=119.41

si53_e  (Eq. 26.18b)

As you can see, we now have a linear system of equations that can be solved conveniently (see section 25.2). This system is so easy that we can actually just write the solution for x1si54_e as

x1=(48.4265.68)

si55_e  (Eq. 26.19)

Obviously, this result is not entirely correct. If we look at Fig. 26.2, we see that the position we are seeking is actually (50, −50). But we have definitely approached the solution starting from our initial guess (0, 0).

Iterative Scheme. Now that we have the improved estimate for the position of our vessel, we will repeat this process in order to obtain an even better approximation x2si56_e. However, it makes little sense to do this manually. The strength of numerical solutions is that they can be solved significantly faster by algorithms. Therefore we will implement a small solver in Maple that performs this task for us.

26.4 A Solver Implemented in Maple

We will now implement a small numerical solver in Maple that carries out Newton’s method. In theory, this piece of code will do nothing more than repeat the procedure we conducted once. It will repeatedly come up with better approximations for xnsi27_e until the solution has converged to a point where it is not deemed necessary to become more exact. When this point is reached, it is really up to the application’s setup. In most applications, having a conversion up to three or four digits is sufficient. However, some applications may require a more exact solution.

26.4.1 Helper Function: Matrix/Vector Multiplication

We will begin by implementing three helper functions. The first function will perform a matrix/vector multiplication, which is required for the Newton method. We carried out this multiplication manually in Eq. 26.17.

Just as a quick reminder to matrix/matrix calculus: A n×m matrix can be multiplied only by a m×o matrix. The first number indicates the number of lines; the second number indicates the number of columns. This means that a matrix A can be multiplied only by a second matrix B if the number of lines of the first matrix and the number of columns of the second matrix are identical. The result of this multiplication is a n × o matrix C given by

(A1,1A1,2A1,nA2,1A2,2A2,mAn,1An,2An,m).(B1,1B1,2B1,oB2,1B2,2B2,oBm,1Bm,2Bm,o)=(A1,1B1,1++A1,mBm,1A1,1B1,2++A1,mBm,2A1,1B1,o++A1,mBm,oA2,1B1,1++A2,mBm,1A2,1B1,2++A2,mBm,2A2,1B1,o++A2,mBm,oAn,1B1,1++An,mBm,1An,1B1,2++An,mBm,2An,1B1,o++An,mBm,o)

si58_e

In this multiplication the entry (i, k) of matrix C will be formed by summing the products of ith line of matrix A with the kth column of matrix B, respectively. In our example, we have two equations (Eq. 26.7) and two unknowns. Therefore the matrix we are dealing with is of type 2 × 2. The second matrix is the vector xnsi27_e, i.e., a 2 × 1 matrix (Eq. 26.17). We implement the matrix/vector multiplication as shown in listing 26.1.

Listing 26.1

[Maple] Listing for the matrix/vector multiplication as required for Newton’s method for solving nonlinear systems of equations. This listing is part of the listing NonLinearNewton.mw, which can be found in the supplementary material.

1  DoMatrixVectorMult:=proc(D::Matrix,v::Matrix,n) local i,j,ret:
2    ret:=Matrix(n,1):
3    for i to n do
4      for j to n do:
5        ret[i,1]:=D[i,j]*v[j,1]+ret[i,1]:
6      end do:
7     end do:
8     return ret;
9  end proc:

The function is termed DoMatrixVectorMult, and it expects a quadratic matrix with m = n number of lines and columns given by the parameter n. The input matrix D is given as a matrix as is the input vector v. The matrix is expected to be a n × n matrix and the vector to be a n × 1 matrix. The output ret therefore is a n × 1 matrix, i.e., a vector. The function then iterates over the lines i and sums the columns j. Please note that Maple has built-in functions for matrix multiplication, but the version used in listing 26.1 is so straightforward that it can be ported to any programming language.

26.4.2 Helper Function: Matrix Evaluation

The second helper function we will implement will evaluate a matrix function when supplied with a given value vector. We require this function for evaluating the matrix D using the value vector xnsi27_e as we did for finding D (x0si46_e) in Eq. 26.16.

The function is shown in listing 26.2. It expects the n × n matrix function D in the form of a matrix of functions of n independent variables. The parameter values holds the numeric values to insert into the matrix function. The return value ret will of course be an n × n matrix again. The function then merely calls the individual entry (i, j) of D providing the values given for the respective independent variable. This is done by the respective Maple command seq, which yields a sequence, i.e., a comma-separated list of the values. As you can see in the way line 5 is written, the code simply calls the entry (i, j) of the matrix using the values provided. Because the entry of the matrix is expected to be a function, this notation is equivalent to calling a function in Maple with the values for the variables in bracket.

Listing 26.2

[Maple] Listing for matrix evaluation as required for Newton’s method for solving nonlinear systems of equations. This listing is part of the listing NonLinearNewton.mw, which can be found in the supplementary material.

1  DoEvaluateMatrix:=proc(D::Matrix,values::Matrix,n) local i,j,ret:
2    ret:=Matrix(n,n):
3    for i to n do
4     for j to n do:
5      ret[i,j]:=D[i,j](seq(values[k,1],k=1..n)):
6     end do:
7    end do:
8  return ret;
9  d proc:

26.4.3 Helper Function: Vector Evaluation

The last helper function we require is very similar to the one we just implemented. It evaluates a function vector using a value vector. The function is shown in listing 26.3. As you can see, the only difference is that the helper function expects the input vector v to be a n × 1 matrix. Therefore we do not have to sum over the columns j, which makes the listing a bit more compact. Except for this detail the implementations are identical.

Listing 26.3

[Maple] Listing for vector evaluation as required for Newton’s method for solving nonlinear systems of equations. This listing is part of the listing NonLinearNewton.mw, which can be found in the supplementary material.

1  DoEvaluateVector:=proc(v::Matrix,values::Matrix,n) local i,ret:
2  ret:=Matrix(n,1):
3    for i to n do
4      ret[i,1]:=v[i,1](seq(values[k,1],k=1..n)):
5    end do:
6    return ret;
7  end proc:

26.4.4 Listing for Newton’s Method

Having implemented the preceding three helper functions, we are now ready to implement Newton’s method.

The code is shown in listing 26.4. It begins as usual by restarting the Maple server and including Core.txt (see line 1). We then implement the three helper functions DoMatrixVectorMult, DoEvaluateMatrix, and DoEvaluateVector whose listings we have already discussed. The implementation of these functions is not repeated in this listing; please refer to listing 26.1, listing 26.2, and listing 26.3 for details on these functions. The function DoNonlinearNewton implements Newton’s method. The function expects a list of nonlinear equations equations that needs to be solved for a list of independent variables given in variables using the initial values initial. The function also expects a maximum number of steps maxsteps to perform.

Listing 26.4

[Maple] Listing for Newton’s method for solving nonlinear systems of equations. This listing is part of the listing NonLinearNewton.mw, which can be found in the supplementary material.

1  restart;read("Core.txt"):
2
3  #matrix/vector multiplication
4  DoMatrixVectorMult:=proc(D::Matrix,v::Matrix,n) local i,j,ret:
5
6  #function matrix evaluation using a value vector
7  DoEvaluateMatrix:=proc(D::Matrix,values::Matrix,n) local i,j,ret:
8
9  #function vector evaluation using a value vector
10  DoEvaluateVector:=proc(v::Matrix,values::Matrix,n) local i,ret:
11
12  #this function solves a non-linear system of equations using Newton's method
13  DoNonlinearNewton:=proc(equations::list,variables::list,initial::list,maxsteps) local n,i,j,k,s,xn, D,Dxn,f,fxn,dx,lhs,sol:
14    #check for consistency
15    n:=numelems(equations):
16    if numelems(variables)<>n or numelems(initial)<> n then
17      print ("Require same number of equations, variables and initial values"):
18      return:
19    end if:
20    #construct D
21    D:=Matrix(n,n):
22    for i to n do
23      for j to n do
24       D[i,j]:=unapply(diff(equations[i],variables[j]),seq(variables[k],k=1..n));
25      end do:
26    end do:
27    #construct the function vector f
28    f:=Matrix(n,1):
29    for i to n do
30      f[i,1]:=unapply(equations[i],seq(variables[k],k=1..n)):
31    end do:
32    #this holds the current value for xn - prime with the initial values
33    xn:=Matrix(n,1):
34    for i to n do
35      xn[i,1]:=initial[i]:
36    end do:
37    #differential vector
38    dx:=Matrix([seq([Delta[k]],k=1..n)]):
39    #now we iterate until maxsteps
40    for s to maxsteps do
41      #output to the user
42      print(sprintf(`step: %d, %s`,s,cat(seq(sprintf("%a=%a ",variables[k],xn[k,1]),k=1..n)))):
43      #calculate f(xn) and D(xn)
44      fxn:=DoEvaluateVector(f,xn,n):
45      Dxn:=DoEvaluateMatrix(D,xn,n):
46      #perform the matrix vector multiplication
47      lhs:=DoMatrixVectorMult(Dxn,dx,n):
48      #solve the new system of equations
49      try
50        sol:=solve({seq(lhs[k,1]=-fxn[k,1],k=1..n)},{seq(dx[k,1],k=1..n)}):
51        #adapt xn
52        for i to n do
53          xn[i,1]:=evalf(xn[i,1]+rhs(sol[i])):
54        end do:
55      catch:
56        print("no solution to linear systemml: ",seq(lhs[k,1]=-fxn[k,1],k=1..n));
57        return;
58     end try;
59   end do:
60  end proc:

In line 15 the function first checks for consistency. The number of equations n must match the number of unknown variables given as a list in variables and the number of initial values provided in initial. If this prerequisite is not met, the function quits by printing an error message. In line 21 the matrix D is created as an n × n matrix. The entry (i, j) of D is created by finding the derivative of the ith equation given with respect to the jth independent variable. The result of this diff operation is turned into a function of the independent variables (again given as a sequence) by performing an unapply operation.

In pretty much the same way, we then create the function vector f by performing an unapply operation to the ith equation of equations line 30. In the next step, the current estimation xnsi27_e for xsi13_e is created as a n × 1 vector (see line 33). The first assumption for xnsi27_e is the initial values given to the function as the parameter initial. The last step before starting the iteration is the definition of the differential vector dx according to Eq. 26.14 in line 38. Please note that we do not directly derive xn+1si28_e here, but rather the difference vector Δxnsi66_e which is why we later have to add this delta value to the last estimate of the solution xnsi27_e (see line 53). dx is a n × 1 matrix that is filled with the values Delta[1], Delta[2], etc. They will be the independent variables for which we solve the system of linear equations we obtain.

The loop incorporates the iterative scheme of Newton’s method. We iterate s to a total number of maxsteps (see line 40). We first output the current step s and the values for the independent variables. This happens in line 42. This lines uses print to output a string created by sprintf. This function creates formatted string output. The function cat joins strings. Here it outputs the individual independent variables variables as a sequence using the form “name=current value”. This helps us keep track of the current value of our approximations.

The following lines implement the scheme we already performed manually. First, the function vector f and the matrix D are evaluated for the current value vector xn using the two helper functions DoEvaluateVector and DoEvaluateMatrix we previously implemented (line 44 and line 45). We then perform a matrix/vector multiplication using the helper function DoMatrixVectorMult we also implemented previously (see line 47). For this we use the evaluated matrix D (xnsi27_e) and the differential vector Δxnsi66_e. In our manual example, we performed this multiplication in Eq. 26.17. We were then left with a system of linear equations in Eq. 26.18. The same thing happens at this point. We now need to solve this system. This happens in the code lines starting from line 49. In line 50 we call solve to make Maple solve the system of linear equations given by Eq. 26.14. Because we have a total of n equations, we provide these in form of a sequence that Maple should solve for the unknown variables dx[1], dx[2], etc. We store the solution in sol from which we extract the individual values for the variables using the function rhs that extracts the right-hand side of an equation. We then correct our original assumption for the kth variable by the correction dx[k]. As stated this procedure is slightly different from the first manual step we performed in Eq. 26.17 where we used the vector xn+1xnsi70_e instead of Δxnsi66_e. This is why we need to correct xnsi27_e by Δxnsi66_e in line 53. Having corrected the assumption, this process is repeated for a total of maxsteps iteration.

It is also possible to check whether the value dx is smaller than a given threshold, i.e., if the solution can be considered sufficiently exact. At this point the function can be aborted.

You may have noted that the call to solve is embedded in a try/catch block (see line 49). This is due to the fact that the algorithm may run into equations that cannot actually be solved. We will look at an example of such a call in just a moment. If this happens, the algorithm obviously cannot continue and aborts by providing an error message to the user.

26.4.5 Using the Solver

We are now ready to apply the solver we just implemented to solve Eq. 26.7, which we obtained from the LORAN positioning system. Listing 26.5 shows how to apply the function DoNonlinearNewton to Eq. 26.7. We provide the two equations and the two unknowns x, y in list form to the function. We also need to provide an initial estimation.

Listing 26.5

[Maple] Listing for applying the Newton’s method solver for the example of the LORAN positioning system. This listing is part of the listing NonLinearNewton.mw, which can be found in the supplementary material.

1 DoNonlinearNewton([sqrt((x+200)^2+y^2)-sqrt((x-200)^2+y^2)-96.84,sqrt((x+200)^2+y^2)-sqrt((x-220) ^2+(y+100)^2)-77.75],[x,y],[0,0],20);
2 DoNonlinearNewton([sqrt((x+200)^2+y^2)-sqrt((x-200)^2+y^2)-96.83,sqrt((x+200)^2+y^2)-sqrt((x-220) ^2+(y+100)^2)-77.75],[x,y],[-100,600],20);

Here we will see a good example of why it is important to provide reasonable and often initial values which are close to the actual solution. We start with line 1 where we assume a first estimate of (0, 0). If this code is run, Maple will output the current step and the current values for x and y. The values are given in Tab. 26.1.

Tab. 26.1.

Values obtained from the solver implementing Newton’s method when applied to the equations obtained from the LORAN positioning system using the initial values (0, 0). As you can see, the solver converges very quickly to the correct solution (50, −50), which is the location at which the vessel is located (see Fig. 26.2).

Stepsxsys
10.000 000.000 00
248.420 00-65.033 31
349.930 58-49.852 17
450.001 13-49.994 31
550.001 15-49.994 25
650.001 15-49.994 25
750.001 15-49.994 25
850.001 15-49.994 25
950.001 15-49.994 25
1050.001 15-49.994 25
1150.001 15-49.994 25
1250.001 15-49.994 25
1350.001 15-49.994 25
1450.001 15-49.994 25
1550.001 15-49.994 25
1650.001 15-49.994 25
1750.001 15-49.994 25
1850.001 15-49.994 25
1950.001 15-49.994 25
2050.001 15-49.994 25

t0010

As you can see, the first run assumes our initial values (0, 0). At the end of the first iteration, we obtain the corrected values we obtained while performing the algorithm manually (see Eq. 26.19). The values are not exactly the same because during the manual derivation, we considered only 2 decimals, whereas our numerical solver operates at machine-precision. Interestingly, at the end of the second iteration, the results have almost converged to the correct solution. From Fig. 26.2 we know that the vessel is located at (50, −50). After the fifth iteration, the solver has reached a stable solution, and the output does not change. This is the point where the algorithm could be aborted. If higher precision is required, the general settings of Maple must be changed, i.e., the number of decimal places to which a numerical value is evaluated must be increased.

As can be seen, the implemented solvers find a solution to this set of nonlinear equations pretty fast. In the next step, we will try to solve the same equations using a different set of initial values.

A Common Case: A Solver Finds No Solution. For the second example, we use the initial values (−100, 600) (see line 2). As you can see from Fig. 26.1, this first estimate is not too far off the actual solution. If the ship was to determine its position for the first time, there would be no way of determining whether (0, 0) or (−100, 600) would be the better initial assumption. Running this line of code will output the values shown in Tab. 26.2.

Tab. 26.2.

Values obtained from the solver implementing Newton’s method when applied to the equations obtained from the LORAN positioning system using the initial values (−100, 600). As you can see, the solver aborts after 11 steps.

Stepsxsys
1-1.000 00×10+26.000 00×10+2
21.442 66×10+3-7.926 28×10+3
3-1.628 60×10+68.956 32×10+6
43.948 69×10+10-2.171 22×10+11
5-7.912 29×10+101.798 11×10+11
6-1.703 62×10+119.019 33×10+11
72.232 98×10+119.273 26×10+10
8-1.525 14×10+111.308 93×10+11
91.870 76×10+111.944 93×10+11
101.125 26×10+112.421 93×10+11
115.171 26×10+119.274 80×10+11

t0015

As you can see, the solver will perform only 11 steps during which the solution values grow continually. At the end of step 11, the solver will abort with an error message saying

no solution to linear systemml: 0 = 96.83

Obviously, this system of equations cannot be solved as 0 6 = 96.83. This is a good example of what happens when a bad initial value is supplied to a solver and why we had to account for similar problems by employing the try/catch construction in line 49. Numerical solvers will eventually choke on some bad initial values throwing comparable error messages.

When employing a numerical solver, it is always a good idea to learn as much about the problem at hand as possible in order to provide good initial values. If this is not possible, the initial values must be estimated, and a trial-and-error approach must be used. For this initial values are varied until the solver converges. However, even then it is important to validate the results obtained in order to ensure that they are physically meaningful. In the case of the LORAN system, we may come across locations that give rise to more than one solution. The vessel then will need to estimate which of the solutions obtained are correct. This can be done by picking up more signals from other beacons and checking whether the solutions obtained have one common location. A second approach may be to track the location over time, in which case all solutions that are too far away from the last known location can be discarded.

Physically Nonmeaningful Results. We encountered an example where physically nonmeaningful results can be obtained from a numerical solver while studying the pendant drop equations (see section 24.5). We found that several of the results that we found numerically are physically impossible because the drop volumes do not increase and there is a discontinuity in the drop volumes (see Fig. 24.9b). In all cases the solutions found are mathematically correct but not physically correct. Therefore it is always important to validate a numerically obtained solution for its physical significance.

26.5 Summary

In this section we studied Newton’s method for solving nonlinear systems of equations. Numerical methods are essential to solving nonlinear systems because it is usually not possible to find analytical solutions to these systems. As an example, we used the LORAN positioning system, which requires a solution to a system of nonlinear equations. We performed a first iteration of Newton’s method by hand before implementing a small solver in Maple, which allowed us to find the solution conveniently. Obviously, this solver can also be used to solve different systems of nonlinear equations and it is a handy tool when working with the elementary equations in fluid mechanics. We also studied the importance of the initial values and saw an example of our solver dead-locking when supplied with bad initial values.

References

[1] Newton I. De analysi per aequationes numero terminorum infinitas. 1711 (cit. on p. 537).

[2] Simpson T. Essays on several curious and useful subjects. 1740 (cit. on p. 537).


1 Thomas Simpson was a self-taught English mathematician. He was the son of a weaver and worked as a weaver for the most part of his life teaching mathematics in his spare time. He became professor for mathematics at the Royal Academy of Wollwich in 1743. Simpson is renowned for his work on integral theory, but he was also the first to employ what is now known as Newton’s method for finding the roots of nonlinear systems of equations [2].

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset