You are on page 1of 14
64 EXCEL soLuER: AN INTRODUCTION 253 6.4 EXCEL SOLVER: AN INTRODUCTION In this section, we describe Excel Sol ver and demonstrate it for solution of nonlinear equa- tions. Preparation of the Excel worksheet for the Solver is explained, as is the Solver Dia- Jog. Box, which sets up the solution conditions and various parameters. It turns out that the Sol ver can also be used for solution of linear and nonlinear programming problems. There- fore, the material in this section should be thoroughly understood because it will be used in all subsequent sections and later chapters. 6.4.1 Excel Solver Excel is a spreadsheet program that has many useful capabilities for engineering calcula- tions. In particular, it can be used to solve a system of simultaneous equations and optimiza- tion problems. Online help is available to assist with using the program. When the program is invoked, it opens what is called a “workbook.” A workbook contains several pages called “worksheets.” These worksheets are used to store related data and information. Each work- sheet is divided into cells that are referenced by their location (je, their column and row num- bers). All of the information and the data and its manipulation must be organized in terms of cells. Cells contain raw data, formulas, and references to other cells. “Sol ver" is the tool available in Excel to solve a nonlinear equation, a system of linear/ nonlinear equations, and optimization problems. Use of this tool to solve linear and nonlinear ‘ptiTTzation problems is demonstrated later in this chapter. In this section, we introduce the tuse of this tool to solve for roots of nonlinear equations.\501 ver|is invoked through the Data tab. If itis not visible under the Data tab, then it is not yet installed on your computer. To in~ stall it, use the Add- in capability under the File-Excel Options menu and follow the screen instructions to install Sol ver. Note that the location of Solver and other commands, and the procedure to install Solver, may change with later versions of Excel. To use the Excel'So1 ver, two major steps need to be followed: 4. An Excel worksheet for the problem needs to be prepared, identifying the cells that con- tain the variables for the problem. Also, all equations for the problem functions need to be entered into different cells. 2. The Sol ver is then invoked, which results in the display of the Solver Parameters dia- Jog box. In this box, the actual problem to be solved is defined, The cells that contain the variables for the problem are identified. The cell containing the objective function for the problem is identified. The cells defining various constraints for the problem are identi- fied. Various Options for the Sol ver are also invoked. In the following sections, we elaborate on these two steps and show their use to solve sev- eral different types of problems. 6.4.2. Roots of a Nonlinear Equation ee Ba sinx=0 @ it TL NUMERICAL METHODS FOR CONTINUOUS VARIABLE OPTIMIZATION OTWsH~ 220 C ts y eee We a So 254 6, OPTIMUM DESIGN: NUMERICAL SOLUTION PROCESS AND EXCEL SOLVER «@) Rocks of 2s ama = 0 a 2 3 ese z z| sen) Oriana] ORDO] © SSS fePoaar= 0 2 Bie 4 FIGURE 6.1 Excel worksheet for finding roots of 2% sj showing. ition problem of Ex- ample 422. We need to prepare a worksheet that defines the problem. The worksheet can be Prepared in many different ways; Fig, 6.1 shows one. We gename cell C3 as x, which is the solution variable, and shows a value of 2 for it. To Aarne Gell Use the Define ‘Name command under the Formule Gk Defining meaning- ful names for cells allows them to be referenced by their ramen rather than their cel il num- bers. This makes the worksheet easily readable, The celle wn Fig. 6.1 contain the following information: GIL A3: indicates that row 3 is associated with the variable x (inactive cell) Gill Aa: indicates that row 4 is associated with the equation (incline cell) Cell B3: the variable name that will appear later in the Ansuer he Cell C3: the starting value for the variable named x (the euren ‘be updated later by Solver toa final value (active cell) CoiLBa: the equation whose roots need to be found; it will appear later in the Answer Report (inactive cell) Cell C4: contains the expression for the equation: “= 2*x/3 — sinx surrently it displays the value of the expression for x= 2 in cell C3; to see the expression in cell Ca, vuse the Show Formulas command under the Formulas tab (active cell) Port (inactive cell) 'nt value is shown as 2); will Solver Parameters Dialog Box Whenever the value in cell C3 is changed, cell C4 is updated automatically: Now Solver is invoked under the Data tab to define the target cell and the cell to be varied” Fig. 6.2 shows the Solver Parameters dialog box. We set the Objective cell as C4 because it sontare the equation whose roots need to be determined. In the next ine, we select the Value. Of button and assign a value of zero for the selected objective function because when the root is fore the objective function value should be zero. (Solver uses the § symbol to identify celle for example, SC$4 refers to cell C4. Use of $ in a cell reference is convenient when the “copy for. tnula” capability is used. With the “copy formula” command, a reference to a cell tharoses a $ symbol is not changed). 1. NUMERICAL METHODS FOR CONTINUOUS VARIABLE OPTIMIZATION. Roots of 2x/3-sinico \Variable: |x [ [Equation [2x/3-sin x to. Seni une Npaeg am one E IN I, NUMERICAL METHODS FOR CONTINUOUS VARIABLE OPTIMIZATION 256 {6 OPTIMUM DESIGN: NUMERICAL SOLUTION PROCESS AND EXCEL SOLY ‘Thereafter, we define the cell whose value needs to be treated as the variable by inserting x in the By Changina Variable Cells box. Then we go to the Select a Solving Method drop- dlown menu and select GR Non! inear option because this is a nonlinear function. Then, by click- ing the Options button, we can reset some of the parameters related to the solution procedure, if desired. Otherwise, we click the So] ve button to find a root starting from x = 2. The buttons on the right side of the sereen, Add, Change, etc. are used to enter constraints for the problem, Solver Output When Solver is finished, it produces three reports: Answer, Sensitivity, and Limits. (ee the Solver Results dialog box in Fig. 6.3.) We select only the Answer Report be- cause it contains the relevant information for the roots of the nonlinear equation. When OK is clicked with the Answer option highlighted under Reports, Solver produces another worksheet that contains the final results, as shown in Fig. 64. The report shows that the 4a Bese chae E F G 5 1 [Roots f2eB-cax= 0 I 2 T 3 Verb: =| 149578097 "4 [Baquation: | 2 73-sax|-3, 4968-07] 5 st “EIA | solver found a solution. All Constraint and optimality | |ff | conditions are satisfied. Reports ato} AAT] fh] | © Keep soiversotuton ‘Sensitivity fal Limits (© Restore Original Vates: return to Solver Parameters Dialog ae Reports (Creates the type of report that you specify, and places esch report on a separate sheet in the workbook ip)eelytslty ies sles] Solver Results dialog box and the final worksheet. 1, NUMERICAL METHODS FOR CONTINUOUS VARIABLE OPTIMIZATION, ® ss NCH. SOL¥1 Hs AN INTRODL 257 {op & aR ame pe Ree |ee tiie pte | re ee a * [Fgare6.1(sontincar equation) 2013.alee|Figero : [Report Created: 760018 Sameera ae [Resalt: Solver found a solatos. All Constraints and opt it 4 . rains and optimality condi “Max Time 100 sec, erations 100, Precision 0.000001, Show Iterafion Rests Convergence 0.0001, Population Size 100, Random Seed 0, Derivatives Ceara, Require Bounds “Mux Solproblems Usted, Max Integr Sols Used Integer Tokrance St, Solve With reget Cosirits ive Cell Vale Cell “Namo Original Valao Final Valeo SCS4 Dii-sinx 0424035907 -3.49598E.07 SCS da-sinx 0424035907 -3.49598E-07 ‘Cell_Name_ Original Valo Final Valo ‘2 1.495780977 Coun Sx 21495780977 Contin objective function has attained a value of almost zero (~3.496x 10°” the final value of x (the root) is 1.496. Other roots for the equation can be found by changing the starting value of x in cell C3. If one starting value does not work, another value should be tried. Using this procedure, three roots of the equation are found as 0, 1496, and ~1.496, as given in Example 4.22. ), which was desired and 'be used to find the roots of a set of nonlinear equations, such as the ones 'KKT necessary conditions, We will use this capability to solve the KKT sary conditions that were determined in Example 4.31. Equations of the nec- ns are Eaae 2x; 3x2 + 2ux, =0 (a) ; A 2x, -3x, +2ux, =0 ) i | abtad-6+s'=0; 520; u20 © ult us=0 @) 1. NUMERICAL METHODS FOR CONTINUOUS VARIABLE OPTIMIZATION a 258 4 OPTIMUM DESIGN: NUMERICAL SOLUTION TROCESS AND EXCEL SOLVER ‘The first step in the solution process isto prepare an Excel worksheet to describe the problem functions. Then Solver i invoked under the Data tab fo define equations and con- Pee Ae nated ear, an Excel worksheet canbe prepared in a number of diforen Wate One way is shown in Fig. 65, which shows not ony the completed worksheet but also the Cero parameters dialog box forthe problem, Various cells are define as follows Cells A3-A6: variable names that will appear ater in the Answer Report worksheet (inactive cells) Cells A8-A13: expressions for the KKT conditions given in Eqs. (a)-(d); these expressions will appear later in the Answer Report (inactive cells) Cells B3-B6: renamed x,y, u, and s, respectively, containing the starting values for the four variables; note thatthe variables x; and x; have been changed to x and y because x: and x2 are not valid names in Excel; current starting values are shown as 1, ~2, 2,0 (active cells) Dex ~ Sty + 2th (expression for DL /2x) (active cel) 2ty - 3x + 2+uty (expression for OL/dy) (active cell) xrm + yty ~ 6 + S#s (constraint, g +5° (active cell) ts (switching condition) (active cell) s*s (active cell) Cell B13:= u (active cell) Cells C8-C13: right side of expressions in Cells B8-B13 (inactive cells) laht29, fins fies tae ana enn sentence SET IGURE 6.5" Worksheet and $01 ver Peraneters dialog box for KKT conditions for Example 431. IL NUMERICAL METHODS FOR CONTINUOUS VARIABLE OPTIMIZATION 9 » » 64 TXCH. Sov vr: AN INTRONUC TION 259 The current values for the expressions in cells HRB at the ot in cells B3-Bo are given as 12, -15, by using the Show Format arting, values of the variables 1,0,0, and 2. Expressions coded in cells B3-B13 are seen as command under the formulas tab. Solver Parameters Dialog Box Now the Solver is invoked under the Data tab and the root-finding problem is defined in the Solver Parameters dialog box. The Ob ject iv is set to B8, whose value is set to zero at the solution point, as shown in Fig. 6.5. The variable cells are identified as B2-B6. The rest of the equations are entered as constraints by clicking the Add button. Note that in order to solve a set of nonlinear equations, one of them is identified as the 0b ject i ve equation, Eq. (a) in the present case, and the rest are identified as equality constraints. Once the problem has been defined, the So1 ve button is clicked to solve it. Sol ver solves the problem and reports the final results by updating the original worksheet and opening the Solver Results dialog box, as shown in Fig. 6.6. The final Answer worksheet can be generated if desired. The current starting point of (1, ~2, 2, 0) gave the KKT point as (—1.732, —1.732, 05, 0) A [Example 4.31 Solution of KKT Conditions | Variables | x -1.732050827891| | _y '-1.732050827891| a ‘0.5000000000044 | or aren ee enereee| Vr] Equations i Valo aretha [0 ty-3xDhuy [0 Sxtxtyty-6ists [0 | sats 0 Hats >=0 =a =o Solver found » soliton. All Constraints and optimalty ‘conditions are satisfied Reports © keep Sober Sckton Senstttty ‘© Restore orginal vabies Di Return to Solver Parameters Dialog FIGURE 6.6 Solver Resuts for KKT conditions for Example 431, IL, NUMERICAL METHODS FOR CONTINUOUS VARIABLE OPTIMIZATION JED OFTMUMUNSIEAE NUMERICAL SOLUTION ROCESS AND ACE SOLVER Solution to KKT Cases with Solver : a 1tis important to note that with the worksheet shown Hf Fig. 65, oe Ki Tenses canbe cole ae araely, These cases can be generated using different starting ves "0 TS variable and the Lagrange multiplier in cells BS and BO. For example, selecting f aa s fenerates the case where the inequality constraint is inactive. This gives the solution: x= and Selecting w>0 and s=0 gives the case where the inequality constraint is active. Shecting different starting values for x and y gives two other points as solutions fo the neces: Se conditions, When there are two or more inequality constraints, various KKT cases can bf generated in a similar way by assigning appropriate values for the Lagrange multipliers and the slack variables, tn, ts, $1, and Sa 6.5 EXCEL SOLVER FOR UNCONSTRAINED OPTIMIZATION PROBLEMS Excel Solver can be used to solve any unconstrained optimization problem. To show this, let us consider the unconstrained optimization problem: Minimize f(%y,2) Figure 67 shows the worksheet and the Solver. Parameters dialog box for the problem. ‘The worksheet can be prepared in several different ways, as explained in Section 6.4. For the present example, cells B4-B6 clefine the design variables for the problem. These are renamed ‘8 x,y, and z and show the starting values for the design variables as 2, 4, and 10. Cell D9 de- fines the final expression for the cost function, Once the worksheet has been prepared, Solver is invoked under the Data tab, and GRG Non! inear is selected as the solution method. The + forward finite difference method is selected for calculation of the gradient of the cost function under the Options button. The central difference approach can also be used. The algorithm converges to the solution (0, 0, 0) with f* = 0 after five iterations. + 2y2 +228 + 2ay+2yz (@) 6.6 EXCEL SOLVER FOR LINEAR PROGRAMMING PROBLEMS Excel Sol ver can be used to solve linear programming, problems as well. The procedure for solving this type of problems is basically the same as the procedure explained tor solving nonlinear equations or unconstrained optimization problents in the previous two sections. To start, an Excel worksheet needs to be prepared that contains all of the data and equations for the problem, Thereafter, the Solver Parameters dialog box is activated under the Data tab. Last, the objective function, the design variables, and the constraints are defined, and the problem is solved, We will demonstrate this process by solving the problem given as bax, @) I. NUMERICAL METHODS POR CONTINUOUS VARIABLE OPTIMIZATION, a 9) uv 66 PXCHL FOR LINPAR PROGRAMMING FRONLEMS Tate eae FIGURE 6,7 Tice! worksheet and Solver Paranetersdislog box for unconstrained problem. subject to xt2x2 $5 ax tr=4 yyouel xx 20 1h, NUMERICAL MITHODS FOK CONTINUOUS VARIABE POPUIMIZATION IMUM DESION: NUMERICAL SOLUTION ROCESS AND! EXCEL SOLVER. 262 6 orm! oi ‘Al x B c E 1 [linear programming problem — 2 a a = [poblenistomanmie: — fatoa 4 |subject to 42x25, 3 faeax=a 6 faxed | hax=0 je 9 [Problem set up for Solver 10 [variables pa fea gum of tH Rs Umit 11 variable value o_o 12 [objective function: max it la [cazegegui+bi2"SDS11 13 [Constraint 1 a jacig*$c$11#013"S0$11_ |S. 14 [Constraint 2 2. lecia*gcsi+D14*g0$11 |4 rs [constraint 3 aba eeasesesavors*gosaa |b FIGURE 6.8 Excel worksheet forthe linear programming problem “The Excel worksheet for the problem can be organized in many different ways. Figure 68 shows one possible format for setting up the problem. The original problem is entered at | the top of the sheet just as a reminder, Other cells containing data about the problem are ex- plained as follows: |A10-A15: row designations (inactive cell) Cai, Dit: starting values for the variables x, and 33, respectively; currently set to 0 (active cell) © Caz, D12-objective function coefficients for % and x, (inactive cell) 2 | GBF Dis: coefficients of constraints in Eqs. (b)-(2) (inactive cel) Fee Formula to calculate the objective function value using the design variable values in the cells CII and D11 (active cell) Eis: formula to calculate left side of the “s type” co ra ormula to calculate the left side of the equality constraint in Ei. (6) Oct cell) aot rma to calculate the left sie of the “2 type” constraint in Eq, (€) (active cell) PIS Fis: right-side limits for the constraints. (inactive cell) straint in Eq. (b) (active cell) [Note that for the present example, the design variable cells C11 and Dt afr Net renamed eee thule command under the Formulas tab is used to display We formulas in ells E12-E15; without that command the cells display the current ‘evaluation of the formu- Se the formala in cell E12 is entered, ancl the rest of the formulas are § erated using the | Copy Cell command, It is important to note the § signs xt in referencing some of the cells | : oe alas entered in cell E12, as = C12*$CS11 + D12°$DSIL. The cols required to re ain fixed in the formula while copying need wo have a§ Pret For example, cells C1 and Dil have design variable values that are needed with each formula: therefore these cells are i) NUMBRICAL METHODS FOR CONTINUOUS VARIABLE OPTIMIZATION (6.6 EXCEL SOLVE FOR LINEAR PROGRAMMING PROBLEMS, 263 entered as $CS11 and $DS11. References to these cells do not change in the formulas in cells E13-E15 while using the copying command. Alternatively, equations can be entered manu- ally in each cell The next step is to identify the objective function, variables, and constraints for Sol ver by invoking Solver under the Data tab. This is shown in Fig. 6.9, where cell E12 is identified as the Objective function cell. The Max button is selected to indicate that the objectiv [NUMERICAL METHODS FOR CONTINUOUS VARIABLE OPTIMIZATION 264 6. OPTIMUM DESIGN: NUMERICAL SOLUTION PROCESS AND EXCEL SOLVER to be maximized. Thereafter, the design variables are entered as cells C11 and D1 in the By Changing Ce11s text box. Sol ver will change the values in these cells as it determines the optimum solution, The constraints are entered by clicking the Add button; a dialog box appears in which the cells for the left and right sides of a constraint are entered. The final set- up for the present problem in the Sol ver Paraneters dialog box is shown in Fig. 6.9. Note that the Hake Unconstrained Variables as Non-Negative is checked; therefore there is no need to enter x; 2 Qand.x2 20 as constraints in the Subject to the Constraints box Inthe Select _a Solving Method dropdown menu Simplex LP is selected as the method for solving this linear programming problem. Now the Sol ve button is clicked to obtain the Sol ver results. Figure 6.10 shows the Solver Result: s dialog box and the updated worksheet. Since the Keep Solver Solution option is chos sen, the Sol ver updates the values of the cells C11, A A i B | c Dt E | ¥F 1 [Linear programming problem, | i 3 _|Problem is to maximize: |x1+4x2_ | I A |subject to x1+2x2<=5 s 2x1 +x2=4 6 [x1-x2>=1 [ 7 Ix], x2>=0 | ee 9 Sum of LHS |RHS Limit] 0.667) 4) 433333333) ‘Solver found a solution. All Constraints and optimality ‘conditions are satisfied. Reports © keep Solver Sotuton eo SSdoscals (© Bestore Original Values: Tlouttine Repoets Sey 2 3 | FIGURE 6.10 Soiver Resutts dialog box fo the linear programming problem. 3, NUMERICAL METHODS FoRCONTINUOUS VARIABLE OPTIMIZATION 265 9 | 1 et 2 |Worksheot: [Figure 6.8(LP)-2015.xIsx]Figure 6.8 3 [Revert Grete: Tayan1s 241M 5 6 7| Solution Time: 0 Seconds. 8 | _ Iterations: 2 Subproblems: 0 9. |Sotver Options 10| Maxime 100 sec, Iterations 100, Precision 0.000001 11| Solve Without integer Constraints, Assume NonNegative 2 15 14 |Objective Gell ax) 15] Got ______Name Original Valuo_FinalValae— 16) “SESI2 Objective finction: max Sum of LHS (04333333333 0 18) p\Warable Cells Cell Name ‘Original Value Fal Valuo Tat 0 0.6666665667 Contin ‘SDS11 Variable value x2 [Constraints ‘Coll ‘Name CllValue Formola Status Slack 'SES13 Constraint 1 Sum of LHS 73 SESI3=SFSI5 Binding o FIGURE 6.11. Answer Report from Solver fr the linea programming problem Dil, and E12-E15. Three reports are produced in separate worksheets: Answers, Sensitiv- fty,and Limits, Any of these can be highlighted before clicking OK. Figure 6.11 shows the Areaer iReport, Figure 6.12 shows the Sensitivity Report it gives ranges for the right= Side parameters and the objective function coefficients (explained later in chapter Linear Programming Methods for Optimum Design). Also it give the Lagrange multiplier values, call the Shadow Prices. The Limits. Report (not shown) gives the lower and upper limi for each vatiable and the corresponding value of the objective function. Solver determines these limits by rerunning the optimizer with all variables fixed to their optimal values except ‘one, which is optimized, "The sign'convention for the Lagrange multipliers in the Solver is opposite to that ‘used in this fext, Therefore their sign in the Solver Report should be flipped to match + the sign conyention of this text. “1 NunenlcaL. yeT#008 FoR CONTINUOUS VARIABLE OFTIZATION 3 |Report Created: 7/11/2015 2: p | ze | Fj] G | #H [Figure 6.8(LP)-2015.xlsx]Figure 6.8 51:41 PM 6 |Variable Cells Final Reduced Objective Allowable Allowable Cel Name Value Cost___Coofficient_Increase Decrease ‘SCS11_ Variable value x1 1,666666667 0 1 71430 ‘SDS11 Variable value x2 0,666666667 0 4 16430 35 Constraints Final Shadow Constraint Allowable Allowable Cen ‘ame Value Price __R.H.Side_Incroase_Decrease SES13_Constraint 1 Sum of LHS 3 0 3 15+30 2 SES14 Constraint 2 Sum of LHS 4 1.666666667 4 2 2 SESIS” Constraint 3 Sum of LHS 1 -2.333333333 1 1 2 FIGURE 6.12 Sensitivity Report from Solver for the linear programming problem,

You might also like