Tech Lab 1 (Excel).pdf - West Point

95 downloads 179 Views 892KB Size Report
Excel Lab. This document serves as an introduction to Microsoft Excel. ... begin by entering the number 2 into cell A1 and enter the number 3 into cell A2.
Excel Lab This document serves as an introduction to Microsoft Excel. Example 1: Excel is very useful for performing arithmetic operations. Suppose we want to add 2 + 3. We begin by entering the number 2 into cell A1 and enter the number 3 into cell A2. Once we have those entered we can create a formula to add the two numbers together. Anytime we want Excel to execute a formula we must start with an equals sign (=). In this case we can type ‘=A1+A2’ into cell A3, and when we hit ‘Enter’ the result that appears is, of course, 5.

Figure 1.1: Adding two numbers together in Excel The syntax for other simple mathematical operations (e.g., subtraction, multiplication, etc.) are what you might expect. Table 1.1 shows the keystrokes used for such operations. Table 1.1: Mathematical Operations in Excel Operation Addition Subtraction Multiplication Division Power (e.g., 52 )

Excel Syntax + * / ^

Example 2: Excel evaluates and plots functions on a discrete domain. The user may also ask Excel to interpolate and produce a continuous graph. Suppose we want to evaluate and create a scatter plot of the function 𝑓(𝑥) = 𝑥 2 over the domain [0, 10] using a step-size of one unit (i.e., consider 𝑥-values {0, 1, 2, …, 10}).

Step 1: Define the domain

1

In a new Excel worksheet create a column labeled ′𝑥′ containing the numbers 0, 1, 2,…, 10. The easiest way to do this is to enter 0 and 1, then let Excel do the rest. With the cells containing 0 and 1 highlighted, align your cursor with the lower right hand corner of the last cell highlighted. A small black cross will appear. Now click and drag down until a small 10 appears (Figure 2.1); upon releasing the mouse Excel will have filled in cells with the rest of the domain (Figure 2.2).

Figure 2.1: Highlight and drag down to fill a column with numbers 0, 1,…, 10.

Figure 2.2: Excel completes the entries of the domain.

Step 2: Define and evaluate the function over a discrete domain (Figure 2.3)

2

A. First, enter 𝑓(𝑥) = 𝑥 2 into cell B1. In cell B2 type an ‘=’ and then reference cell A2 by clicking on it (we do want to square the x-values after all). Finally, use the carrot ‘^’ symbol for an exponent and since we’re squaring type a ‘2’. B. Hitting ‘Enter’ will evaluate the formula you just input, resulting in 𝑓(0) = 02 = 0. C. To apply to the other values in the domain, highlight cell B2 and then click and drag as before.

Figure 2.3: Evaluating the function 𝑓(𝑥) = 𝑥 2 on the domain [0,10] using a step-size of one unit.

Step 3: Plotting the data

Highlight both columns of numbers that you wish to plot. Navigate to the ‘Insert’ panel and then click ‘Scatter.’ Excel will insert a scatter plot of the data (Figure 2.4).

f(x) = x^2 150 100 f(x) = x^2

50 0 0

5

10

15

Figure 2.4: A basic scatter plot in Excel Step 4: Formatting the graph It is important that anyone who opens your Excel file to be able to interpret your plot. This requires you to label the axes and provide a descriptive title for the graph. To add axis labels navigate to the Layout panel and then click the ‘Axis Titles’ button (Figure 2.5).

3

Figure 2.5: Navigating to add axis labels. You can add axis labels for both the horizontal and vertical axes. Similarly, you can add or change the title of your plot by clicking the ‘Chart Title’ button in the Layout panel. A final version of my plot is shown in Figure 2.6.

f(x) = x^2

Scatter plot of quadratic function 120 100 80 60 40 20 0

f(x)=x^2

0

5

10

15

x-values

Figure 2.6: Scatter plot of the function 𝑓(𝑥) = 𝑥 2 on the domain [0,10] using a step-size of one unit.

Example 3: Consider the discrete dynamical system 𝑝0 = 50,

𝑝𝑛 = 1.10𝑝𝑛−1 + 100.

We can use Excel to iterate this system and create a scatter plot of the sequence using the same steps outlined in Example 2. Step 1: Define the domain - In this example we will consider n = {0, 1, 2,…,25}. Step 2: Define the initial condition and iterate the recursion equation (Figure 3.1) A. First, enter 𝑝𝑛 = 1.10𝑝𝑛−1 + 100 into cell B1. Since we know the initial condition 𝑝0 = 50, 4

we type that into cell B2. B. Now we can enter a formula for the recursion equation into cell B3. To do this we type ‘=1.1*B2+100’ and notice that we reference cell B2 (𝑝𝑛−1 = 𝑝0 since 𝑛 = 1). Hit Enter to evaluate the formula for this cell. C. To apply to the other values in the domain, highlight cell B3 and then click and drag as before.

Figure 3.1: Iterating a recursion equation in Excel. Steps 3 & 4: Plotting the data and formatting the graph - We use the procedure outlined in Example 2 to produce a scatter plot (Figure 3.2) of the sequence.

Scatter plot of pn=1.10pn-1+100 12000 10000 pn

8000 pn=1.10pn-1+100

6000 4000 2000 0 0

10

20

30

n

Figure 3.2: Scatter plot of a recursion equation in Excel.

5

Example 4: Using Solver We can use Excel to minimize or maximize problems using the Solver add-in. To load Solver select Excel Options from the “Office” button in the upper left of the screen. Another screen will appear with several options, choose the Add-Ins options on the left-hand toolbar. At the bottom of the screen will be another drop-down menu. Choose Excel Add-ins from this menu and click the Go button. A smaller window should appear with multiple available Add-ins; select theAnalysis ToolPak and Solver options as shown in Figure 4.1.

Figure 4.1: Add – In Dialogue Box We can use Solver to determine the best exponential model that fits a given data set. Open exponential.xls and minimize the SSE by changing the exponential model parameters in the form 𝑎 ∗ 𝑏 𝑥 + 𝑑. Step 1: Go to Solver under the Data tab.

Step 2: Set the target cell to be the SSE cell, D18. Click on the button next to min and in the “By Changing Cells” input, highlight the parameter values, B15:B17. See Figure 4.2. Step 3: Click Solve and click okay when prompted to keep Solver solution. The new model parameters and minimized SSE should now be displayed. Solver finds a local maximum or minimum so reasonable initial estimates are key in this example.

6

Figure 4.2: Minimizing SSE with Solver

Example 5: Using Excel for Simple Linear Regression and Descriptive Statistics. Open the studentdata.xls file. Find the mean, mode, and variance for the height of cadets. Step 1: Under the data tab, click on data analysis, highlight descriptive statistics and click ok. Step 2: In the input range highlight the height data, F1:F63, and click on the labels in first row button. Set the output range to be in the same worksheet and click on summary statistics. Click OK.

Figure 5.1: Descriptive Statistics Excel will output the mean, mode, variance, and various other descriptive statistics of the data. Now use Excel to fit a simple linear regression model where foot length is the predictor and hand length is the response. Step 1: Under the data tab, click on data analysis, highlight regression and click ok.

7

Step 2: In the input Y range highlight the hand length column, I1:I63. In the input X range, highlight the foot length column, G1:G63. Click on labels and change the output range to be in the current worksheet. Click OK. See Figure 5.2.

Figure 5.2: Simple Linear Regression The output from the regression shows the model coefficients along with the ANOVA table, model utility test p-vale, R squared value along with other information shown in Figure 5.2.

Problems: Use Excel to complete the following problems. Be sure to save your work in a place you will remember. You may want to revisit these problems at a later time. 1. Plot the function 𝑓(𝑥) = 𝑥 3 − 12𝑥 + 1 over the domain [-5, 5] using a step-size of one unit. Be sure to include axis labels and a descriptive title. 2. Use Excel to find the sum of the first 200 positive integers. (Hint: Excel has a built-in Sum command.) 3. Use Excel to iterate the following discrete dynamical system and find 𝑝150 . Create a scatter plot of your results. Be sure to include axis labels and a descriptive title. 𝑝𝑛 = 0.95𝑝𝑛−1 𝑝0 = 15000,

4. Suppose you borrow $12000 for a period of ten years at an interest rate of 12% per year and the interest is compounded monthly. How much do you have to repay at the end of ten years? What is the effective annual interest rate? 5. Suppose that we send one rocket to the moon each year with 75 colonists for twenty years to set up a permanent colony, and the birthrate on the moon is 5% -- that is, each year the number of babies born is 5% of the current population. Additionally, assume the death rate is 1% per year. What would the population of the colony be after twenty years? What assumptions did you make? Use a discrete dynamical system to model this situation and answer the questions.

8

6. Using the exponential.xls file, use the x and f(x) columns to fit a power model of the form 𝑓(𝑥) = 𝑎 ∗ (𝑥 − 𝑐)𝑏 + 𝑑. Use Solver to find the model that minimizes SSE.

7. Using the studentdata.xls file, plot the number of Facebook friends vs. GPA. Do you need to clean the data up a bit? Perform a simple linear regression and comment on the appropriateness of the model.

9