Académique Documents
Professionnel Documents
Culture Documents
Using Solver
Excel has two tools, Goal Seek and Solver, that can save a great
deal of time with complex mathematics. From a practical point of
view the simple tool Goal Seek is redundant. It has limited scope
and is far outpaced by Solver. So why is it there? Simply because,
being easier to use, it is less intimidating for the mathematically
challenged. So we shall spend a brief time on it.
Solver, which is leased by Microsoft from Frontline Systems Inc.,
was developed primarily for solving optimization (maximum and
minimum) problems. However, it can also be used to solve
equations, and that is where we shall start. You may wish to visit
www.solver.com to learn more about this product and its
variations. The site also has a tutorial for using the Excel Solver,
but it concentrates on optimization problems; we will do more
with Solver.
In this chapter we will see examples where Solver is used (i) for
equation solving, (ii) for curve fitting or regression analysis, and
(iii) some simple optimization problems.
Solver needs to be installed on your computer and loaded into
Excel. It is likely this happened when Excel was installed. To check,
open the Data tab and look in the Analysis group for a Solver icon.
If you do not see it, use the Excel Help with the search word solver
to get instructions on loading it. The Excel Help has nothing more
about Solver, as Solver has its own Help facility.
you altered AS until BS was nearly a-or you got tired of the
game ! Well, Goal Seek wo rks the same way. Let us see Goal Seek
at work.
Figure 12.1
(a) On Sheetl of a new workbook, enter what you see in Figure
12.1 without the text box. The formula in BS is =EXP(-A5)5IN(A5).
Exercise 2: Solver as
Root Finder
Figure 12.2
(a) Open Sheetl of Chap12.xlsx. In AS enter the value 1.
(b) Use the command Data / Analysis / Solver to open the dialog
shown in the top of Figure 12.2. You can see this is much
more detailed than Goal Seek.
(c) For this problem: The Set Target is B5, with Value Of selected
and set to 0, and By Changing Cells is A5. Click the Solve
button in the top right corner.
(d) Solver finds an answer, and the Results dialog pops up. Note
that you can accept the answer or return to the original
values. The reports are relevant only for optimization
problem, not for a Value Of problem. Click OK.
(e) SetAS to 0 and try again. Note (i) that Solver remembers the
problem and (ii) the results are more consistent.
(f)
Open Solver again but before you click Solve, open the Options
dialog; see Figure 12.3. We shall not make any adjustments
for this problem, but you may wish to use Solver's Help to
learn a little about the first few optional settings.
(g) Save the workbook.
Figure 12.3
Solving Equations
with Constraints
THIS IS IMPORTANT: Many
Excel texts do not use Solver
correctly. It is not necessary
to have a Set Target Cell. We
can find roots of equations
using Changing Cells and
Constraints. This method can
make the problem easier to
set up and will often give
better results.
If,in the last Exercise, you did look at Solver's Help and read about
the Precision setting, you saw that it said: Controls the precision of
solutions by using the numberyou enter to determine whether the
value ofa constraint cell meets a target or satisfies a lower or upper
bound. This might sound irrelevant to the problem, but it is not.
With a starting value of 1 in AS and the default value of Precision
at 0.000001 (that's five zeros after the decimal), Solver's answer
made B5 avalue of-2.1E-08 (your result could differ slightly). But
when Precision is set to 0.00000000001 (ten zeros after the
decimal), the value was 1.8E-12. Higher precision leads to an
answer closer to zero.
This is because: when the Value O[model is used in Solver, it is
treated as a constraint problem. Indeed, to solve the last
problem, we could have cleared the Set Target Cell and enter a
constraint in the Form $B$5 = O.
This becomes very important when you want more than one cell
to take on a certain value. Suppose your model requires all cells in
D1:D10 to become zero. Ifwe insist on using the Value afmethod,
we need a single cell, and so write =SUMSQ(Dl:DlO) in Dll and
use it as the Set Target Cell. Of course, =SUM(D1:D10) would not
work since cells with positive and negative values could sum to
Exercise 3: Finding
Multiple Roots
12
Figure 12.4
(a) On Sheet2 ofChap12.xlsx, copy from Figure 12.4 the text and
values in columns A and B.
There is an analytical
method for solving cubic
equations. This is shown in
the workbook CubicEqn.xlsx
on the companion website.
Exercise 4: Saving
Solver Models
(c) Set Solver up to use the constraint and no target cell. With FS
as the active cell, open Solver's Option dialog and click on
Save Model. Solver highlights a S-by-1 range; click OK. Mark
these with borders/and color fills.
(d) Nowyou can switch from one model to the next using Options
/ Load Model and selecting with appropriate block of cells.
(e) Save the workbook
Exercise 5: Systems of
Nonlinear Equations
Figure 12.5
Figure 12.6
Figure 12.7
The heading s, y, and yfit in the data set were used to name the
columns of data. Cells BS and CS were named as m and b,
respectively. The formula in each cell inyfit is =mx+b. Note how
Excel lets us use x to refer to just a single cell in this formula. The
formula In B3 is =SUMXMY2(y,yfit). This function conveniently
generates the sum of the squares of the residuals. Cells B6:C6 have
the formula =LINEST(y,x), while B7:C7 are copies of the values
from the NIST website.
With initial values of m and b as 1, the Solver model used The Set
Target is C5,with Min box selected and By Changing Cells as B5:C5.
While the LINEST results are much closer to the accepted NIST
values, the Solver answers are quite acceptable.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
yfit
0.2
0.3
0.3
0.4
0.5
0.6
10.1
11.1
11.6
118.2
118.3
120.2
226.5
228.1
229.2
337.4
338.0
339.1
447.5
448.6
448.9
556.0
556.8
558.2
666.3
666.9
669.1
775.5
777.0
779.0
884.6
887.2
887.6
995.8
996.3
999.0
0.1
0.3
0.6
0.3
0.2
0.1
9.2
10.2
10.8
118.1
117.6
119.6
228.1
228.3
228.9
338.8
339.3
339.3
448.9
449.1
449.2
557.7
557.6
559.2
668.5
668.8
668.4
778.1
778.9
778.9
888
888
888.8
998
998.5
998.5
-0.1
Figure 12.8
0.0
0.0
0.1
0.2
0.3
9.9
10.9
11.4
118.2
118.3
120.2
226.7
228.3
229.4
337.9
338.5
339.6
448.2
449.3
449.6
556.9
557.7
559.1
667.4
668.0
670.3
776.9
778.4
780.4
886.2
888.8
889.2
997.6
998.1
1000.9
A
B
1 Gaussian Fit
2
3 Before
4
1600
h
5
0.255
mu
sig
6
0.005
base
7
0
8
SSR
-10
11
-
-12
-13
14
-
-15
-16
-17
-18
-19
.12-
-21
-22
-23
-24
-25
-26
-27
-28
-29
*
-32
-33
-34
35
-36
-37
-38
39
-40
-41
x
0.239
0.240
0.241
0.242
0.243
0.244
0.245
0.246
0.247
0.248
0.249
0.250
0.251
0.252
0.253
0.254
0.255
0.256
0.257
0.258
0.259
0.260
0.261
0.262
0.263
0.264
0.265
0.266
0.267
0.268
0.269
Figure 12.9
y
25
24
39
49
56
84
66
97
158
244
353
444
773
1196
1677
1654
1341
1173
933
550
220
101
97
39
26
11
16
10
13
8
5
After
1580.69
0.253959
0.003654
40.11852
114867.2
yfit
40.12
40.12
40.12
40.15
40.31
41.06
44.00
53.89
82.19
150.81
290.84
528.99
860.77
1226.11
1515.68
1620.61
1497.53
1197.10
830.85
505.37
275.79
142.89
78.70
52.59
43.59
40.95
40.29
40.15
40.12
40.12
40.12
Exercise 6: Gaussian
Curve Fit
Yi
Yi
h
Xi
fl
a
b
= hexp (=
=
=
=
=
=
Xi -
JL
) 2J -b
-(J-
where:
the predicted value
the peak height above the baseline
the value of the independent variable
the position of the maximum
the standard deviation and
the baseline offset
parameters.
(e) To get ready for Solver we need a target cell holding the sum
of the squares of the residuals. In C8 enter the formula
=SUMXMY2(Bll:B41,Cll:C41).
Use Solver to complete the task. The target cell is C8, which
we wish to minimize by changing C4:C7. The resulting values
are shown in Figure 12.9, while Figure 12.10 shows before
and after fitting plots.
(f)
After
1800
1800
1600
1600
1400
1400
1200
1200
1000
1000
800
800
600
600
400
400
200
200
0.230
0.240
0.250
0.260
0.270
0.280
0.230
0.240
0.250
0.260
0.270
0.280
Figure 12.10
Figure 12.11
The worksheet to solve this problem, together with the Solver
dialog, are shown in Figure 12.12.
Figure 12.12
(a) On Sheet 7 ofChap12.xlsx, enter the text shown in the figure.
Enter the values in B4, BS, and HS.
(b) SelectA4:BS, then while holding! Ctrl] down, selectD4:E4 and
G4:HS. Use Formula / Defined Names / Create from Selection to
name the cells to the right of each text entry.
(c) Enter these formulas: in E4 =(0"'2) + (4*0*b) and in H4
=0"'2*b. The parentheses in the first formula are just to
improve its readability.
(d) Set Solver up as shown in the figure and press the Solve
button. The results should be 1.26 for a and 0.63 for b.
(e) Save the workbook.
Exercise 8: An
Optimization Problem
Figure 12.13
Figure 12.14
(e) All that remains is to run Solver; the settings are shown in
Figure 12.14. The maximized profit comes out as $15,375
using all available supplies. Save the workbook.
TK Solver"
Problems
1.
2.
3.
Benzene
Toluene
Ethyl Benzene
4.
's.
Carnahan and J. O.
Wilkes, Digital Computing
a
7.84125
8.08840
8.11404
1750
1985
2129
0.5
0.3
0.2
. ld
yze
Va (1 - exp( -kt
o
r
= --"--------'-t, + t,
)
ao
k
tc
S.
-In(trk + tk + 1) / k
10
0.1
1
0.5
20
0.1
1
0.5
10
0.2
1
0.5
=0
10
0.1
0.5
0.5
10
0.1
1
1
3y=18-2x2
Area A
0.5
6.
1.5
2.5
3.5
Figure 12.16
7.
8.
S = KSrnax
l+Kp
Fit the data in the following table to find K and Smax'
9.
4.72
9.29
18.45
18.02
48.01
25.08
2V + J[ r
S = ---;:-
- Ta+C(~J%
Ta
17 - 170 T + C
11 (expt)
10
20
30
40
50
60
70
80
90
100
17.87 18.37 18.86 19.34 19.82 20.29 20.75 21.21 21.66 22.10
Figure 12.17
Do not use the UDF you may have coded in Problem 7 of
Chapter 9 but compute the ml values with an Excel function.