Upload
bkrawat2008
View
231
Download
3
Embed Size (px)
Citation preview
7/28/2019 Modelling With Excel
1/25
Introduction to Excel
When you start up Excel97, you will see a screen like the following. Familiarize yourself with the
various components of the spreadsheet.
Data and cell references
All information in a spreadsheet is entered through data in cells. Each cell has a unique
reference given by its column letter and row number.
For example, the blue cell below is referenced as B38.
7/28/2019 Modelling With Excel
2/25
Once you have entered data into cells, you will want to perform some operations with them.
Basic arithmetic operators are:
+ : addition / : division ^ : exponentiation
- : subtraction * : multiplication
The usual order of operations holds.
Using the above operators, you can write formulas which manipulate the data you have
entered in cells.
Example 1 Let x=3. Calculate f(x)=x^3-4x.
Solution We need to store the x value in a cell. We also need to store the x^3-4x result
in another cell. Hence, we can make a simple table as follows. Note that you can
enter text into a cell as well. Using a spreadsheet makes it easy to annotate your
work.
x f(x)3 15
Now, the value of x is contained in the cell D72. The value for f(x) is computed by
the formula using the cell reference D72 in place of x.
So, the formula for f(x) using cell references is =D72^3-4*D72
This formula is typed into the cell E72. (Note: E72 is the same as e72)
Check it out Change the value in D72 from 3 to some other number
and press . What do you notice?
Check it out Change f(x) to be f(x)= 2x^2+1. Enter the formula using
cell references in E72.
Copying and Pasting
Now suppose you want to compute f(x) in Example 1 for x =1,2,3,4,5. You also want to
display all these values simultaneously by creating a table. Instead of typing the formula
over and over again, we can copy and paste. This is illustrated in the next example.
Example 2 Compute f(x) for x=1,2,3,4,5 and display the results in a table.
Solution Make columns for x and f(x). Enter the x values that you are interested in:
x f(x)
12
3
4
5
In the yellow f(x) cell, enter the formula for f(x)= x^3-4x. This gives the following:
x f(x)
1 -3 Click into this cell to see
Copyright (c) 2003 R.Narasimhan Page 2 of 25
7/28/2019 Modelling With Excel
3/25
2
3
4
5
Since we want to compute the values of f(x) for the other values of x as well, we
can copy the formula in the yellow cell as follows:
1. Select the yellow cell in the above table. Press c to copy.
2. Select the rest of the f(x) column. Press v to paste.
Note that the cell references automatically change to the
x-value directly to the left of the y-value.
Once you do this your table will look like the following:
x f(x)
1 -3
2 03 15 Click into these cells
4 48 to see how the formulas are
5 105 entered
how the formula is entered
Copyright (c) 2003 R.Narasimhan Page 3 of 25
7/28/2019 Modelling With Excel
4/25
Formatting and Printing
Saving files
Once you have done some work in your worksheet, you will want to save it first:
SAVE by going to the File menu and selecting Save As (if this is anew file) orSave (if you are resaving to an existing file). A dialog
box will appear and it is self explanatory.
Formatting pages
You will also want to format your work. Excel has many ways to help you
beautify your work, and it would fill many pages to describe all the possibilities.
Some basic page formatting will be done in the Page Setup option under the File menu.
Check it
out Pull up the Page Setup option and set margins, headers, footers, etc.
Previewing and Printing
You will next want to preview your work, so you bring up Print Preview under the File
menu.
Check it
out Use Print Preview to preview your work after page setup.
When you are ready to print, choose the Print option under the File menu
Formatting data and tables
But what about formatting your data and tables...
Once again, the possibilities are endless! The second row of icons in the tools bar are
all devoted to helping you format your data etc.
Check it
out Point your mouse at each of the icons in the second row of the toolbar to see
what it does.
Check it
out Type some text in a cell, select the cell, and click on some of the
formatting icons.
With all these bells and whistles, it is easy to get carried away and produce very busy
looking documents. Keep your formatting simple. Highlight the information youwant. Do not use too many fonts and too many sizes of letters.
Inserting Rows, columns, worksheets
To insert rows and columns, select the insertion point and go to Insert
in the menu bar. To insert a new worksheet, simply choose Insert -> Worksheet
More Formatting...
Copyright (c) 2003 R.Narasimhan Page 4 of 25
7/28/2019 Modelling With Excel
5/25
You will often want to increase width of a column. This is easy - position your
mouse cursor at the very top of the column line that you want to widen. You will see
a small picture like Use your mouse to widen the cell.
To wrap text within a cell, go to Format menu, choose Cells option . Go to
the alignment tab and check the Wrap text box.
These are some basic formatting operations which you will use often. Consult a general Excel
guide for a more extensive review.
Copyright (c) 2003 R.Narasimhan Page 5 of 25
7/28/2019 Modelling With Excel
6/25
Tables in Excel
In order to use the graphing features of Excel, you will need to generate tables of x and y
values first. In this section, you will learn to easily generate equally spaced entries for use as
x-values.
Example 1 Let us generate a table of values from -2 to 3 in increments of 0.5.
We could of course do this by hand but that would be laborious. Let
us have Excel automatically generate this table by using the Fill feature.
Solution
-2 1. Let the first x-value begin in the blue cell at left.
2. Select the blue cell with the mouse.
3. In the menu bar, go to Edit -> Fill -> Series
You will get the following dialog box.
4. You usually want your list in columns; so check the columns
box for "Series in" section. The type is "linear" since we want
equally spaced points. Step value is set to 0.5 since our
increments are in 0.5. Stop value is set to 3, since that is where
we terminate.
Click OK
5. On your left you should now see a filled column of values from
-2 to 3 in increments of 0.5, like the one below.
-2
-1.5
-1
-0.5
00.5
1
1.5
2
2.5
3
Copyright (c) 2003 R.Narasimhan Page 6 of 25
7/28/2019 Modelling With Excel
7/25
Shortcut If you are filling a column or row of equally spaced values, you can type in the fir
values of the series in two adjacent cells, highlight the two cells, and drag the val
moving your mouse to a cross hair at the lower right hand corner of the selecte
A table of x and y values
Example 2 Suppose we want to generate x and y values in a table. For example, findf(x)=3x-2 for the x-values given in the table above.
Solution Make a table with x and f(x) column headings. Fill the x-column as directed in
Example 1.
x f(x)
-2 -8
-1.5 Note: the table was formatted with
-1 borders using the formatting icons in the
-0.5 rightmost section of the second toolbar
0
0.51
1.5
2
2.5
3
Next, we need to fill in values for f(x). As you know, Excel only understands
cell references. Therefore, the first y-value will have the formula =3*d61-2
Click into the yellow cell and see how the formula is entered in the
cell entry box right below the toolbars.
We next fill the entire f(x) column by simply copying and pasting the formula
in the yellow cell:
1. Select the yellow cell in the above table. Press c to copy.
2. Select the rest of the f(x) column. Press v to paste.
Note that the cell references automatically change to the
x-value directly to the left of the y-value.
Copyright (c) 2003 R.Narasimhan Page 7 of 25
7/28/2019 Modelling With Excel
8/25
Copyright (c) 2003 R.Narasimhan Page 8 of 25
7/28/2019 Modelling With Excel
9/25
t two
ues down by
cells.
Copyright (c) 2003 R.Narasimhan Page 9 of 25
7/28/2019 Modelling With Excel
10/25
Graphs of Functions
Graphing a single function
To graph functions in Excel, you must first create a table of data with the information about the x and y
values. You then use Chart Wizard to create the plot. The following example will take you through the
process step by step.
Click for help
Example 1: Let us graph the function f(x)=2x^2+x. on Tables
We first create a table of x and y values. The y-values are given by f(x).
x f(x)
-2 6
-1.5 3
-1 1
-0.5 0
0 0
0.5 11 3
1.5 6
2 10
Next, select the entire table. A special macro called "grapher" has been written to plot the
table of values. Press the "grapher" button to the right side of the table. You should see a graph
similar to the one below. (The grapher button does not appear in printouts of worksheets.)
You can also access grapher anywhere in this workbook by pressing g
Click out of the graph that you created.
You can also click back into it and move, resize or delete it. Practice a little with your graph.
Check it out Modify the above table to graph the function
with the same set of x-values.
Make sure you change all the entries in the y-column. You can copy
the formula from the first y-column cell, then select the rest of the column
and paste the formula using V
f (x) = 3x2 + 4
-2
0
2
4
6
8
1012
-3 -2 -1 0 1 2 3
f(x)
f(x)
Copyright (c) 2003 R.Narasimhan Page 10 of 25
7/28/2019 Modelling With Excel
11/25
Remarks Notice that you have to specify the x-range of values in order to create your table and
then the graph. You must pick a suitable x-range so that the salient features of the
graph are captured. This may take a few trials before you get a suitable range of
x-values.
Graphing more than one function
To graph more than one function on the same plot with the same x-range of values, simply
create a table with multiple column headings, one for each function. The next example
illustrates this.
Example 2 Graph f(x)=x^2 and g(x)=x^3 on the interval [-2,2].
Solution We create the following table with x-spacing of 0.5. Note that f(x) and g(x)
each have a separate column.
x f(x) g(x)
-2 4 -8
-1.5 2.25 -3.375-1 1 -1
-0.5 0.25 -0.125
0 0 0
0.5 0.25 0.125
1 1 1
1.5 2.25 3.375
2 4 8
Invoke the grapher by pressing g. You will see a graph like the one below.
Check it out Graph the functions f(x)=x^3 and g(x)=3x+1 on the same graph.
Use x values from -3 to 3 with x-spacing=0.5. This example is on p.61.
Changing options in the graph
You can change the scale of the x and y-axes by clicking into the graph and double
clicking into the axes you wish to customize. The options that are possible are too
numerous to mention here. The best way is to play around with the dialog boxes.
Similarly, you can change the colors of the lines that are graphed by clicking
graph and double clicking the lines. Have fun exploring!!
-10
-5
0
5
10
-3 -2 -1 0 1 2 3
f(x)
g(x)
Copyright (c) 2003 R.Narasimhan Page 11 of 25
7/28/2019 Modelling With Excel
12/25
Graphs of Rational Functions
To graph functions in Excel, you must first create a table of data with the information about the x and y
values. You then use Chart Wizard to create the plot. The following example will take you through the
process step by step. Unlike the previous example, however, you must be careful when working
with functions which may not be defined for certain values of x.
Click for helpExample 1: Let us graph the function f(x)=1/(x-1) on Tables
We first create a table of x and y values. The y-values are given by f(x).
This function is not defined at x=1, and so that space for the y-value
is left blank.
x f(x)
-1 -0.5
-0.5 -0.66667
0 -1
0.5 -2
1
1.5 22 1
2.5 0.666667
3 0.5
Next, select the entire table. A special macro called "grapher" has been written to plot the
table of values. Press the "grapher" button to the right side of the table. You should see a graph
similar to the one below. (The grapher button does not appear in printouts of worksheets.)
You can also access grapher anywhere in this workbook by pressing g
If you need a closer look at the graph near x=1, you need to generate a new table
-2.5
-2
-1.5
-1
-0.5
0
0.5
11.5
22.5
-2 -1 0 1 2 3 4
f(x)
f(x)
Copyright (c) 2003 R.Narasimhan Page 12 of 25
7/28/2019 Modelling With Excel
13/25
from, say, 0 to 2 in increments of 0.1.
x f(x)
0 -1
0.1 -1.11111
0.2 -1.25
0.3 -1.428570.4 -1.66667
0.5 -2
0.6 -2.5
0.7 -3.33333
0.8 -5
0.9 -10
1
1.1 10
1.2 5
1.3 3.333333
1.4 2.5
1.5 21.6 1.666667
1.7 1.428571
1.8 1.25
1.9 1.111111
2 1
Select the above table and press g to invoke the grapher and you should get a
graph similar to the one above.
-15
-10
-5
0
5
10
15
0 1 2 3
f(x)
f(x)
Copyright (c) 2003 R.Narasimhan Page 13 of 25
7/28/2019 Modelling With Excel
14/25
Finding Zeros of a Function with Goal Seek
Finding x-intercept of a line
To find the x-value where a function is zero, you can use a feature of Excel called Goal Seek.
The next example will tell you how to use Goal Seek.
Example 1 Let the profit function for a company be given by p(x) = 200x - 4000,
where x denotes the number of items produced. The manufacturer
wants to know how many items to produce to break even. That is, she
wants to know when the profit will be zero.
Solution First we make a table with x and the formula for p(x):
x p(x)
10 -2000
Change the value of x and see what happens to p(x).Now, we want to find the value of x such that p(x) = 0. Since this is a
linear equation, there will be only one such value.
To do this, go to Tools -> Goal Seek. You will get the following dialog box:
Note: the boxes on the left
are just pictures! You need to
go to the Tools menu and start
Goal Seek to get the real thing.
In the Set Cell box, click the yellow box which stands for profit. In the To Value box,
type in 0. Hence, you should see the following:
Next, you want to fill in the last box called By changing cell. This is the x-value.
Therefore, click into the blue cell, and the dialog box will automatically record
its cell reference. Your completed box should look like the following:
Click into the cell to see
Copyright (c) 2003 R.Narasimhan Page 14 of 25
7/28/2019 Modelling With Excel
15/25
Click OK, and you will see the following box.
Click OK and the cell values in the blue
and yellow boxes for x and p(x) will be changed accordingly.
Check it out Scroll up to see what solution Goal Seek gave you.
You should get a value of x=20 to make p(x)=0. This
means that the company must make at least 20
products before realizing a positive amount of
profit.
Redo the problem by hand and recheck the solution.
Exercise What is the break-even point if p(x) = 300x-8800?
Copyright (c) 2003 R.Narasimhan Page 15 of 25
7/28/2019 Modelling With Excel
16/25
Finding zeros of a parabola
You know from algebra that a parabola could have 0,1 or 2 x-intercepts. Also, Goal Seek
will return only one x-intercept at a time. Which one it returns depends on the initial value
of x which is already in the box when you start Goal Seek. In the previous example, we knew
there would only be one x-intercept, and since the function was linear, it did not matterwhat value x had when starting.
Therefore, it is advisable to graph the function before starting Goal Seek. You can then
set the initial value for x close to the x-intercept you are interested in. We will illustrate this
in the next example.
Example 2 Find the zeros of the function f(x) = x^2-6x+7
Solution We first make a table of values and then graph the function usingthe grapher macro.
x f(x)
0 7
1 2 Click for help
2 -1 on Tables
3 -2
4 -1
5 2
6 7
Now select the entire boxed region above and press g to start the
grapher macro. You will get a graph like the following:
We see that there is one x-intercept near 2 and another near 4. We can
start Goal Seek in the following table with the starting value of x=2.
x f(x)
-4
-2
0
2
4
6
8
0 2 4 6 8
f(x)
f(x)
Copyright (c) 2003 R.Narasimhan Page 16 of 25
7/28/2019 Modelling With Excel
17/25
2 -1
Invoke Goal Seek from Tools-> Goal Seek, and follow the directions
given in the previous example. The box should look like the following after
you entered all pertinent data.
Click OK and you should get the following window.
The x-intercept near 2 is approximately 1.585816. Note that Goal Seek gives
an approximate answer. The y-value is very small but not quite zero.
Check it out Find the x-intercept near 4 using Goal Seek.
Your answer should be 4.414
Note: The grapher macro will work only within this workbook. To use
it for your problems, insert a new worksheet within this workbook by
choosing Insert -> Worksheet in the menu bar. You can then have access
to the grapher macro by pressing g
Copyright (c) 2003 R.Narasimhan Page 17 of 25
7/28/2019 Modelling With Excel
18/25
Finding Intersections of Graphs of Functions with Goal Seek
Before starting this worksheet, make sure you review the worksheet on finding
zeros. Click for help onFinding
zeros
We can use Goal Seek to find the intersection points of graphs of two functions.The next example will show you how.
Example Suppose you want to determine the intersection of the graphs of the
functions f(x)=x^3 and g(x)=3x+1.
Solution We first create a table of values for f(x) and g(x) as shown in the worksheet
for graphs of functions. X-values range from -3 to 3 with an x-spacing of 0.5.
x f(x) g(x)
-3 -27 -8
-2.5 -15.625 -6.5
-2 -8 -5-1.5 -3.375 -3.5
-1 -1 -2
-0.5 -0.125 -0.5
0 0 1
0.5 0.125 2.5
1 1 4
1.5 3.375 5.5
2 8 7
2.5 15.625 8.5
3 27 10
Graph the boxed region above by selecting it with the mouse and pressing gto invoke the grapher. You will get a graph similar to the one below.
There are three points of intersection: one near x=-2, another near x=0, and the
third near x=2.
We can now call Goal Seek. Remember that Goal Seek can find the zeros only
one at a time.
-30
-20
-10
0
10
20
30
-4 -2 0 2 4
f(x)
g(x)
Copyright (c) 2003 R.Narasimhan Page 18 of 25
7/28/2019 Modelling With Excel
19/25
The following table has been set up to use Goal Seek. Note that there is a new
column titled "f(x)-g(x)". The intersection points are those where f(x)-g(x)=0.
This is equivalent to the statement f(x)=g(x).
Goal Seek will give an error if you try to set value of f(x) equal to g(x). That is why
we must use f(x)-g(x) as the Set Cell reference.
First Intersection Point:Since this intersection point is near x=-2, the starting value of x will be -2
x f(x) g(x) f(x)-g(x)
-2 -8 -5 -3
Follow the same steps as in the worksheet Zeros of Functions to
call Goal Seek. We set the yellow colored cell to zero by changing
the x-value in the blue cell. Your box should look like the following.
Goal Seek Help
Click OK and you will get one of the intersection points in the blue box.
The approximate answer is -1.53. You should get this answer.
Second Intersection Point:
Since this intersection point is near x=0, the starting value of x will be 0.
x f(x) g(x) f(x)-g(x)
0 0 1 -1
Invoke Goal Seek as above. Fill in all cell references.
Your answer should be approximately -0.35.
Check it out Use the procedure outlined above, find the third intersection
point. It should be approximately 1.88.
Copyright (c) 2003 R.Narasimhan Page 19 of 25
7/28/2019 Modelling With Excel
20/25
Linear Regression
Linear regression is a procedure where we fit a linear function to a set of data which
seem to exhibit a linear relationship. It uses all the data points, not just two. Hence,
all the points in the data set may not necessarily pass through the line.
Let us illustrate how to find the line of best fit using the functions in Excel.
Example 1 The following table lists data
showing the price P of a one-day adult admission to Disney World for
years since 1993. Fit a regression line to this set of data.
Year
x: yrs.
since
1993
P: price
of adult
ticket
1993 0 34
1994 1 36
1995 2 37
1996 3 40.811997 4 42.14
1998 5 44.52
Solution We first make a scatterplot of the data.
Step A: Scatterplot
1. Select the x and the P columns above, including the column headings.
2. Click on the Chart Wizard icon. You should see the following
Copyright (c) 2003 R.Narasimhan Page 20 of 25
7/28/2019 Modelling With Excel
21/25
3. Select the XY Scatter for chart type. Select the dots only for chart sub-type.
See the figure below.
4. Click the Next button. You will see the following
5. Click the Next button. You will get a screen with options. Simply press
Copyright (c) 2003 R.Narasimhan Page 21 of 25
7/28/2019 Modelling With Excel
22/25
the Next button.
6. You will now at Step 4. Click the box that says to include the chart in this
worksheet. Then press the Finish button.
Congratulations! You have finished your scatterplot. It should look like the
following.
Step B: Inserting the regression line
1. Single-click any one of the data points in the scatterplot you created.
All points will be highlighted.
2. In the menu bar choose Chart -> Add Trendline. You see the following.
Choose the linear box.
3. Click into the options tab and check the box that says "display equation".
Click OK. You chart will be similar to the one below.
0
10
20
30
40
50
0 2 4 6
P: price of adult ticket
P: price of adultticket
Copyright (c) 2003 R.Narasimhan Page 22 of 25
7/28/2019 Modelling With Excel
23/25
You can click into the equation box and move it to place it where you can
read it better.
We are finished and the equation is y = 2.138x + 33.733.
Check it out Use the equation above to predict the ticket price in 2000.
y = 2.138x + 33.733
0
5
10
15
20
25
30
35
4045
50
0 2 4 6
P: price of adult ticket
P: price of adultticket
Linear (P: price ofadult ticket)
Copyright (c) 2003 R.Narasimhan Page 23 of 25
7/28/2019 Modelling With Excel
24/25
Polynomial Regression
Not all data sets possess a linear relationship. Some may be better fit through a quadratic,
cubic, or even a quartic. Polynomial regression is easy to perform in Excel.
The next example shows you how.
Example The following chart gives the age and average number of live birthsper 1000 women. We would like to fit a quadratic and cubic function
to this set of data and see which function fits the data better.
Age
# live births
per 1000
women
16 34
18.5 86.5
22 111.1
27 113.9
32 84.5
37 35.442 6.8
Solution Fitting the quadratic function
You essential follow the same steps as in the Linear Regression
worksheet.
Step A Follow all items in Step A of linear regression worksheet
Step B
1. Single-click any one of the data points in the scatterplot you created.
All points will be highlighted.
2. In the menu bar choose Chart -> Add Trendline. You see the following.
Choose the polynomial box with Order 2 for the drop down box.
3. Click into the options tab and check the box that says "display equation".
Copyright (c) 2003 R.Narasimhan Page 24 of 25
7/28/2019 Modelling With Excel
25/25
Click OK. You chart will be similar to the one below.
You can click into the equation box and move it to place it where you can
read it better.
The equation is y=-0.4868x^2 + 25.95x - 238.49
Fitting the quadratic function
Follow Step A as above. In Step B, part 2, change polynomial order to 3
for a cubic. Then follow the same steps as before.
Check it out Find the best cubic for this set of data. Your final graph
should be similar to the following.
We see that the cubic function is a better fit for the data that was given.
y = -0.4868x2 + 25.95x - 238.49
-20
0
20
40
60
80
100
120
0 20 40 60
# live births per 1000 women
# live births per1000 women
Poly. (# live birthsper 1000 women)
y = 0.0314x3 - 3.2196x2 +101.18x - 886.93
0
50
100
150
0 20 40 60
# live births per 1000 women
# live births per1000 women
Poly. (# livebirths per 1000women)