Excel--The Solver Add-In

advertisement
UNC-Wilmington
Department of Economics and Finance
ECN 377
Dr. Chris Dumas
Excel—Using the Solver Add-In
Microsoft Excel has a feature called Solver that can help you solve systems of equations and optimization
problems, such as linear programming and nonlinear programming problems. This handout will explain how to
conduct these types of analyses using Solver in Microsoft Excel 2013.
Activate the Solver Add-In
You need to activate the Solver "Add-In" in Excel (if you have not done so already prior to reading this
handout). An "Add-In" is an extra feature of Excel that is not active by default, so you must activate it. To
activate the Solver "Add-In" in Excel, start Excel, and then go to the File tab at the top of the Excel window, then
select "Options" on the left, and then "Add-Ins" on the left. Next, at the bottom of the window, in the box to the
right of "Manage", select "Excel Add-ins", then click the "Go" button, then check the box in front of "Solver Addin" in the pop-up window, then click the "OK" button. After doing this, you might need to re-start Excel to
activate the Add-In.
Using Solver to Solve a System of Equations
As an example, let's use Solver to solve for the market equilibrium values of quantity Q and price PQ in a simple
demand and supply system of equations. Suppose the demand curve equation is PQ = 60 – 0.25*Q, and suppose
that the supply curve equation is PQ = 10 + 0.50*Q. What are market equilibrium values of Q and PQ? That is,
where do the demand and supply curves cross?







In Excel, type the following title in cell A2: "Solving a Simple Demand and Supply System of
Equations." The title doesn't do anything; it's just a label.
Add a few more labels to keep things organized:
o In cell A4, type "Independent Variables"
o In cell B5, type "Q"
o In cell A7, type "Dependent Variables"
o In cell B8, type "Pq in Demand Equation"
o In cell B9, type "Pq in Supply Equation"
In cell C5, type the number "1" (no quotes, just the number 1). This is our initial guess for Q. You could
type any number here, but the number "1" is usually a good initial guess.
In cell C8, type the equation for demand: "=60–0.25*C5". Leave out the PQ, and put "C5" in place of Q.
The equation will look up at cell C5 to find the value of Q and put it into the equation. After you type in
the equation and hit <enter>, cell C8 should contain the number 59.75; this is the value of PQ when Q=1.
This is not the final answer for PQ, it's just an initial guess, based on our initial guess of Q=1.
In cell C9, type the equation for supply: "=10+0.50*C5 ". Leave out the PQ, and put "C5" in place of Q.
The equation will look up at cell C5 to find the value of Q and put it into the equation. After you type in
the equation and hit <enter>, cell C9 should contain the number 10.5; this is the value of PQ when Q=1.
This is not the final answer for PQ, it's just an initial guess, based on our initial guess of Q=1.
Now, we use Solver to try different guesses for Q, larger and small than 1, until the PQ in the demand
equation is equal to the PQ in the supply equation. When the PQ's in the two equations are equal, we have
found the Q that produces market equilibrium.
Click on the "Data" tab at the top of the Excel window, then click on the "Solver" button on the right.
The Solver Parameters pop-up window will appear.
o In the "Set Objective" box, type C9
o Click on the "Max" button below the Set Objective box
o In the "By Changing Variable Cells" box, type C5
o The steps above tell Excel to maximize the value in C9 by changing the number in C5.
1
UNC-Wilmington
ECN 377
Department of Economics and Finance
Dr. Chris Dumas
 Click on the "Add" button to the right of the "Subject to the Constraints" box. The "Add
Constraints" pop-up window appears.
o In the "Cell Reference" box on the left, type C8
o In the "Constraint" box on the right, type C9
o In the operator box in the middle, select the "equal to" symbol "="
o Click the "OK" button
o The steps above tell Excel that, when searching for the best value of Q, the PQ in the demand
equation must be kept equal to the PQ in the supply equation (because that is the condition for
market equilibrium).
 You are automatically returned to the "Solver Parameters" window.
 In the "Select a Solving Method" box, select "Simplex LP" for solving systems of linear equations.
 Click the "Solve" button in the "Solver Parameters" window.
 The "Solver Results" pop-up window will appear. It says "Solver found a solution." This is good.
 Click the OK button.
 On the spreadsheet, look at cell C5; it should be 66.6667. This is the value of Q at market equilibrium.
This is the value of Q that makes PQ in the demand equation equal to the PQ in the supply equation. On
the spreadsheet, look at cells C8 and C9; they should be 43.3333. This is the value of PQ at market
equilibrium. Excel tried different values of Q in cell C5 until it found a value of Q for which the prices in
cells C8 and C9 were the same.
2
UNC-Wilmington
Department of Economics and Finance
ECN 377
Dr. Chris Dumas
Using Solver to Solve a Linear Programming Problem
Solver can also be used to solve Linear Programming problems. For example, suppose we want to solve
Example Problem 2 in the "Linear Programming Example Problems & Solutions" handout on the ECN377
website. In that problem, we wanted to maximize a consumer's utility, given by U =1.5*X+1*Y, subject to two
constraints: 1*X+1*Y ≤ 16 and 2*X+1*Y ≤ 18, that is:
max U = 1.5·X + 1·Y
X,Y
Subject to:
1·X + 1·Y ≤ 16
2·X + 1·Y ≤ 18








In Excel, type the following title in cell A12: "Solving a Linear Programming Problem." The title
doesn't do anything; it's just a label.
Add a few more labels to keep things organized:
o In cell A14, type "Objective"
o In cell B15, type "U"
o In cell A17, type "Choice Variables"
o In cell B18, type "X"
o In cell B19, type "Y"
o In cell A21, type "Constraints"
o In cell C21, type "Resource Amounts"
o In cell C22, type the number 16
o In cell C23, type the number 18
In cells C18 and C19, type the number "1" (no quotes, just the number 1). These are our initial guesses
for X and Y. You could type any numbers here, but the number "1" is usually a good initial guess.
In cell C15, type the equation for utility: "=1.5*C18+1*C19 ". Leave out the X and Y, and put "C18" in
place of X and C19 in place of Y. The equation will look at cells C18 and C19 to find the values of X and
Y to put into the equation. After you type in the equation and hit <enter>, cell C15 should contain the
number 2.5; this is the value of U when X=1 and Y=1. This is not the final answer for U, it's just an
initial guess, based on our initial guess of X=1 and Y=1.
In cell B22, type the equation for the first constraint: "=1*C18 + 1*C19 ", putting C18 in place of X and
C19 in place of Y. After you type in the equation and hit <enter>, cell B22 should contain the number 2.
This is not the final answer for cell B22; in the end, after X and Y have been adjusted to their final values,
cell B22 will equal cell C22 (assuming that the constraint is binding), indicating that the constraint has
not been violated.
In cell B23, type the equation for the second constraint: "=2*C18 + 1*C19 ", putting C18 in place of X
and C19 in place of Y. After you type in the equation and hit <enter>, cell B23 should contain the
number 3. This is not the final answer for cell B23; in the end, after X and Y have been adjusted to their
final values, cell B23 will equal cell C23 (assuming that the constraint is binding), indicating that the
constraint has not been violated.
Now, we use Solver to try different guesses for the choice variables (X and Y) until the value of U in the
objective equation is maximized, while also checking to make sure that the constraints have not been
violated.
Click on the "Data" tab at the top of the Excel window, then click on the "Solver" button on the right.
The Solver Parameters pop-up window will appear.
o In the "Set Objective" box, type C15
o Click on the "Max" button below the Set Objective box
o In the "By Changing Variable Cells" box, type "C18,C19" (don't type the quotes)
3
UNC-Wilmington
ECN 377
Department of Economics and Finance
Dr. Chris Dumas
o The steps above tell Excel to maximize the value in C15 by changing the values of C18 and C19.
 If there are any constraints listed in the "Subject to Constraints" box, click on them, and then click the
"Delete" button to clear them out and start fresh.
 Click on the "Add" button to the right of the "Subject to the Constraints" box. The "Add
Constraints" pop-up window appears.
o In the "Cell Reference" box on the left, type B22
o In the "Constraint" box on the right, type C22
o In the operator box in the middle, select the "less than or equal to" symbol "<="
o Click the "Add" button to save that constraint and add another
o In the "Cell Reference" box on the left, type B23
o In the "Constraint" box on the right, type C23
o In the operator box in the middle, select the "less than or equal to" symbol "<="
o Click the "OK" button
 You are automatically returned to the "Solver Parameters" window.
 In the "Select a Solving Method" box, select "Simplex LP" for solving systems of linear equations.
 Click the "Solve" button in the "Solver Parameters" window.
 The "Solver Results" pop-up window will appear. It says "Solver found a solution." This is good.
 In the "Solver Results" window, select "Sensitivity" under "Reports". Click the "OK" button.
 On the spreadsheet, look at cells C18 and C19; these give the optimal values of the choice variables,
X = 2 and Y = 14. Cell C15 gives the maximum value of U, U = 17. Cell B22 = C22, indicating that
the first constraint is not violated. Cell B23 = C23, indicating that the second constraint is not violated.
 Click on the "Sensitivity Report" tab at the bottom of the Excel window. The Shadow Price, or
Shadow Value, is given for each constraint equation. In this case, the Shadow Value is the same for each
constraint, 0.5. It is a coincidence that the Shadow Values are the same for both equations; usually, each
equation has a different Shadow Value.
4
UNC-Wilmington
Department of Economics and Finance
ECN 377
Dr. Chris Dumas
Using Solver to Solve a Nonlinear Programming Problem
Solver can also be used to solve Nonlinear Programming problems. For example, suppose we want to solve
Problem 4 in Homework 8 on the ECN377 website. In that problem, we wanted to maximize a consumer's
utility, given by U =20*X2/3*Y1/4, subject to the constraint: 2*X+3*Y ≤ 36, that is:
max U = 20·X2/3·Y1/4
X,Y
Subject to:
2·X + 3·Y ≤ 36









In Excel, type the following title in cell A25: "Solving a Nonlinear Programming Problem." The title
doesn't do anything; it's just a label.
Add a few more labels to keep things organized:
o In cell A27, type "Objective"
o In cell B28, type "U"
o In cell A30, type "Choice Variables"
o In cell B31, type "X"
o In cell B32, type "Y"
o In cell A34, type "Constraints"
o In cell C34, type "Resource Amounts"
o In cell C35, type the number 36
In cells C31 and C32, type the number "1" (no quotes, just the number 1). These are our initial guesses
for X and Y. You could type any numbers here, but the number "1" is usually a good initial guess.
In cell C28, type the equation for utility: " =20*C31^(2/3)*C32^(1/4)". Leave out the X and Y, and put
"C31" in place of X and C32 in place of Y. The equation will look at cells C31 and C32 to find the
values of X and Y to put into the equation. After you type in the equation and hit <enter>, cell C28
should contain the number 20; this is the value of U when X=1 and Y=1. This is not the final answer for
U, it's just an initial guess, based on our initial guess of X=1 and Y=1.
In cell B35, type the equation for the constraint: "=2*C31+3*C32", putting C31 in place of X and C32 in
place of Y. After you type in the equation and hit <enter>, cell B35 should contain the number 5. This is
not the final answer for cell B35; in the end, after X and Y have been adjusted to their final values, cell
B35 will equal cell C35 (assuming that the constraint is binding), indicating that the constraint has not
been violated.
Now, we use Solver to try different guesses for the choice variables (X and Y) until the value of U in the
objective equation is maximized, while also checking to make sure that the constraints have not been
violated.
Click on the "Data" tab at the top of the Excel window, then click on the "Solver" button on the right.
The Solver Parameters pop-up window will appear.
o In the "Set Objective" box, type C28
o Click on the "Max" button below the Set Objective box
o In the "By Changing Variable Cells" box, type "C31,C32" (don't type the quotes)
o The steps above tell Excel to maximize the value in C28 by changing the values of C31 and C32.
If there are any constraints listed in the "Subject to Constraints" box, click on them, and then click the
"Delete" button to clear them out and start fresh.
Click on the "Add" button to the right of the "Subject to the Constraints" box. The "Add
Constraints" pop-up window appears.
o In the "Cell Reference" box on the left, type B35
o In the "Constraint" box on the right, type C35
5
UNC-Wilmington
ECN 377
Department of Economics and Finance
Dr. Chris Dumas
o In the operator box in the middle, select the "less than or equal to" symbol "<="
o Click the "OK" button
 You are automatically returned to the "Solver Parameters" window.
 In the "Select a Solving Method" box, select "GRG Nonlinear" for solving systems of nonlinear
equations.
 Click the "Solve" button in the "Solver Parameters" window.
 The "Solver Results" pop-up window will appear. It says "Solver found a solution." This is good.
 In the "Solver Results" window, select "Sensitivity" under "Reports". Click the "OK" button.
 On the spreadsheet, look at cells C31 and C32; these give the optimal values of the choice variables,
X = 13.09 and Y = 3.27. Cell C28 gives the maximum value of U, U = 149.42. Cell B35 = C35,
indicating that the constraint is not violated.
 Click on the "Sensitivity Report" tab at the bottom of the Excel window. The Lagrange Multiplier, or
Shadow Value, is given for the constraint equation. In this case, the Shadow Value is 3.80
6
Download