EXCEL SOLVER TUTORIAL - Stanford University
ENGR62/MS&E111 Prof. Ben Van Roy
Autumn 2003?2004 October 1, 2003
EXCEL SOLVER TUTORIAL
This tutorial will introduce you to some essential features of Excel and its plug-in, Solver, that we will be using throughout ENGR62 to solve linear programs (LPs). You will learn how to
? represent LPs in an Excel worksheet,
? use the matrix functions SUMPRODUCT and MMULT,
? set up an LP in Solver, and
? generate various outputs from Solver.
This quarter you will see many applications of Solver in class demonstrations and homework assignments. Keep this tutorial document as a reference as you review the class demos and as you formulate LPs in your homeworks. For additional Excel/Solver assistance, try consulting the Excel Help files or numerous online resources. Parts of this tutorial borrow from Prof. Veinott's detailed Formulating and Solving Linear Programs in Excel.
1 Setting Up Linear Programs In Excel
Linear programs (LPs) can take many forms. In ENGR62 we will often be dealing with LPs that can be represented mathematically as
maximize cT x subject to Ax b,
where the matrices A, b, and c comprise the problem data. Our goal is to maximize the value of the objective function, cT x, by choosing an appropriate vector of decision variables, x. The matrices A and b specify a set of linear inequality constraints that reflect the requirements of the problem.
EXCEL SOLVER TUTORIAL
Page 2 of 6
a11
a12
a13
a21
a22
a23
a31
a32
a33
a41
a42
a43
a51
a52
a53
Each matrix element occupies a cell in the worksheet.
Entering Matrices into Excel
It is easy to display the components of an LP in their natural way in Excel, i.e., as a range of cells. For example, if A is a 5 ? 3 matrix, then each element of A can be entered into its corresponding cell in a 5 ? 3 range of cells. Identify ranges of cells to contain the data matrices A, b, and c and enter them into the Excel worksheet. Do the same for the decision variables, x. To keep your worksheet organized, you might consider arranging the matrices as shown below. You are also encouraged to use labels and text to document your work.
cT
cT x
x
A
Ax
b
A sample layout of LP matrices in an Excel worksheet.
Naming Matrices in Excel
Excel allows you to name ranges of cells in the worksheet. This feature is especially convenient for doing matrix calculations and for setting up LPs in Solver. To name a range of cells, select the entire range with the mouse and use the Insert Name Define... menu. Alternatively, select the range and enter its name in the Name Box adjacent to the Formula Bar. Try using both methods to give names to the data matrices A, b, and c and to the decision variables, x.
EXCEL SOLVER TUTORIAL
Page 3 of 6
Matrix Calculations: SUMPRODUCT and MMULT
We will frequently use the SUMPRODUCT and MMULT commands in Excel.
Syntax
Description
SUMPRODUCT(range1, range2 ) sum of products of corresponding elements
MMULT(range1, range2 )
ordinary matrix multiplication
The arguments of SUMPRODUCT and MMULT can be either ranges of cells or range names. It is more concise and descriptive to use names. For a pair of ranges named S and T, entering SUMPRODUCT(S,T) into the Formula Bar returns i,j sijtij, i.e., the sum of the products of corresponding elements of S and T. Entering MMULT(S,T) into the Formula Bar returns the matrix whose ijth element is k siktkj, i.e., normal matrix multiplication.
SUMPRODUCT(S,T) will return an error unless S and T have the same dimensions. Similarly, MMULT(S,T) will return an error unless the number of columns of S equals the number of rows of T. If you need to take the transpose of a matrix, use the TRANSPOSE function.
Important note: If a matrix function returns a matrix larger a single element, you must first use the mouse to select the cells that will contain the result, then type the matrix function into the Formula Bar, and finally type CTRL SHIFT ENTER (COMMAND ENTER on a Mac) to evaluate the matrix function. For example, if S and T are 3 ? 5 and 5 ? 4 matrices, respectively, then the result of MMULT(S,T) will be a 3?4 matrix. To perform this calculation and display the result in the worksheet, first highlight a 3?4 range of cells, type MMULT(S,T) into the Formula Bar, then type CTRL SHIFT ENTER to display the result in the highlighted area.
With regard to LPs, two of the most important matrix calculations are computing the objective function value, cT x, and the constraint function, Ax. The objective function value cT x is the scalar product of two vectors, and so can be computed using either SUMPRODUCT(c,x) (as long as c and x are both either row or column vectors) or MMULT(cT,x.1 The constraint function Ax is a matrix, so MMULT(A,x) must be used.
Select ranges of cells to contain cT x and Ax and compute their values using the Excel matrix functions. As the following section will make clear, it is helpful to give these ranges names such as cTx or OF for cT x, and Ax for Ax. Also remember that neither SUMPRODUCT nor MMULT will work properly if either of the two arguments are empty. For this reason, you must provide dummy values?such as zeros?for the decision variables, x.
1The MMULT command shown here assumes that the objective function coefficients, c, have been entered as a row matrix and named cT. Of course, how you issue matrix function commands in Excel will depend on how you entered the data into your worksheet. If you entered c as a column, then you would compute cT x as MMULT(TRANSPOSE(c),x).
EXCEL SOLVER TUTORIAL
2 Using Solver
Page 4 of 6
Setting up the LP in Solver
When all of the LP components have been entered into the worksheet and given names, bring up Solver using the Tools Solver... menu. There are four main elements of the Solver dialog box:
? Set Target Cell: The Target Cell contains the quantity you wish to optimize?the objective function value. To specify the Target Cell, either click on the cell with the mouse or type in the name of the cell containing the objective function value (e.g., OF or cTx).
? Equal To: This specifies the direction of the optimization. Click on either of the "Max" or "Min" radio buttons.
? By Changing Cells: Recall that our goal is to optimize the value of the objective function by choosing an appropriate vector of decision variables. Therefore we will allow Excel to change the decision variables, x. In the "By Changing Cells:" field, either select the range of decision variables using the mouse or type in the name of the range (e.g., x).
? Subject to the Constraints: Specify a constraint by clicking on the Add button. While it is possible to add each constraint one at a time, it is easier (and more concise) to enter a single inequality between the constraint function, Ax, and the right-hand side, b. If Ax and b are named ranges in the worksheet, enter the constraint as Ax b.2 Be sure to include any additional constraints, such as nonnegativity constraints (x 0).
On the right hand side of the Solver dialog box is a button labeled Options... Click on this button to bring up another dialog box. Since we will be dealing primarily with linear programs in ENGR62, the option of greatest interest is "Assume Linear Model." Selecting this option forces Excel to use a method for solving LPs known as the Simplex algorithm, which we will discuss in some detail later in the course. It is important that "Assume Linear Model" is selected, or else you may end up with inappropriate outputs.
Once the LP has been properly set up in the Solver dialog box, press the Solve button to run Solver.
2Or whatever the appropriate inequality is. You may find it easier to separate , , and = constraints into "blocks," provide appropriate names, then enter them into Solver.
EXCEL SOLVER TUTORIAL
Page 5 of 6
Solver Output Options
Pressing the Solve button runs Solver. Depending on the size of the LP, it may take some time for Solver to get ready. If Solver reaches a solution, a new dialog box will appear and prompt you to either accept the solution or restore the original worksheet values. At this point you may also choose to see a number of output reports. The Answer report provides a summary of the optimal decision variable values, binding and non-binding constraints, and the optimal objective function value. The Sensitivity report provides information describing the sensitivity of the optimal solution to perturbations in the problem data. This report will become important during our study of linear programming duality.
A Note About What to Hand In
Solving an LP in Excel can sometimes take up a lot of worksheet space, especially if there are many variables or constraints. Although it is important for you to set up your worksheets correctly and neatly, it is not necessary?unless clearly stated by the assignment?for you to submit them with your homework. Instead, you may print out and submit the Answer and Sensitivity reports that accompany your Solver solution.
3 An Example
Consider the following linear program:
subject to
max 50x1 + 30x2 + 25x3 + 30x4
2x1 + 2.5x2 + 3x3 + 1.8x4 800 1.2x1 + 1x2 + 2x3 + 0.8x4 400 1.5x1 + 1.2x2 + 1.5x3 + 0.8x4 380
x2 50 x3 30 x1, x2, x3, x4 0
This problem can easily be represented as an LP of the form
maximize cT x subject to Ax b
x 0,
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- formulas and functions
- excel keyboard shortcuts and function keys ucdc
- formulas for collecting bloomberg data in excel
- basic formulas in excel georgetown isd
- intro to excel spreadsheets us epa
- excel solver massachusetts institute of technology
- excel solver tutorial stanford university
- excel 2019 basic quick reference customguide
- formulas and functions libreoffice
- creating a grade sheet with microsoft excel ucla mathematics
Related searches
- stanford university philosophy department
- stanford university plato
- stanford university encyclopedia of philosophy
- stanford university philosophy encyclopedia
- stanford university philosophy
- stanford university ein number
- stanford university master computer science
- stanford university graduate programs
- stanford university computer science ms
- stanford university phd programs
- stanford university phd in education
- stanford university online doctoral programs