You are on page 1of 41

Mathematical Modeling using Excel

By
Ajit Kumar @ ICT Mumbai

MODULE I
Getting Started With Excel
When you open the excel programme you get a window that look like the figure 1. As you can see this
consists of large number of rectangular boxes called cells, a place where the data in input. A collection of
cells is called a worksheet. Each worksheet is given a name in the worksheet tab which appears in the
bottom left of the excel window. The name of the worksheet can be changed, a new worksheet can be
added, deleted or even reshuffled. All these can be achieved by right clicking on the worksheet tabs and
choosing the appropriate options.

Name Box  Formula Box

Worksheet  Tabs

Figure 1

A collection of worksheets is called a workbook. Each worksheet contains 1048576=220 rows and
16384=214 columns. One can have 210=1024 worksheets in one workbook. Thus one workbook can
handle a large number of data.

 
Cell References: Each cell has a reference number which is indicated by the column number and row
number. As soon as mouse is clicked on a cell its reference number appears in the name box. You can
also go to a particular cell by entering the cell number in the name box. For example if you wish to go to
the cell which is in the 100th row and VZ column, just enter VZ100 in the name box. The column
numbers vary from 1 to 1048576 and column numbers vary from A to Z then AA to AZ and so on up to
XFZ.

Entering the data or text: A cell can contain data, text, date and formula. This can be entered by
selecting the desired cell, tying the desired content and pressing Enter to finish typing. The data can be
also entered by selecting the cell and entering the content in the formula bar.

Formatting Cells: The format of cell or a range of cells can be easily changed by selecting a cell or a
range of cells and right clicking. Now select Format Cells this will open the windows as in Figure 2 and
you can chose the appropriate options. For example in order to choose currency EURO select the option
Currency and from the drop down menu and chose the € option. Similarly if you wish to change

Figure 2

the number format select the Number from the category option and then choose the number of decimal
places you wish to display inside the cell.

The Font tab allows you to change the font size, font style and colors etc inside cells. Border allows you
to change the border around the cells or range of cells.

Many a time the text entered does not fit in one cell, in such cases select the Alignment option to open a
window as shown in the Figure 3 and merge a range of cells in which entire text can be fitted. You may
also choose wrap text.

 
Figure 3

Entering the Formula: A formula in Microsoft Excel always begins with an equal sign (=). The equal
sign tells Excel that the following numbers or cells make up a formula. The general rules of mathematics
apply here in deciding the order of operation within a formula. In order to enter the formula in the cell
you do the following

1. Select the cell in which you want to enter the formula.


2. Type an equal sign = to activate the Formula Window and type the formula if you already know
it.
3. After this formula is typed in press <ENTER>, the result is immediately shown

The formula can be also entered through Formula Bar.

1. Click on cell in which you want to enter the formula. Now click on the formula bar and type an
equal to = sign. (Note that any formula always begins with = sign.)
2. Now click on insert function option to get a list of function from the menu.
3. Choose a formula listed and click on the OK button. Fill in the required fields within the
parentheses in the formula.
4. After you have completed the formula or chosen one from the Formula menu, press <ENTER>

A B C D E
1 x y z sum Average
2 2 3 9 =SUM(A2:C2) =AVERAGE(A2:C2)
3 6 9 11 =SUM(A3:C3) =AVERAGE(A3:C3)
4 7 -2 6 =SUM(A4:C4) =AVERAGE(A4:C4)
Figure 4

 
Auto filling the data: Instead of entering data manually in a worksheet, you can use the Auto Fill
feature to fill cells with data that follows a pattern or that is based on data in other cells. Excel provides
several ways of filling cells with data, and can even work out the kind of data to be placed in cells. To
access the Fill function, either use Edit->Fill from the menu, or use the Fill Handle which appears on the
bottom, right of any selected cell. The Fill handle is usually dragged down or across (right), but be careful
that the mouse pointer has become a cross shape before you start to drag.

Suppose you wanted to enter the numbers 2 to 20 with step size 2 down a column of cells starting at A1.
The quick way of doing this is to enter 2 in cell A1 and 4 in cell A2. Now highlight cells A1 and A2 by
dragging across them, then drag the Fill handle (now on cell A2) down to cell A10.

Another way of doing the above, is to enter 2 in cell A1, then enter a formula =A1+2 in the cell A2. Now
dragging down the Fill handle of cell A2 to A10 will replicate the formula in a relative fashion.

Next suppose we want to fill the second column B1 to B10 with sin of the value in the first column. First
type =sin(A1) in the B1 cell. Click on the this cell and Fill Handle, now either double click on the right
bottom corner or click the Fill Hand and drag down.

Creating Charts and Graphs:


To illustrate creating graph and chart, open a blank worksheet and input the following data and use the
following steps. (We wish to plot the graph of y=x+sin(x) when x varies from -2 to 2 in a step of 0.5

A B C D E F G H I J
1 x -2 -1.5 -1 -0.5 0 0.5 1 1.5 2
2 y -2.9093 -2.49749 -1.84147 -0.97943 0 0.979426 1.841471 2.497495 2.909297
Figure 5

1. Input x and y in the cell A1 and A2 respectively.


2. Input -2 in B1 and =B1+0.5 in C1 and drag to the right up to J1 using the Fill Handle.
3. Input =B1+sin(B1) in B2 and drag to the right up to J2 using the Fill Handle.
4. Now select range of cells A1:J2 and click on to get the chart wizard. You may also click on
insert->Chart Wizard-> Scattered to get the following graph as in Figure 6.

 
y
4
2
0 y
‐3 ‐2 ‐1 ‐2 0 1 2 3

‐4

Figure 6

Creating a Column Chart

1. Input the following data as in Figure 7.

A B
1 Months Expenditure
(in thousand
2 January 5
3 February 8
4 March 4
5 April 7
6 May 9
June 6
Figure 7

2. Click on Insert-> Column A and select the 2-columns to get the following graphs as in
Figure 8.

Expenditure
(in thousand
10

5 Expenditure
(in thousand
0
January February March April May June

Figure 8

 
Linear Fit Using Least Square

Example 1.1. Suppose a biologist records the number of pulses per second of the chirps of a cricket at
different temperature (in Fahrenheit). The data collected is as follows:

Table 1

Temperature 72 73 89 75 93 85 79 97 86 91
Pulses /s 16 16.2 21.2 16.5 20 18 16.75 19.25 18.25 18.5

1. Fit a straight line of this data (where temperature is on the x-axis. How well does the model fit
the data?
2. What is the slope of this line? What does the sign of the slope tell you about the relationship
between pulse/s and temperature?

Solution: Note that if be the fitted line then using the least square method it is easy to
obtain

∑ ∑ ∑ ∑
∑ ∑

∑ ∑ ∑
∑ ∑

Now follow the following steps:

1. Start a new worksheet and input the data in cells ranging from A1:B11 as in Figure 9. Rename
the worksheet as pulse_rate.

A B C D E
1 x y
(Temp) (Pulse rate) f(x) (y-f(x)^2 sum of squares
2 72 16 =$B$14*A2+$B$15 =(B2-C2)^2 =SUM(D2:D11)
3 73 16.2
4 89 21.2
5 75 16.5
6 93 20
7 85 18
8 79 16.75
9 97 19.25
10 86 18.25
11 91 18.5

 
12
13
14 m 2 Fitted Line
15 b 0 x y
16 70 =B14*D16+B15
17 100 =B14*D17+B15
Figure 9

2. Highlight the data in the range A1:B11 and click on Insert->Scatter to get the graph. You
can change the range of x-axis and y-axis by first clicking the plot area and choosing the
Fotmat-> Axes. You may also change the title of the graph, and axes title by choosing these
options.

Temp vs. Pulse rate
24
22
20
Pulse Rate

18
16
14
12
10
60 65 70 75 80 85 90 95 100
Temperature

3. Add the formula as in Figure 10 and fill the remaining cells in column C and D.

C D E
1
f(x) (y-f(x)^2 sum of squares
2 =$B$14*A2+$B$15 =(B2-C2)^2 =SUM(D2:D11)
Figure 10

4. Now use solver to find the value of m and b that minimizes the total sum of squares. To do this
select Data->Solver.
a. Next set the Target cell : select $E$2
b. Set Equal To: select Min
c. Under By Changing Cells: select $B$14:$B$15
d. Click the solve button.
5. This gives m=0.168283 and b=3.9292

 
6. You may calculate the value of m and b manually by applying the above formula. Use
the following formula as shown in the Figure 11.

G H I J

sum x sum y sum x^2 sum xy


1
=SUMPRODUCT(A2 =SUMPRODUCT(A2:A1
=SUM(A2:A11) =SUM(B2:B11) :A11,A2:A11) 1,B2:B11)
2

4
Manual
Calculations
5

6
=(I3*H3-
b J3*G3)/(10*I3-G3^2)
7
=(10*J3-
m G3*H3)/(10*I3-G3^2)
8
Figure 11

7. Next we can use the inbuilt feature of add the best fit line also known as trend line. Right click
on the data in the chart and select Add Trendline. Choose Linear option and Display equation
on chart. Verify that the two calculation in step 5 and 6 and 7 are same.

22

20 y = 0.168x + 3.929

18

16

14

12

10
60 65 70 75 80 85 90 95 100
Temperature

 
8. Excel also has built in functions SLOPE and INTERCEPT to calculate the slope and
intercept of the fitted line. Use the formula as shown in the Figure 12 to find the slope
and intercepts.

A B
21 b =INTERCEPT(B2:B11,A2:A11)
22 m =SLOPE(B2:B11,A2:A11)
Figure 12

Conclusion: Note that the slope of the best fit line is positive which indicates that the pulse rate increases
as the temperature increases.

 
MODULE II
Empirical Models
In this module we shall build some models that captures the trend of the data solely based on the data and
do not try to use any theory behind. We try to predict the values rather than explain the behavior. These
are often called empirical model.

Exampl 2.1. (Logarithmic Model) Consider the following data

Table 2

Male Life
Person/Physician Expectancy
Country (P) (L)
Spain 275 74
USA 410 72
Canada 467 73
Romania 559 67
China 643 68
Taiwan 1010 70
Mexico 1037 67
S. Korea 1216 66
India 2471 57
Morocco 4873 62
Bangladesh 6166 54
Kenya 7174 59

We shall try to fit the curve to the above data. This is achieved by graphing L verses
ln(P) and fitting a straight line. We follow the following steps:

1. Input the data in cells ranging from A1 to C13. In the column D2 enter the formula =ln(B2) and
fill the rest of the cells in that column by using the Fill Handle.

A B C D
1 Person/Physician Male Life Expectancy
Country (P) (L) ln(P)
2 Spain 275 74 5.616771
3 USA 410 72 6.016157
4 Canada 467 73 6.146329
5 Romania 559 67 6.326149
6 China 643 68 6.466145
10 

 
7 Taiwan 1010 70 6.917706
8 Mexico 1037 67 6.944087
9 S. Korea 1216 66 7.103322
10 India 2471 57 7.812378
11 Morocco 4873 62 8.491465
12 Bangladesh 6166 54 8.726806
13 Kenya 7174 59 8.878219
Figure 13

2. Create a graph of L verses ln(P) . Now right click on the data and chose the option Add
Trendline. Also display the equation of the fitted line. We obtain the following graph as in
Figure 14. We get the slope=-5.2876 and intercept=103.4

80

75
L
i
f 70
e
65
E
x
p 60
e y = ‐5.287x + 103.4
c
55
t

50
5 5.5 6 6.5 7 7.5 8 8.5 9
Persons/Physician ln(P)

Figure 14

3. The slop and intercepts can be also computed using the inbuilt functions as given in Figure 15.
Input =SLOPE(C2:C13,D2:D13) in C15 to get the slope and =INTERCEPT(C2:C13,D2:D13) in
the cell C16.

B C
15 m= =SLOPE(C2:C13,D2:D13)
16 b= =INTERCEPT(C2:C13,D2:D13)
Figure 15

11 

 
4. Now compute the predicted value of the life expectancy in the column E. Input the formula
=$C$15*D2+$C$16 in the cell E2 and fill the remaining cell using the Fill Handle.

1 expected value
2 =$C$15*D2+$C$16
Figure 16

5. Create a graph to compare the observed value of the life expectancy and the expected values of
the life expectancy. Note that the two values are very close to each other which means the model
is a good fit.

80
E
L x 75
i p 70
f e
e c 65
t 60
5 6 7 8 9 10
Persons/Physician ln(P)

Observed values

Figure 17 

6. Now we compute the Residual=Observed value – Predicted value

F
1 Residual
2 =C2-E2
Figure 18

Input the formula =C2-E2 in F2 and fill the remaining cells using Fill handle. Note that
the positive residual mean that the predicted value is less than the observed value.
Similarly negative residual mean that the predicted value is more than the observed value.

7. Finally plot the residuals verses P. It is easy to see that roughly half the residuals are positive and
half are negative. This indicates that the model does not tend to over predict or under predict the
values of L.

12 

 
Residual
4

0
Residual
0 2000 4000 6000 8000
‐2

‐4

‐6

Figure 19

Example 2.2. (Power Model) We now try to fit the curve to the life expectancy data of
Table2. Note that this model can be converted into a linear model by taking logarithm both sides.

A B C D E
1
Male Life
Person/Physician Expectancy
Country (P) (L) ln(P) ln(L)
2 Spain 275 74 5.616771098 4.304065
3 USA 410 72 6.01615716 4.276666
4 Canada 467 73 6.146329258 4.290459
5 Romania 559 67 6.326149473 4.204693
6 China 643 68 6.466144724 4.219508
7 Taiwan 1010 70 6.91770561 4.248495
8 Mexico 1037 67 6.944087208 4.204693
9 S. Korea 1216 66 7.103322063 4.189655
10 India 2471 57 7.812378206 4.043051
11 Morocco 4873 62 8.491465043 4.127134
12 Bangladesh 6166 54 8.726805608 3.988984
13 Kenya 7174 59 8.878218658 4.077537
Figure 20

1. Open a new worksheet and input the data in cells ranging from A1 to C13. In the column D2
enter the formula =ln(B2) and fill the rest of the cells in that column by using the Fill Handle.
Similarly in the cell E2 enter the formula =ln(C2) and the remaining cells using the Fill Handle.

13 

 
2. Plot the graph of the ln(L) verses ln(P) and fit the trendline and displaying the equation of the
fitted line.

4.35
4.3
4.25
4.2
ln(L)

4.15
ln(L)
4.1
Linear (ln(L))
4.05
y = ‐0.082x + 4.767
4
3.95
5 6 7 8 9 10
ln(P)

Figure 21

Clearly the slope of the line is=-0.0823 and the intercept is 5.7675. Thus

.
ln 4.7675 117.62 0.0823
.
Thus the fitted mode is 117.62

E F
15 a= =EXP(C16)
16 b= =C15
Figure 22

3. We find the predicted values and residuals in the column E and F by putting the formula as in the
following table and filling the remaining cell using Fill Handle.

F G
1 Expected
value Residual
2 =$F$15*B2^($F$16) =C2-F2
Figure 23

4. Finally we plot the graph of residuals verses P. It is easy to see again that roughly half of the
residuals are positive and half of them negative indicating that this is a good model.

14 

 
Residual for Power Model
4

0
0 2000 4000 6000 8000 Residual
‐2

‐4

‐6

Figure 24

Example 2.3. (Exponential Model) Now we fit the exponential model defined by

To the data in the Table 2. This model again can be transformed to a linear model by taking
logarithm both sides

ln ln

Do the following steps

1. Input the entire data as before in the cell range A1 to C13. Create ln(L) in the column D as in
Figure 25. Now plot the graph of ln(L) verses P and add the trendline with displaying the
equation of the fitted line.
2. Find the slope and intercepts using the formula =SLOPE(D2:D13,B2:B13) and
=INTERCEPT(D2:D13,B2:B13) in the cell C15 and C16 respectively. We get slope=0.00003
.
and intercept=4.2561. Thus we get 70.53.
3. Find the expected value of life expectancy by entering the formula =$E$15*EXP($E$16*B2) in
the cell E2 and fill the remaining cell using Fill Handle.
4. Find the residuals by entering the formula =C2-E2 in F2 and filling the remaining cell using Fill
Handle.
5. Finally plot the residual as in Figure 27. It is easy to see that the residuals are not small. This
means the exponential model is not a good model for the given data of life expectancy.

A B C D E F

1 Country Person/Physician Life Expectancy ln(L) Expected value Residual


(P) (L)
2 Spain 275 74 =LN(C2) =$E$15*EXP($E$16*B2) =C2-E2

15 

 
3 USA 410 72 =LN(C3) =$E$15*EXP($E$16*B3) =C3-E3
4 Canada 467 73 =LN(C4) =$E$15*EXP($E$16*B4) =C4-E4
5 Romania 559 67 =LN(C5) =$E$15*EXP($E$16*B5) =C5-E5
6 China 643 68 =LN(C6) =$E$15*EXP($E$16*B6) =C6-E6
7 Taiwan 1010 70 =LN(C7) =$E$15*EXP($E$16*B7) =C7-E7
8 Mexico 1037 67 =LN(C8) =$E$15*EXP($E$16*B8) =C8-E8
9 S. Korea 1216 66 =LN(C9) =$E$15*EXP($E$16*B9) =C9-E9
10 India 2471 57 =LN(C10) =$E$15*EXP($E$16*B1 =C10-E10
0)
11 Morocco 4873 62 =LN(C11) =$E$15*EXP($E$16*B1 =C11-E11
1)
12 Banglade 6166 54 =LN(C12) =$E$15*EXP($E$16*B1 =C12-E12
sh 2)
13 Kenya 7174 59 =LN(C13) =$E$15*EXP($E$16*B1 =C13-E13
3)
14
15 m= =SLOPE(D2:D1 a =EXP(C16)
3,B2:B13)
16 b= =INTERCEPT( b =C15
D2:D13,B2:B13
)
Figure 25

Exponential Model
4.35
4.3
4.25 y = ‐3E‐05x + 4.256
4.2
ln(L) 4.15
4.1 ln(L)
4.05 Linear (ln(L))
4
3.95
0 2000 4000 6000 8000
P

Figure 26

16 

 
Resid
dual for EExponen
ntal Mod
del
6

‐2 0 2000
0 400
00 60
000 8
8000 Resiidual

‐4

‐6

‐8

‐10

F
Figure 27

Trendlin
nes using inb
built option
ns: You can automaticallyy fit the linearr, power and exponential
e (aand
other moddels) models.. To fit differeent models we
w follow the following
f stepps.

1. Innput the entiree data as befoore in the cell range A1 to C13


C as beforee.
2. Plot the graph of L verses P
3. To
T add a trend dline select thee different typpe of model under
u Type and
a display thhe equation.

F
Figure 28

17 

 
Power Model
80
70
60
Male Life 
50 Expectancy
40 (L)
y = 117.6x‐0.08
30
Power (Male Life 
20 Expectancy
10 (L))
0
0 2000 4000 6000 8000

Figure 29

Exponential Model
80
70
60
Male Life 
50 Expectancy
40 (L)
30 y = 70.53e‐3E‐0x
Expon. (Male Life 
20 Expectancy
10 (L))
0
0 2000 4000 6000 8000

Figure 30

It is easy to see that models are exactly same as the one which was found in the example 1 to 3. Also the
graph of logarithm and exponential models are good fit, but the exponential model is not a good fit.

Question: Predict the life expectancy if we know that the number of persons per doctor is 2500.
Answer: Using the logarithmic model . We have a=103.4, b=-5.2876
103.4 52876 ln 2500 60 .
Using the power model , we have a=117.63, b=-0.0823,
117.63 2500 . 62.76

We can find the life expectancy using the exponential model, however this is not an a good fit.

18 

 
Coefficients of Determination:
The coefficient of determination, denoted by is a numerical measure of how well a line fits a set of the
data. If is the linear model to be fitted to the set of data , where is the
error (noise) term. Let us assume that the fitted model using the least square method is given by

Let us fix the following notations

Then the coefficient of determination is given by

The closer is to 1, the better the fitted line to the data. An value close to 0 indicate very poor
fitting.

Example 2.4. Let us calculate the coefficient of determination for the examples 1 to 3 for life
expectancy. You may follow the instruction as in the next table. The value in case of logarithmic
model is 0.82558.
This suggest a reasonably good fit.

A B C D E F G =B2‐D2
1 (P) (L) ln(P)
2 275 74 5.616771 73.70094573 8.25 7.950945731 0.299054
3 =D2‐$B$16D2
410 72 6.016157 71.58914294 6.25 5.839142939 0.410857
4 467 73 6.146329 70.900842 7.25 5.150842004 2.099158
=B2‐$B$16
5 559 67 6.326149 69.95002056 1.25 4.200020558 -2.95002
6 643 68 6.466145 69.2097785 2.25 3.459778496 -1.20978
7 1010 70 6.917706 66.82209492 4.25 1.072094925 3.177905
8 1037 67 6.944087 66.68259899 1.25 0.932598987 0.317401
9 1216 66 7.103322 65.84062516 0.25 0.090625163 0.159375
10 2471 57 7.812378 62.09140383 -8.75 -3.658596169 -5.0914
11 4873 62 8.491465 58.50064888 -3.75 -7.249351116 3.499351
12 6166 54 8.726806 57.25625678 -11.75 -8.493743223 -3.25626
13 7174 59 8.878219 56.4556417 -6.75 -9.294358296 2.544358
14
15 mean(P) Average (L) SS_T 460.25 =SUMPRODUCT(F2:F13,F2:F13)
16 2191.75 65.75 SS_Reg 379.9491 =SUMPRODUCT(G2:G13,G2:G13)
17 Slope -5.2876226 SS_Res 80.30093 =SUMPRODUCT(H2:H13,H2:H13)
18 Intercept 103.40031
19 R^2 0.825528 =(F15-17)/F15
20
Figure 31

19 

 
The value of can be also displayed by right clicking on the data and choosing Add Trendline option
and check the option Linear, Display Equation on Chart and Display R-squared value on chart. We
obtain the Figure 32.

10 R2 value for logarithm model
9.5
9
8.5
y = ‐0.156x + 17.38
8 R² = 0.825
7.5 Series1
7 Linear (Series1)
6.5
6
5.5
5
60 65 70 75 80

Figure 32

Exercise: Verify that value for the power model is 0.8152 and for the exponential model is 0.6864.

20 

 
MODULE III

Discrete Dynamical System


In this section we model some long term behavior of data which changes over discrete time. Such
systems are called discrete dynamical systems. One can define a discrete dynamical system as a sequence
of numbers
, , , ,…

Example 3.1. The following table represent the number of bacteria in a Petri dish, , at the end of
each hour . We wish to model in terms of .

Table 3 

0 1 2 3 4 5 6 7 8 9 10
10.3 17.2 27 45.3 80.2 125.3 176.2 255.6 330.8 390.4 440
10 11 12 13 14 15 16 17 18 19
440 520.4 560.4 600.5 610.8 614.5 618.3 619.5 620 621

700
Growth of a Bacteria
600

500

400
Population

300

200

100

0
0 5 10 15 20
Hour
 
Figure 33

We consider the change in number of bacteria between time period

21 

 
It is easy to see that as increases, also increases. This means is proportion to . That’s is
1
where is a positive constant. This can be interpreted as a constant hourly growth rate. Note that the
graph of bacteria population verses time does not show that the population grow with constant rate.

Therefore, we refine the model. Note that the graph show that the rate of growth decreases as population
reaches 621. This number is called the carrying capacity of the system. Thus instead of assuming a
constant growth rate , we assume a growth rate that approaches to zero as the population approaches
621. This gives
621
where 0 is a constant. Now solving the above equation we get
621
This type of equation is called a discrete logistic equation. This type of equations are used to model
population growth .

A B C D E
1
n an Predicted value an (621- an) an+1-an
2
0 10.3 =B2 =B2*(621-B2) =B3-B2
3
1 17.2 =C2+$D$23*(621-C2)*C2 =B3*(621-B3) =B4-B3
4
2 27
5
3 45.3
6
4 80.2
7
5 125.3
8
6 176.2
9
7 255.6
10
8 330.8
11
9 390.4
12
10 440
13
11 520.4
14
12 560.4
15
13 600.5
16
14 610.8
17
15 614.5
18
16 618.3
19
17 619.5
20
18 620
21
19 621
22
23
Slope 0.0008 =SLOPE(E2:E20,D2:D20)
Figure 34

To model this problem we follow the following steps


22 

 
Open a blank excel worksheet and input the data in the cell range A1: B21.

1. Input the formula =B2*(621-B2) in D2 and =B3-B2 in E2 to create a transformed data. Now fill
the remaining cells in the columns D and E using the Fill Handle.

2. Now plot the graph of graph of the transformed data verses 621 and fit the
straight line through the origin.

90
80 y = 0.008x
70
an+1‐an

60
50
Series1
40
Linear (Series1)
30
20
10
0
0 50000 100000
an(621‐an )

Figure 35

3. Find the slope of the line in the cell D23 using the formula =SLOPE(E2:E20,D2:D20). The slope
is 0.0008 which means the model is given by
0.0008 621

4. Now find the predicted value of the number of bacteria in the column C as show above.
5. Finally plot the graph of predicted values and actual values together. Notice that the predicted
values are relatively close to the actual value which means that the model is a good model.

23 

 
700
Growth of a Bacteria
600
500
400
Population 300 Observed Values
200 Predicted Values
100
0
0 5 10 15 20
Hour

Figure 36

Sensitivity to the intrinsic Growth Rate:

Earlier we saw how the long term behaviors of the number of bacteria changes as initial value of b. Nw
we look at how the behavior of the bacteria model changes as b changes. Follow the following steps.

1. Open a new worksheet and place 0 in A2 and =A2+1 in A3 and fill the cell A3:A102 using the
Fill Handle.
2. Input 0.0008 in C2
3. Input 10.3 in B2 and =B2+$C$2*(621-B2)*B2 in B3 and fill the cells B4:B102 using the Fill
Handle.

A B C

1 n a_n b

2 0 10.3 =0.0008

3 =A2+1 =B2+$C$2*(621-B2)*B2

Figure 37

4. Highlight the columns A and B to plot the graph. We obtain the following graph.

24 

 
700

600

500

400

300 S eries 1

200

100

0
0 20 40 60 80 100

Figure 38

5. Now we add a scroll bar. View->Toolbars->Control Toolbox.

Design Mode 
Scroll Bar 

Figure 39

6. Click on the Scroll Bar. Then the cursor changes to a small cross. Use this to draw a long skinny
rectangle.

Now right click on the resulting scroll bar and select Properties. Now in the resulting window

25 

 
Figure 40

Change the LinkedCell to D2. Min to 0 and Max to 900. Now close the properties window and click
on the Design Node. Change the cell C2 input to D2/200000 so that b varies from 0 to 0.0045.

7. Now move the slider to notice the change in behavior of the system. The following figures give
the system for three values of b=0.0035, b=0.0041 and b=0.0045.

26 

 
F
Figure 41

F
Figure 42

27 

 
Conclusion: It easy to see that for small value of b the behavior is very regular whereas for large
values of b is quite chaotic.

28 

 
MODULE IV:
Linear Predator –Prey Model
Example 4.1: Consider a forest containing foxes and rabbits where the foxes eat rabbits for food. We
wish to determine whether the two species can coexist in long run. Since forest is a complex ecosystem,
we wish to simplify this model by the following assumptions:

1. The only source of food for the foxes is rabbits and the only predator of the rabbits is foxes.
2. Without rabbits present, foxes would die out.
3. Without foxes present, the population of rabbits would grow.
4. The presence of rabbits increases the rate at which the population of foxes grows.
5. The presence of foxes decreases the rate at which the population of rabbits grows.

To create the model, we assume


population of foxes at the end of month
population of rabbits at the end of month
The rate of changes of these two species are given by

Due assumptions (2) and (3), we may assume that rate of changes are proportional to populations
resulting in

Where 0 , 1. Note that the negative sign in the rabbits rate of change mean, the population is
decreasing.

Assumptions (4) and (5) say that the rates of changes of the populations either increase or decrease in the
presence of the other species. Therefore, it is appropriate to add one term in the above equation, yielding
the following equations

Where 0 , .
Rewriting the above equations we get
1
1
The above model can be also written in matrix form as

1
1

29 

 
We shall take a graphical approach to analyze the above model. The parameters 1 and are called
the fox death and birth factors respectively. The parameters and 1 are called the rabbits death
and birth factors respectively.

Excel Model: Follow the following steps to analyze this model in excel.

1. Open a blank worksheet and name it as rabbit_fox_model. Put the initial values as shown in the
following Figure 43. Now fill the cells from A9:A37, B8:B37 and C8:C37 using the Fill Handle
in order to model the data for 30 months.

A B C
1 Factors
2 Death Birth
3 Foxes 0.5 0.4
4 Rabbits -0.036 1.1
5
6 Month Foxes Rabbits
7 0 500 200
8 =A7+1 =$B$3*B7+C7*$C$3 =B7*$B$4+C7*$C$4
Figure 43

2. Create the graph for growth of rabbits and foxes as in the following Figure 44 & 45.

Rabbits
250

200
Population

150

100
Rabbits
50

0
0 5 10 15 20 25 30 35
Month

Figure 44

30 

 
Foxes
600

500
400
Population

300

200 Foxes
100
0
‐4 1 6 11 16 21 26 31
Months

Figure 45

3. Next we plot the graph of rabbits verses foxes as in the Figure 46. This curve is called a
trajectory.

Rabbits vs. Foxes
250
200
Rabbits

150
100
Rabbits
50
0
0 100 200 300 400 500 600
Foxes

Figure 46

Conclusion: Notice that the curve tends towards the origin, which means that both species eventually die
out. You may change the initial populations and observe that the trajectory still tend to origin.

31 

 
Now let us examine what happens if the rabbit death rate changes:

Follow the following steps

1. Add a scroll bar to the worksheet created earlier. Set the min to 0 and max to 500 and linked
cell to H1.
2. Add the formula=-H1/100 in the cell B4 for rabbits death rate.
3. Now move the slider and notice how the behavior of the system changes. For the death rate less
than -0.123, the origin appears to be stable and both populations die out. For values greater than
-0.123 the origin appear to be unstable and both populations grow without bound.

Rabbits vs. Foxes  when rabbitsdeath rate=‐0.036
1800
1600
1400
1200
1000
800
600 Rabbits
400
200
0
0 200 400 600 800 1000 1200
Foxes

Figure 47

Non-Linear Predator-Prey Model:


In the linear model we assumed that the coefficients of proportionality are constant. Now we
model them as increasing or decreasing in the presence of the other populations. In this case the
two model equations can be written as

Where 0, 0. Rewriting the above equations we get

1
1

This is called a Lotke-Volterra model.

32 

 
To implement this model graphically in Excel, follow the following steps:

1. Open a blank worksheet and rename is as rabbit_fox_model2. Put the initial values as shown in
the Figure 48. Now fill the cells from A9:A507, B8:B507 and C8:C507 using the Fill Handle in
order to model the data for 500 months.

A B C
1 Factors
2 Death Birth
3 Foxes 0.88 0.0001
4 Rabbits -0.0003 1.0391
5
6 Month Foxes Rabbits
7 0 100 900
8 =A7+1 =$B$3*B7+C7*$C$3*B7 =$B$4*B7*C7+C7*$C$4*C7
Figure 48

2. Highlight the A, B, C column and create the following graph as in Figure 49..

2500

2000
Population

1500

1000 Foxes
Rabbits
500

0
0 100 200 300 400 500 600
Month

Figure 49

3. Create the graph of rabbits verses foxes as shown in the Figure 50.

33 

 
Rabbits
2500

2000

1500

1000 Rabbits

500

0
0 100 200 300 400 500

Figure 50

Conclusion: This model predicts that the populations oscillate with the same period of oscillation
with the phase shift. This means they do not reach their peaks at the same time. These oscillations
cause the spiral nature of the trajectory. This model seems to be more reasonable than that of
linear model.

Equilibrium of the system: Let us assume that the equilibrium is attained at , . Then we
have
0.88 0.0001
0.0003 1.039
Assuming that 0 and solving the two equation, we get 130 and 1200.

Note that if you change the initial populations in the worksheet as 130 foxes and 1200 rabbits,
then the rabbits and foxes remain constant. That means this is an equilibrium. A slight change in
the value for example 129 foxes and 1201 rabbits yields the trajectory as in the Figure 51.

34 

 
Rab
bbits vs. Foxes
1220
1210

Rabbits
1200
1190 Rabb
bits
1180
126 128 130 132 134
4
Foxes

F
Figure 51

You may try with


Y w other initial values. Nootice that slight change in the
t initial poppulations,
trrajectory mov
ves away from
m the equilibriium , indicating that the eqquilibrium is not
n stable.

E
Example 4.2. ( Hunting Problem)
P Suuppose that a local
l hunting club wants too have a fox hunt
h
att one of its neext two meetinngs. The firstt meeting is 366 months from m now and thhe next is 36
m
months after th
hat. If the hunnters limit theemselves to kiilling 50 foxees, how wouldd the two optiions
afffect the long term populattions of the fooxes and rabbbits?

Solutions: To o model this problem


p againn let us look at
a the worksheeet of the nonn-linear modell.
Y may copy
You y the same moodel to a diffeerent worksheeet and name it hunting. Starting
S with 110
fooxes and 900 rabbits, the model
m predictss that at montth 36, there arre about 88 fooxes. Killing 50 of
thhem would reduce the num mber to 38. Thhus in the worrksheet, changge the foxes number
n for 366
m
month as 38. This
T results inn the following graph as shhown in the Fiigure 52.

F
Figure 52

35 

 
Note that this cause
N c a dramaatic change inn the behaviorr of the system
m and the poppulation flucttuates
quuite rapidly. Thus
T killing 50
5 foxes at in month 36 woould have a grreat effect on the long term m
poopulations.

Now change th
N he number off foxes in the 36
3 months baack to normal.. In the monthh of 72 the model
prredicts the nu
umber of foxees to be 212. Killing
K 50 of them
t would leave
l 162. Chhanging the
nuumber of foxees in the 72 month
m to 162 results
r in the following graaph as in the Figure
F 53.

F
Figure 53

Note that foxess populationss causes the raabbits populattion to initiallly grow. How
N wever in long term
thhe populations behave simiilar to the origginal one. Thhe reason behiind, this change is that
orriginally nearr month 36, thhe foxes popuulation was neear local miniimum and at month
m 72, it was
w
neear local maxximum. Thus killing 50 foxxes at a time of o local minimmum has mucch greater effeect
thhan killing neear local maximum. Thus hunter shouldd hunt in 72 month.
m

36 

 
MODULE V:
Differential Equations:
In this module we shall look at some problems involving differential equation. We shall use Euler’s
dy
method for approximating solution of a differential equation given by = f ( y ) with initial condition
dt

. Algorithm for solving this type of problem is as follows:

We start with a small step length , then we define y1 = y 0 + hf ( y 0 ) and so on. The n th iterate is
given by

y n = y n −1 + hf ( y n −1 )

To implement this procedure let us look at a problem

Example 5.1. Suppose a large tank with 300 gallons of a brine of solutions. A brine solution is being
pumped into the tank at a rate of 3 gal/min. Then mixed with the solutions there and then pumped out of
the tank at 3 gal/min. The concentration of the salt inflow is 2lb/min. Suppose initially there were 50lb
of salt dissolved in the 300 gallons. How much salt is left in the tank between times 0 to 50. How much
salt will be left in the tank after a long time.

Solution: Let x (t ) be the amount of salt in the tank after time t. The rate at which the salt concentration
changes in the tank is given by

dx
= ( Input rate of salt) –(Output rate of salt) = Rin − Rout
dt

Note that Rin = (2lb / gal )(3 gal / min) = 6lb / min and
Rout = ( x / 300 lb / gal )(3 gal / min) = x / 100 lb / min .

Hence the system is governed by the equation

dx x
= 6− with x(0) = 50.
dt 100

To solve model n excel, follow the following steps:

1. Open a blank worksheet and name it salt_mixture. Input the data as shown in Figure 54. Now
copy row 5 down to row 5004. So that t takes values from 0 to 1000 in the step of h = 0.2.

37 

 
A B

h= 0.2

2 Time Amt Salt

3 0 50

4 =B4+$B$1*(6-
=A4+$B$1 B4/100)

Figure 54

2. Note that at t = 50 the amount of salt in the tank is 266.57.


3. Plot the graph of the salt content against the time. In the long run the amount of salt in the tank is
600 lb which is evident from the following Figure 55.
Amt Salt

700

600

500

400
Amt Salt
300

200

100

0
0 200 400 600 800 1000 1200

Figure 55

Exercise 5.1. A 100-gal tank is full of a solution that contains 15 lb of salt. Starting with time t = 0
distilled water is poured into the tank at the rate 5gal/min. The solution in the tank continuously well
stirred and is drained out of the tank at the rate 5 gal/min.

1. Let y (t ) represent the amount of salt in the tank at time t . Form the differential equation to
dy
model .
dt
2. Use the Euler’s method to estimate the amount of salt in the tank at time 10.
3. Find the quantity of salt in the solutions t → ∞. Is this what you expect.

38 

 
Quadratic Models: We now model the populations of two species with a system of two differential
equations. Again we will use the Euler’s method for a system of two differential equations, given by

dx dy
= f ( x, y ), = g ( x, y )
dt dt

With given initial x(t 0 ) = x 0 and y (t 0 ) = y 0 . Euler’s iteration scheme for this kind system is given by

t 1 = t 0 + h, x1 = x0 + h f ( x0 , y 0 ) y1 = y 0 + h g ( x0 , y 0 )
t 2 = t 1 + h, x 2 = x1 + h f ( x1 , y1 ) y 2 = y1 + h g ( x1 , y1 )
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
t n +1 = t n + h, x n +1 = x n + h f ( x n , y n ) y n +1 = y n + h g ( x n , y n )

If f ( x, y ) and g ( x, y ) are quadratic in x and y, then the system is called a quadratic population model. A
general quadratic model is given by

dx dy
= a1 x + b1 x 2 + c1 xy, = a 2 y + b2 y 2 + c 2 xy
dt dt

Here and terms mean completion within the first species and the term mean competition
between the two species.

Example 5.2: Consider a forest with foxes and rabbits where the foxes eat rabbits for food. We wish to
determine whether the two species can coexist in long run. Since forest is a complex ecosystem, we wish
to simplify this model by the following assumptions:

1. The only source of food for the foxes is rabbits and the only predator of the rabbits is foxes.
2. Without rabbits present, foxes would die out at a rate 8% per month.
3. Without foxes present, the population of rabbits would grow at a rate of 4% per month.
4. The presence of rabbits increases the rate at which the population of foxes grows.
5. The presence of foxes decreases the rate at which the population of rabbits grows.
We wish to model this system see what happens to the population in long run?

Solution: Let F (t ) and R (t ) represent the populations of foxes and rabbits at time t respectively. The
system of equations governing this model is given by
dF
= −0.08 F + c1 F R
dt
dR
= 0.04 R + c 2 F R
dt

39 

 
We assume the initial conditions F (0) = 100 and R (0) = 1000 . Note that for the linear model we used
c1 = 0.0001 and c2 = −0.0003 . We model the above system using the Euler’s method and use
h = 0.25. This is same as saying almost every week there is a check. Use the following steps.

1. Open a blank excel worksheet and name it quadratic. Input the data as given in the following
Figure 56.

A B C D

1 Foxes Rabbits h

2 a1 -0.08 0.04 0.25

3 c1 0.0001 -0.0003

5 Time Foxes Rabbits

6 0 100 1000

7 =A6+$D$2 =B6+$D$2*($B$2*B6+$B$3*B6*C6) =C6+$D$2*($C$2*C6+$C$3*B6*C6)

Figure 56

Now drag the cells A7:C7 up to A806:C806. This will generate data for 200 months.

2. Plot the graph of the trajectory (graph of rabbits verses foxes populations) as in Figure57.

Rabbits vs. Foxes

1200

1000

800
Rabbits

600

400

200

0
0 50 100 150 200 250
Foxes

Figure 57

40 

 
2. Experiment with small values of h and large numbers of iterates. You may also assign arbitrary
number of species at the beginning and see what is the effect. It can be seen that the equilibrium
is near 133 foxes and 800 rabbits.
3. The initial data of 100 foxes and 1000 rabbits is arbitrary, so you may try to put any random
number for these cells by using the =randbetween(0,1000) for foxes in A6 and
=randbetween(0,2000) for rabbits in B6. Now press F9 to generate different initial data.

Conclusion: Note that the trajectory forms a loop indicating the unstable system. That is same as saying
the populations will oscillate over time.

41 

You might also like