You are on page 1of 12

Solving Problems Involving Algebraic Equations

Single Nonlinear Equations


Live solution versus Goal Seek & Solver
Spherical Tank Problem

b g

h 2 3R h
V
3
V

Goal: Calibrate a tape scale for the sight gauge in convenient increments of volume.
Given R and various values of V, determine corresponding values of h.

h 3 3Rh 2
Methods:

3V
0

Bisection
False Position
Newton
Fixed-Point Iteration (Direct Substitution)
Wegstein Accelerator
See workbook file TANK.XLS.

Solving Equations with the Bisection Method


The bisection method is a simple, bracketing technique for finding a root of a single, nonlinear
equation, f x 0 . To initiate the method, two starting guesses, x L and x H , are required, and
these guesses must lie on each side of the root location, such that
sign. See the diagram below.

f xL

and

f xH

are of opposite

f(x)
f(xH)

xL

xH
f(xL)

The bisection method then determines the next approximation to the solution to be

xN

xL xH
2

and x N replaces either x L or x H for the next round of the method according to
if f x N and

f x N and

f xL
f xH

are of same sign, x L x N , otherwise


will be of same sign, and x H x N

The method is terminated when one or more of the following criteria are satisfied
1)

when x N from one round doesn't change much from x N in the last round, i.e.,

x Nnew x Nold
tolerance
x Nnew

typ., tolerance 1 10 6

2)

when f x N threshold , where threshold value depends on the nature of f x

3)

when the number of iterations reaches some limit value, typ. 100

Solving the Spherical Tank Problem Using Bisection


We will now develop a spreadsheet to solve the spherical tank problem using the bisection method.
This "live" solution spreadsheet will be easily adaptable to other nonlinear equations and other
numerical methods. Start with a blank spreadsheet and make the entries indicated below:
A1: Radius
A2: Volume
A3: Depth

B1: 10
B2: 1000

C1: ft
C2: ft3
C3: ft

E1: Total Volume

G1: ft3
G2: gal

Right-justify the labels in A1, A2 and E1. Format the 3 in ft3 as a superscript, ft 3. Use Insert Name
Create to transfer the labels in cells A1:A3 to names on the cells B1:B3. Also, create the name TotVol
for cell F1.
Enter the following formulas in cells F1 and F2 to compute the total volume of the tank in ft 3 and
gallons:
F1: =4/3*PI()*Radius^3
F2: =TotVol*7.48
Enter the following labels in row 5:
A5: Iteration

B5: h1

C5: f(h1)

D5: h2

E5: f(h2)

F5: hm

G5: f(hm)

Your spreadsheet should now look like

To implement the bisection method, we will first enter an initialization row followed by an operational
row. In row 6, enter
A6: 1

the iteration number

B6: 0

an initial guess for depth that will always be below the solution

C6: =B6^3-3*Radius*B6^2+3*Volume/PI()This is

h 3 3 Rh 2

3V
with B6 for h .

The formula evaluates the equation based on the cell to the left as the guess for h .
It's convenient to use pointing in creating this formula.
D6: =2*Radius

an initial guess for depth that will always be above the solution

E6: Copy the formula in C6 to here. [Suggestion: select C6, Ctrl-C, select E6, Enter]
F6: =(B6+D6)/2

This is the midpoint between the low and high guesses.

G6: Copy the formula in C6 to here.

This completes the initialization row, and it should look like

Initialization Row
Now, we will construct an operational row; that is, a row that can be copied downward to iterate the
numerical method.
A7: =A6+1

This will keep track of the iterations.

In cell B7, we have to enter a formula that will select between B6 and F6 as the lower limit of the
interval. This follows the logic of the bisection method and should be

B7

F6
R
S
TB6 if

if C 6 and G6 are same sign


C 6 and G 6 are of different sign

The easiest way to check for same or different sign is to multiply C6 and G6. So, enter the following
formula:
B7: =IF(C6*G6>0,F6,B6)

The syntax is IF(logical condition, true result, false result)

Then,
C7: Copy C6 down.
And, enter a similar formula to determine the new upper limit of the interval:
D7: =IF(E6*G6>0,F6,D6)
Then, copy down cells E6:G6 to cells E7:G7. [Suggestion: select E6:G6, double-click on the fill
handle.]
Your spreadsheet should now look like

Initialization Row

Operational Row

and you can extend the bisection method by copying the operational row down a number of rows to
create enough iterations for a solution that will meet any practical convergence requirement. Here, we
suggest that you copy it down to row 25. To complete the "live" solution, put a pointer formula in B3:
A3: =F25

This will then display the solution with the details of the numerical method below.

Your spreadsheet should look something like

Mapped
to B3 with
pointer
formula

Final
Solution
Estimate
Display precision has been adjusted here. You can do the same, if you want. Note that the solution
has converged to 1/10,000th of a foot close enough for most engineering work!
Before we go on, try out your live solution.
Enter 2000 in B2. What is the depth? _______ ft.
Try 31000 in B2. Again, the depth is

_______ ft.

Use of Goal Seek and/or the Solver


It turns out that it is much easier to use the built-in Goal Seek or Solver utilities to solve this nonlinear
equation; however, as you will see, the live solution method with bisection (or with another numerical
method) has some important advantages over Goal Seek or Solver.
To illustrate how the built-in features work, enter 1000 again in cell B2 and note that the solution
returns to 3.46 ft. Enter a guess of 5 for depth in cell D3 and copy the formula from cell C6 to cell E3.
D3: 5

E3:

=D3^3-3*Radius*D3^2+3*Volume/PI()

The cells D3:E3 should look like


. Select Goal Seek from the Tools menu and
complete the dialog box fields as shown below:

Then click the OK button. After a bit, you should see

Click OK again and note that D3 now contains the solution to the equation,
.
Wasn't that easy?! Now change the Volume entry to 2000, and your live solution displays 9.699, but
the Goal Seek "dead" solution hasn't changed. Go ahead and re-run Goal Seek to update the "dead"
solution in cells D3:E3. Notice that you have to enter the Set cell:, To value:, and By changing cell:
fields once again; that is, Goal Seek doesn't remember.
Now, enter 3000 in the Volume field and note that the "live" solution is 12.97 ft. Try the Solver now by
selecting it from the Tools menu. Set up the Solver dialog box as shown below

Click on the Solve button, and, in a few seconds, you should see

Click on the OK button and cells D3:E3 should show


. That was also pretty easy.
Now, change the Volume to 4000 and use the Solver again. You will note that the Solver remembers
the previous scenario. In this way, it is more convenient than Goal Seek. But the Solver still provides
a "dead" result. With a change in Volume (or Radius), the Solver's solution is no longer valid and it
has to be resolved.
Before we continue with this example, note what basic changes would be required to use the bisection
"live" technique to solve another nonlinear equation:
1)
2)
3)

Initial guesses in cells B6 and D6 would have to be changed to values suitable for the new
equation.
The new equation would have to be entered in cell C6, then copied down the C column and over
into the E and G columns.
Any supporting cells, such as those at the top of the spreadsheet germane to the spherical tank
problem, would have to be modified.

That's it! It is relatively easy to convert to another equation.


Now, you will see how the "live" solution technique lends itself to a case study of equation solutions.
Developing a Calibration Table for the Spherical Tank
Going back to the original goal of this example, we want a table that will allow us to produce a
calibrated tape for the tank's sight gauge. We will assume here that the graduations on the tape need
to be in convenient increments of volume and in gallons. We need to know the position on the tape (in
feet & inches, let's say) for each even increment of volume.
Looking at the total volume of the tank, let's say that we wanted to mark the tape at 100-gallons
increments. We will see that the "live" solution technique combined with Excel's Data Table feature
allows us to do this quite conveniently.
Start by deleting the contents of cells D3:E3. We won't need these.
Make the following label entries:
I1:
I2:

Volume
gallons

K1: Depth ft
J2:

ft3

Center the Volume label across cells I1:J1. Center the other labels.
Enter 100 in cell I3. With cell I3 selected, use the Edit Fill Series selection and set up the dialog box
as shown below:

Notice that the Columns radio button is selected. Click on OK. A column of Volume (gallons) values
should have been generated down to row 315.
In cell J3, you will enter a formula to convert to ft3:
J3: =I3/7.48
and copy that formula down by double-clicking on the fill handle. The top part of your table should
now look like

Here, the precision of column J has been adjusted.


To complete this table, the equation for the spherical tank needs to be solved for each value in column
J. You would not want to have to do this manually. With the "live" solution method in place, we can
use the Data Table feature of Excel.
If any of the values in column J were placed in the Volume cell (B2) in the spreadsheet, the correct
value for the Depth would be found in cell B3. Enter a formula at the head of column K, in cell K2, to
indicate this:
K2: =Depth
Next, select J3:K315. That is all of the volume (in ft3) values including the ft3 header and the cells
adjacent in column K. To be sure, this selection contains the formula in cell K2.
Select from the Menu, Data Table and enter Volume in the Column Input field as shown

Click on the OK button and the table should complete, showing the correct solution for each volume
value. You have solved the equation several hundred times.

To add the final cosmetic touch, enter


L2: feet

M2:

inches

M3:

=MOD(12*K3,12)

and in cells L3:M3


L3: =INT(K3)

Select cells L3:M3 and double-click on the fill handle. Now you have a table in integral feet plus
inches, ready for marking a tape! By adding a label and adjusting representation, the top end of your
table can look like

This example has illustrated several important techniques. The combination of a "live" solution
technique with the Data Table is most useful.
Using Other Numerical Methods
There are several numerical methods that could be used as alternates to the bisection method. We
will mention a couple here:
False Position (Regula Falsi)
For the false position method, instead of using the midpoint formula, such as
F6: =(B6+D6)/2
the following formula would be used
F6: =(B6*E6-D6*C6)/(E6-C6)

This is based on the update formula

then cell F6 would be copied downward.

xN

b g bg
b g bg

xL f xH xH f x L
f xH f xL

The result would look like

Notice that the solution has effectively converged in 5 iterations; whereas, bisection took over 20. The
false position method is evidently more efficient.
Newton's Method (also called the Newton-Raphson Method)
This method has a different look from the previous two because it requires only one initial guess (it is
not a "bracketing" method) and the derivative formula of the equation. In this case,

af
f af
h 3h

f h h 3 3 Rh 2
2

3V

6 Rh

and the update formula is

x N xO

bg
bg

f xO
f xO

If our example spreadsheet is converted over to Newton's Method, it would look like

Notice that Newton's Method has converged by the 4 th iteration, dramatically faster than bisection or
false position. Of course, the disadvantage of Newton's Method is that its stability is quite sensitive to
initial guess.
Implementing "Live" Solution with a VBA Function -- Dealing with Convergence Issues
The "live", "on the sheet" methods illustrated have the limitation that you have to decide how many
rows is sufficient to give a converged solution. In most practical examples, that is an easy issue to
manage; however, it is possible to create a VBA user-defined function that provides a "live" solution
and control over convergence, as described on the bottom of page 4-2. This is illustrated in the Excel
workbook Tank.xls. The top end of the spreadsheet looks like

=tank(Rad,C7)

As shown, the solution for each volume value is found by using the tank user-defined function. This
function is written in VBA and is

Function tank(Radius, Volume)


h1 = 0
h2 = 2 * Radius
hm = h2
tolerance = 0.000001
iteration_limit = 100
Iteration = 0
Do
Iteration = Iteration + 1
hmnew = (h1 + h2) / 2
If Abs((hmnew - hm) / hm) < tolerance Then Exit Do
hm = hmnew
If f(Radius, Volume, h1) * f(Radius, Volume, hm) > 0 Then
h1 = hm
Else
h2 = hm
End If
Loop Until Iteration > iteration_limit
tank = hm
End Function
Function f(R, V, h)
Pi = 4 * Atn(1)
f = h ^ 3 - 3 * R * h ^ 2 + 3 * V / Pi
End Function
You will note that a convergence tolerance of 1 part in 10 6 is used along with an iteration limit of 100.
The actual equation is supplied via another function f, and the bisection method is used.

You might also like