代做ECON10151: Computing for Social Scientists Lecture 2: Excel Solver代做留学生SQL 程序

Lecture 2: Excel Solver

ECON10151: Computing for Social Scientists

September 29, 2024

Excel’s Solver is a versatile tool designed to help users find optimal solutions to complex decision-making problems. Whether you’re allocating resources in finance, managing supply chains in logistics, or scheduling operations, Solver allows you to work within constraints and identify the best outcome, such as maximising profits or minimising costs.

For example, imagine you’re managing a factory and need to determine the ideal production levels of two products, given a limited supply of materials and labour. Solver can help you calculate the most efficient allocation that maximises profit while staying within your resource limits.

In essence, Solver takes your objective—like increasing profit or reducing expenses—and tests different combinations of variables, subject to the constraints you set. It simplifies decision-making where trade-offs are involved, ensuring the result is not just mathematically sound but also practical for real-world scenarios.

1 How to Install Excel Solver

Solver is an Excel add-in that doesn’t load automatically when you install Excel, but it’s easy to enable. Whether you’re using a Mac or Windows, the steps are straightforward, though they differ slightly between the two operating systems.

1.1 Mac

To install Solver on a Mac, follow these steps:

1.  Open Excel.

2.  Click on the Tools menu at the top.

3.  Select Excel Add-Ins.

4.  In the Add-Ins available list, tick the box for Solver Add-In.

5.  Click OK.

6. Note:

•  If Solver Add-In isn’t listed, click Browse to find and install it.

If youre prompted to install the Solver Add-In, select Yes.

7.  Once installed, youll see the Solver button under the Data tab.

1.2 Windows

To install Solver on Windows, follow these steps:

1.  Open Excel.

2.  Click File in the top-left corner, then select Options.

3.  In the Excel Options window, click Add-Ins.

4.  At the bottom of the window, next to Manage, ensure Excel Add-ins is selected, then click Go.

5.  Tick the box for Solver Add-In in the Add-Ins available list.

6.  Click OK.

7. Note:

If the Solver Add-In is missing from the list, click Browse to locate and install it.

If asked to install the Solver Add-In, select Yes.

8.  Once installed, youll find the Solver button in the Analysis group on the Data tab.

2 A Worked Example: Diet Optimisation

In this example, we’ll explore a practical scenario often faced by fitness trainers and dieticians: how to create a cost-effective yet nutritionally balanced meal plan. Using Excel Solver, we’ll navigate through the constraints of this problem to optimise our meal choices,aiming for the best nutritional outcome at the lowest cost.

Let’s consider four meal options:  Salad, Protein Shake, Grilled Chicken, and Pasta.  Each of these meals offers different nutritional values and comes with a specific cost:

Salad

Protein Shake

Grilled Chicken

Pasta

Calories

300

250

450

600

Protein (g)

10

30

35

12

Fat (g)

7

3

10

15

Cost ($)

6.5

5

12

8

The challenge is to create a meal plan that meets specific nutritional goals while minimising the total cost. In this case, the goals are:

At least 1800 calories per day,

A minimum of 90 grams of protein,

No more than 45 grams of fat.

Here’s how Solver comes into play. We need to select the number of servings of each meal (Salad, Protein Shake, Grilled Chicken, and Pasta) that together satisfy these nutritional requirements. At the same time, we aim to minimise the total cost of the meal plan. This type of problem is ideal for Solver, as it allows us to work within defined constraints (calories, protein, and fat limits) while optimising for cost.

For example, you might have a client with a fixed daily budget but also the need to maintain certain nutritional standards. By inputting the nutritional data and cost for each meal into Excel, Solver can identify the most cost-effective combination that achieves the target nutritional intake.  This not only saves time but also ensures that the plan is scientifically backed by quantitative analysis.

3 How to Use Solver in a Nutshell

To effectively use Excel Solver for optimisation problems, follow these key steps. Solver works by varying the values of specific variables (behind the scenes) within the limits you define to find the best possible solution to your problem.  Here’s a simple guide to get started:

1. Construct a Detailed Spreadsheet:  Start by organising your spreadsheet with all relevant data.   Make sure that the problem components—like costs, nutritional values, or other important factors—are clearly laid out so that Solver can interpret them correctly.

Identify Decision Variables: Decision variables are the values Solver will adjust to find the optimal solution. In Excel, these are also known as Changing Cells.  For example, in the diet optimisation problem, the decision variables are the number of servings of each meal option.

Define the Objective Function: The objective function is what you want to optimise, such as minimising cost or maximising profit. In Solver, this is referred to as the Set Objective. In our diet example, the objective function is the total cost of the meal plan, which we aim to minimise.

Incorporate Constraints: Constraints are the rules or limits that your solution must follow, such as nutritional needs or budget limits.  These ensure that Solver’s solution makes sense in real-world situations.  In our case, the constraints are the minimum and maximum nutritional goals, like needing at least 1800 calories and no more than 45 grams of fat.

2. Run Solver:  Once your spreadsheet is set up with the decision variables, objective function,  and constraints, you’re ready to run Solver. Head to the Data tab, click on Solver, and it will begin adjusting the decision variables within your constraints to find the best possible outcome.

3. Review the Solution: After Solver has finished, it will display the optimal solution directly in your spreadsheet.  This will include the values for the decision variables that best meet your objective, while adhering to the constraints. At this point, you can check the results and ensure they are sensible for your particular problem.

By following these steps, you can confidently use Solver for various optimisation challenges, whether it’s finding the best resource allocation, balancing a budget, or creating cost-effective diets.  Solver handles the complex calculations, leaving you to focus on analysing the results and making informed decisions.

4 Solving the Diet Optimisation Problem

4.1 Setting up the Spreadsheet

To solve the diet optimisation problem using Excel Solver, we need to organise our data so that Solver can process it efficiently. This involves defining the decision variables, setting up the objective function, and establishing the necessary constraints. Follow these steps to set up your spreadsheet:

Step 1: Define the Decision Variables

In cells B2 : E2, create headings for each type of food (e.g., Salad, Protein Shake, Grilled Chicken, Pasta).

•  In cells B3 : E3, enter initial trial values for the amount of each food to include in the meal plan. Make sure at least one of the values is greater than zero to allow Solver to work with a non-empty starting point.

Step 2: Set up the Objective Function

Reference the number of units of each food from your decision variables by entering =B3, =C3, etc., in cells B7 : E7.

It’s important to reference the number of units rather than manually typing them. By referencing, any changes made to the decision variables (in B3 : E3) will automatically update the rest of your calculations.  This not only saves time but also reduces the risk of errors, ensuring consistency across your calculations.

In cells B8 : E8, input the cost per unit for each food item (e.g., 6.5 for Salad, 5 for Protein Shake, etc.).

•  To calculate the total cost of the meal plan, use the SUMPRODUCT function in cell B10. The formula will look like this: = SUMPRODUCT(B7 : E7, B8 : E8)

The SUMPRODUCT function multiplies the number of units of each food (in B7 : E7) by its respective cost (in B8 : E8), and then sums the results.  This function essentially performs element-wise multiplication of B7 × B8, C7 × C8, and so on, then adds them together. The formula is equivalent to:

Total Cost = B7 × B8+C7 × C8+ D7 × D8+ E7 × E8

This gives the total cost of the diet based on the quantities you have selected for each food.

Step 3: Establish the Constraints

•  Recreate the table from the problem statement, listing the nutritional information (calories, protein, fat) for each food item in cells B14 : E16.

•  Use the SUMPRODUCT function again to calculate the total nutrients based on the amounts chosen in the decision variables. For example, to calculate total calories, use:

= SUMPRODUCT($B$7 : $E$7, B14 : E14)

This will give you the total calories consumed based on the servings of each food.

–  Note: The dollar signs ($$) in the formula ensure that the cell references remain fixed (absolute references) when copying the formula to other cells.

In Column G, specify the inequalities for your constraints (e.g., >=  1800 for calories, <= 45 for fat).

In Column H, enter the target values for each constraint (e.g., 1800 for calories, 45 for fat).

By following these steps, you will have constructed a well-organised spreadsheet that Solver can use to optimise the meal plan. Once everything is set up, you are ready to run Solver and find the best solution.

4.2 The Solver Parameters Dialog Box

To effectively use Solver, follow these steps:

1. Open the Solver Parameters Dialog Box

Begin by navigating to Data > Solver to open the Solver Parameters Dialog Box.

2. Set the Objective and Problem Type In this step:

•  In the "Set Objective" box, specify the cell that calculates the objective function (e.g., Cell B10, which calculates the total cost).

•  Choose whether you want to minimise or maximise the objective. For our problem, since we want to minimise the total cost, select " Min".

3. Identify Decision Variables

Next, specify the cells that represent your decision variables:

•  Click in the "By Changing Variable Cells" box.

•  Select the cells containing the decision variables (e.g., B3 : E3).  These are the cells Solver will adjust to find the optimal solution.

4. Add Constraints

To ensure that Solver respects the constraints in the problem:

Click the "Add" button on the right.

•  In the "Cell Reference" box, select the cell that calculates the total for the constraint (e.g., for calories, choose Cell F14, which sums the total calories consumed).

•  Choose the appropriate constraint type (<=, >=, =) and then input the target value for that constraint (e.g., Cell H14, which specifies at least 1800 calories).

•  Click "OK" to add the constraint.

Repeat this process for each constraint (e.g., protein, fat) to ensure Solver respects all nutritional requirements.

5. Make Variables Non-Negative

Ensure all decision variables remain non-negative:

•  Check the box titled  "Make  Unconstrained Variables  Non-Negative".   This ensures that all variable values are greater than or equal to zero, meaning Solver won’t suggest negative servings of food.

6. Select the Solving Method Choose the solving method:

•  Select "Simplex LP" as the solving method. This method is appropriate for linear programming problems like this one.

7. Solve the Problem

Once everything is set up:

•  Click the "Solve" button to run Solver and find the optimal solution.  Solver will adjust the decision variables and provide a solution that minimises the cost while meeting all the constraints.

4.3 Solution

Once you’ve completed the Solver process, you’ll notice the following changes in your spreadsheet:

•  The Solver Parameters Dialog Box will close automatically.

The values in the decision variable cells (e.g., B3 : E3) will update to reflect the optimal solution that Solver has found.

•  As a result, the objective function and caluculations under constraints in your spreadsheet will also adjust to reflect the updated decision variables.

This updated information indicates that Solver has successfully applied the optimal solution to your optimisation problem.

4.4 Final Remark:

In practical applications, serving sizes are usually represented as whole numbers (e.g., you can’t eat half a serving of grilled chicken). If the optimal solution contains fractional serving sizes, this might appear unusual.

Question: How might we adjust our constraints or model to ensure that the resulting serving sizes are whole numbers?

Answer: To ensure that Solver produces whole numbers for the serving sizes, you need to adjust the constraints to require integer values for the decision variables. Follow these steps:

Open the Solver Parameters Dialog Box again by clicking on Data > Solver.

Click the "Add" button to introduce a new constraint.

In the "Cell Reference" box, select the cells representing the decision variables (e.g., B3 : E3).

•  In the "Constraint" box, select int (integer), which ensures that the values for the decision variables are restricted to whole numbers.

Click "OK" to add the constraint, and then click "Solve" again to re-run Solver with the updated settings.

By adding this integer constraint, you ensure that Solver provides solutions with whole number servings, which makes the results more practical for real-life applications.


热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图