tarleton state university€¦ · computer aided math with maple peter w. white keith e. emmert (p....

166
Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address, P. W. White: Department of Mathematics, Tarleton State University E-mail address, P. W. White: [email protected] URL: http://www.math.tarleton.edu/Faculty/White/ (K. E. Emmert) Department of Mathematics, Tarleton State University Current address, K. E. Emmert: Department of Mathematics, Tarleton State University E-mail address, K. E. Emmert: [email protected] URL: http://www.math.tarleton.edu/Faculty/Emmert/ Dedicated to ??

Upload: others

Post on 29-Sep-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

Computer Aided Math with Maple

Peter W. White

Keith E. Emmert

(P. W. White) Department of Mathematics,

Tarleton State University

Current address, P. W. White: Department of Mathematics,Tarleton State UniversityE-mail address, P. W. White: [email protected]: http://www.math.tarleton.edu/Faculty/White/

(K. E. Emmert) Department of Mathematics,

Tarleton State University

Current address, K. E. Emmert: Department of Mathematics,Tarleton State UniversityE-mail address, K. E. Emmert: [email protected]: http://www.math.tarleton.edu/Faculty/Emmert/

Dedicated to ??

Page 2: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

1991 Mathematics Subject Classification. Primary 05C38, 15A15; Secondary 05A15,15A18

The Author thanks ?

Abstract. Our abstract is....

Page 3: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

Contents

List of Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v

List of Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix

Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi

Chapter 0. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12. Polynomials and Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . 23. Calculus and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 94. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

Chapter 1. Linear Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192. Basic Operations with Matrices . . . . . . . . . . . . . . . . . . . . . . 223. Solving Systems of Equations . . . . . . . . . . . . . . . . . . . . . . . . 244. Eigenvalues and Eigenvectors . . . . . . . . . . . . . . . . . . . . . . . . 265. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

Chapter 2. Ordinary Differential Equations . . . . . . . . . . . . . . . . . . . 311. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312. Systems of First Order, Linear, ODE’s . . . . . . . . . . . . . . . . . . . 333. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

Chapter 3. Population Models in Biology . . . . . . . . . . . . . . . . . . . . 411. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412. Malthusian Models - Exponential Growth . . . . . . . . . . . . . . . . . 413. The Logistic Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444. Equilibrium Solutions and the Logistic Model . . . . . . . . . . . . . . . 485. Linear Stability Example . . . . . . . . . . . . . . . . . . . . . . . . . . 516. Modeling the Chemostat . . . . . . . . . . . . . . . . . . . . . . . . . . 537. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

Chapter 4. Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 711. Lists in Maple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 712. Data at Distinct Points and Interpolating Polynomials . . . . . . . . . . 763. Linear Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 824. How Maple Does It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

iii

Page 4: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

5. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

Chapter 5. Parameter Estimation - Nonlinear Regression . . . . . . . . . . . 911. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 912. Basic Theory of Epidemics . . . . . . . . . . . . . . . . . . . . . . . . . 933. Curve Fitting by Inspiration . . . . . . . . . . . . . . . . . . . . . . . . 954. Nonlinear Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . 985. Fitting the Differential Equation . . . . . . . . . . . . . . . . . . . . . . 1006. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104

Chapter 6. Gambler’s Ruin . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1071. When Can a Farmer Turn a Profit? . . . . . . . . . . . . . . . . . . . . 1072. Markov Chains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1083. Solution to the Gambler’s Ruin Problem . . . . . . . . . . . . . . . . . 1164. Approximating the Solution of the Gambler’s Ruin Problem via Simulations1235. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

Chapter 7. The Spectrum of Extinction . . . . . . . . . . . . . . . . . . . . . 1311. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1312. Steady States and Stability . . . . . . . . . . . . . . . . . . . . . . . . . 1323. Generating Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1364. The Spectrum of Extinction . . . . . . . . . . . . . . . . . . . . . . . . 1395. The Spectrum with Parametric Stochasticity . . . . . . . . . . . . . . . 1426. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149Index of Maple Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 150Index of Subjects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152

iv

Page 5: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

List of Figures

1 Plot of the expression f := x2 + 2x + 1 over −5 ≤ x ≤ 5. . . . . . . . . . . 2

2 Plot of the expression f := x2 + 2x + 1 with a default horizontal range. . . 3

3 Plot of the function f(x) = sin(x) + cos(2x). . . . . . . . . . . . . . . . . . 5

4 Plot of the function f(x) = x2 − 2x − 3. . . . . . . . . . . . . . . . . . . . 7

5 Plot of the function f(x) = x5 − 4x4 + 4x3 − 7x2 + 15x − 6. . . . . . . . . 9

6 Plots of the function f(x) = x+1x2−1

. . . . . . . . . . . . . . . . . . . . . . . . 12

6(A) The horizontal range is −∞ < x < ∞. The vertical range isunspecified. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

6(B) The ranges truncated to −10 ≤ x ≤ 10 and −10 ≤ y ≤ 10. . . . 12

7 Plot of the solution P (t) = e0.2t over 0 ≤ x ≤ 10. . . . . . . . . . . . . . . . 32

8 Plot of the state space of u(t) and v(t) from 0 ≤ t ≤ 20. . . . . . . . . . . 358(A) The state space of u(t). . . . . . . . . . . . . . . . . . . . . . . 358(B) The state space of v(t). . . . . . . . . . . . . . . . . . . . . . . . 35

9 Phase space plot of u(t) vs v(t) over 0 ≤ t ≤ 20 with initial conditions. . . 36

10 Phase space plot of u(t) vs v(t) over 0 ≤ t ≤ 20 with initial conditionsv0 = 2, 4, 5, 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

11 Malthusian Growth – Exact Solution for p0 = 1, k = 0.1. . . . . . . . . . . 44

12 Malthusian Growth – Exact Solution for p0 = 1, k = 0.1, .3, .5, .7, .9, and 1.1. 44

13 Logistic Solution – varying a value. . . . . . . . . . . . . . . . . . . . . . . 4713(A)Logistic Solution – b = 0.1, a = 0.1. . . . . . . . . . . . . . . . . 4713(B)Logistic Solution – b = 0.1, a = 0.2. . . . . . . . . . . . . . . . . 4713(C)Logistic Solution – b = 0.1, a = 0.3. . . . . . . . . . . . . . . . . 4713(D)Logistic Solution – composite plot. . . . . . . . . . . . . . . . . 47

14 Logistic Solution – varying b value. . . . . . . . . . . . . . . . . . . . . . . 48

15 Logistic Solution – varying initial populations. . . . . . . . . . . . . . . . . 49

16 Graph of f(x) = x2(1 − x)3. . . . . . . . . . . . . . . . . . . . . . . . . . . 52

17 Graph of solutions with various initial conditions. . . . . . . . . . . . . . . 53

18 Compartmental Diagram for the Chemostat. . . . . . . . . . . . . . . . . . 54

19 Plot of N(t) vs C(t) with initial conditions (.1, .1). . . . . . . . . . . . . . 67

20 Plot of N(t) vs C(t) with initial conditions (.5, .5), (1, 1), (1.5, 1.5), . . . , (8, 8). 68

v

Page 6: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

21 Plot of the list list1 using style=s and color=”C”. . . . . . . . . . . . . . . 7221(A)Plot of the list list1. . . . . . . . . . . . . . . . . . . . . . . . . 7221(B)Plot of the list list1 using style=point. . . . . . . . . . . . . . . 7221(C)Plot of the list list1 using style=boxand color=”Green”. . . . . 72

22 Plot of the list list2 using various style=s and color=”C” options. . . . . . 7522(A)Plot of the list list2. . . . . . . . . . . . . . . . . . . . . . . . . 7522(B)Plot of the list list2 using red and blue circles. . . . . . . . . . . 7522(C)Plot of the list list2 using the circle and plus symbols. . . . . . . 7522(D)Plot of the list list2 connecting the points with lines. . . . . . . 75

23 Plots of the list list3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7523(A)Plot of the list list3. . . . . . . . . . . . . . . . . . . . . . . . . 7523(B)Plot of the list list3 using blue circles. . . . . . . . . . . . . . . 75

24 Plot of the Lagrange interpolating polynomial, g. . . . . . . . . . . . . . . 80

25 Plots of the original function x2eπx − sin(x), and Lagrange interpolatingpolynomial g for x ∈ [−1, 1]. The original function and g show in blue andred, respectively. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

26 Plot of data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

27 Plot of the Leastsquares interpolation polynomial for data. . . . . . . . . . 87

28 Plot of the Leastsquares quadratic interpolation polynomial for a given dataset and data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

29 Plot of the Leastsquares quadratic and cubic interpolation polynomials for agiven data set and data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

30 Plot of data found in nlreg1.txt. . . . . . . . . . . . . . . . . . . . . . . 92

31 Deaths per week of the Bombay plague. . . . . . . . . . . . . . . . . . . . 96

32 Linear regression for the Bombay plague model. . . . . . . . . . . . . . . . 98

33 Nonlinear regression for the Bombay plague data. . . . . . . . . . . . . . . 100

34 Comparison of Linear and Nonlinear regression for the Bombay plague data. 101

35 Plot of the solution of the Bombay plague system of differential equationswith initial condition from week 20. . . . . . . . . . . . . . . . . . . . . . . 104

36 Plot of the solution of the Bombay plague system of differential equationswith initial condition from week 5. . . . . . . . . . . . . . . . . . . . . . . 105

37 Probability of winning game vs. p given a = 15 and c = 20. . . . . . . . . . 121

38 Simulations of the Gambler’s Ruin Problem. . . . . . . . . . . . . . . . . . 12638(A)Frequency of winning game vs. rounds played. . . . . . . . . . . 12638(B)Frequency of loosing game vs. rounds played. . . . . . . . . . . 126

39 Stability of eigenvalues in the Coyote-Jack rabbits model as a function of a. 135

40 Time series of Bunny-Coyote populations with a = 1.4. . . . . . . . . . . . 137

41 Bunny population with a = 1. . . . . . . . . . . . . . . . . . . . . . . . . . 138

vi

Page 7: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

42 Coyote population with a = 1. . . . . . . . . . . . . . . . . . . . . . . . . . 139

43 Relative frequency of the year of extinction vs the year for the Coyote-Jackrabbit model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142

44 Relative frequency for the spectrum of extinction in the Coyote–Jack rabbitmodel with 100 iterations. . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

45 Relative frequency for the spectrum of extinction in the Coyote–Jack rabbitmodel with 1000 iterations. . . . . . . . . . . . . . . . . . . . . . . . . . . 145

vii

Page 8: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,
Page 9: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

List of Tables

I Selected Maple plot options. . . . . . . . . . . . . . . . . . . . . . . . . . 35

II Common Arguments for Vector . . . . . . . . . . . . . . . . . . . . . . . . 37

III List of font Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

IV Possible Behavior ofdp

dt= αp. . . . . . . . . . . . . . . . . . . . . . . . . . 50

V Data for number of bees, counted in thousands. . . . . . . . . . . . . . . . 105

VI Table of parameters for the Coyotes and Jack rabbits problem. . . . . . . . 131

ix

Page 10: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,
Page 11: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

Preface

“Computer Aided Mathematics with Maple” is a work designed to draw togethervarious applied undergraduate mathematical areas in a capstone-like experience inorder to solidify and expand the students’ mathematical experience. This book usesclassical dissemination of concepts combined with mathematical software to put amodern spin on tried-and-true application problems. The outstanding feature of thiswork is its use of modern computer software and example applications to educate thestudent in the use of mathematical concepts and to investigate some of the researchproblems posed (and solved) over the last century. After each major topic the studentsare asked to work through project level problems in ways similar to that presented inthe example explorations.

This book is intended for junior and senior level mathematic (primarily), biol-ogy, engineering and computer science majors. It is recommended that the studentscomplete the calculus sequence, differential equations and linear algebra before thiscourse; however the minimum prerequisites are a year of calculus (including series)and 6 hours of upper level mathematics (including differential equations OR linearalgebra). Access to a computer with the Maple software package installed is requiredfor this material. This material has been extensively class-tested over the past tenyears and this book has evolved out of course notes.

Starting with an overview of functions and calculus, and then progressing intodifferential equations and linear algebra, this work will lead the student through anexploration of the fundamental mathematical tools used in applied research. Thisbook uses examples from Biology and Statistics to teach students how to use con-tinuous and discrete models to explore natural phenomena. The Computer AlgebraSystem, Maple is used to investigate the dynamics of these models in ways that“pen and paper” just can’t match. The capstone nature of this work will both solid-ify and expand the students experience in their foundational mathematics course workand give them access to production level tools for conducting applied mathematicalresearch.

xi

Page 12: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,
Page 13: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 0

Functions

1. Introduction

Perhaps the most fundamental concept in mathematics is that of a function. Afunction is a set of relations or rules that assigns to each value x in the domain setX a unique value y in the range set Y . A function is a special case of a more generalconcept, that of a relation. A relation is a map or rule from one set, X, to anotherset, Y . If elements x ∈ X and y ∈ Y are related, then we write (x, y). Note that theset of all elements that are related is a subset of X × Y . Two examples of relationsare

f(x) = x2 + 2x + 4 andx2

a2+

y2

b2= 1,

where the first is also a function of x.Functions appear in mathematics courses at a variety of levels. In algebra and

pre-calculus the concept of a function is introduced and the relationship betweenfunctions, relations and graphs are explored. Concepts such as one-to-one, inversesand roots are investigated. Basic functions such as polynomials, rational functions,exponential and logarithmic functions are introduced along with their graphs and abasic concept of increasing/decreasing and asymptotes. In trigonometry the functionssin(x), cos(x) and so on, are introduced. The concept of periodic functions, ampli-tudes, phase shift and frequency are explored. In calculus, the concept of an operator,or function of functions, is introduced. Two such operators are differentiation andintegration. Continuity, smoothness of functions (differentiability), slopes of curves(other than straight lines), concavity and maximum/minimum values of functionsare usually covered in first semester calculus. In second semester calculus sequences(functions over the integers), series, power series, parametric and polar functions areinvestigated. In third semester calculus the concepts dealing with functions of morethan one independent variable are introduced. As a student progresses through theupper division mathematics courses, they are introduced to functions in the contextof ordinary (and possibly partial) differential equations, dynamical systems and mod-eling, the complex number system, the topological and algebraic setting, and theanalysis of real numbers.

In this chapter we will explore some of the properties and concepts of functionsand relations using Maple. We will start with some of the basic Maple commandsto input, manipulate and use functions.

1

Page 14: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 0. FUNCTIONS 2

2. Polynomials and Graphs

In this section we will use Maple to investigate some of the properties of polyno-mials. We’ll first input and graph several polynomial functions. Start your favoriteflavor of Maple and enter the following command.

> f := x^2+2*x+1;

Maple will generate the output:

f := x2 + 2x + 1

Note that in this case f is defined as an expression and we use the asterisk (*) forthe multiplication operator and (^) for exponentiation. In Maple, multiplication isnot assumed in the 2x term (Maple treats 2x as a symbol or variable).

We can plot the expression f using the plot command as shown below to generatea two dimensional graph.

> plot(f,x=-5..5);

This generates Figure 1. The basic plot command expects an expression as it’s

xK4 K2 0 2 4

10

20

30

Figure 1. Plot of the expression f := x2 + 2x + 1 over −5 ≤ x ≤ 5.

first argument that has one independent variable, x in this particular example. Thedomain along with the independent variable is specified in the second argument byx = -5..5. Instead of domain, Maple uses horizontal range or more simply range forthe domain of expressions. Note that you need not specify the range of the x valueswhen plotting, but you must specify the independent variable. In the command

> plot(f, x);

We see in Figure 2 that Maple assumes a default horizontal range of -10..10. Of

Page 15: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

2. POLYNOMIALS AND GRAPHS 3

xK10 K5 0 5 10

20

40

60

80

100

120

Figure 2. Plot of the expression f := x2 + 2x + 1 with a defaulthorizontal range.

course the vertical range (what we normally call range of the dependent variable) isautomatically determined based upon the horizontal range (domain).

If you have a burning desire to know more about the plot command (or any othercommand), type

> ? plot;

This will open Maple help and display the basic help on plot. Of course, you canaccess Maple help via Help->Maple Help and search for the command.

Maple can also evaluate expressions using the subs command. This commandcan be simply used to substitute a number for a variable or replace expressions withother expressions. An example is

> subs(x=4, f);

This command generates the output

25

In addition to expressions, Maple can also define functions. Before we continue,it is important to be able to distinguish between functions and expressions. Anexpression is like a substitution rule, the left hand side of the “:=” (or name of theexpression) can be used in place of the right hand side in later commands. A function

Page 16: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 0. FUNCTIONS 4

in Maple can be used just like functions you use in mathematics classes. One thingto remember: functions must be evaluated using function notation while expressionsare evaluated using the subs command. Let’s consider the command

> f := x-> sin(x)+cos(2*x);

Maple give the output

x− > sin(x) + cos(2x)

In the above example, f is defined as a function. Note that the original definition off has now been lost because we reused the symbol f . Like expressions, the name of thefunction f appears left of the := and Maple uses the special symbol -> to indicatethe name f is in reality a rule (function) that maps the independent variable x tosin(x) + cos(2x).

As an example, if we wish to evaluate f at x = π, we would execute the command

> f(Pi);

which gives the output

1

Of course there is nothing special about x. We could also define a function

> q := CAT -> sin(CAT) + cos(2*CAT);

and

> q(Pi);

would generate the same output since it is the same function. The only differencebetween f and q is the name used for the independent variable.

In terms of the plot command, there is little difference between an expression anda function. The main difference is that we must remember to indicate the independentvariable, say x, for the function f by typing f(x) as the first argument of the plot

command. Thus, executing the command

> plot(f(x), x = -2*Pi..2*Pi,y=-2..2);

generates Figure 3. Notice that we’ve included a new optional parameter y = -2..2

which specifies the vertical range of the plot. This overrides Maple’s default behaviorof generating the vertical range based upon the horizontal range.

Of course we can do much more than just plot functions and expressions withMaple. Many Maple commands have descriptive names: expand for multiplying outpolynomials, factor for factoring polynomials, etc. Let’s define several expressions(f and g) and a function (gobolyguk).

> f := x^2+5*x-24; g := (x-3)*(x+2); gobolyguk := x-> x^3+8;

Maple responds with

f := x2 + 5x − 24

g := (x − 3)(x + 2)

gobolyguk := x− > x3 + 8

Page 17: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

2. POLYNOMIALS AND GRAPHS 5

xK6 K4 K2 0 2 4 6

y

K2

K1

1

2

Figure 3. Plot of the function f(x) = sin(x) + cos(2x).

Since gobolyguk is a function, we evaluate it at x = 2 via the command

> gobolyguk(2);

with output

16

However, since f is an expression, we evaluate it at x = 2 via

> subs(x = 2, f);

resulting in the output

−10

Notice that g is a polynomial in factored form. We can use the command expand

to expand the expression g.

> expand(g);

x2 − x − 6

Maple can also factor expressions using factor.

> factor(f);

(x + 8)(x − 3)

It is interesting to note that factor does not factor integers. You should use thecommand ifactor instead.

Page 18: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 0. FUNCTIONS 6

Notice that these commands work with functions as well as expressions, as longas we remember to explain to Maple what independent variable is being used. Forexample,

> factor(gobolyguk(CAT));

generates output

(CAT + 2)(CAT 2 − 2CAT + 4)

Maple will also perform basic operations such as expanding products and sim-plifying expressions as shown in the next few examples.

> expand(f*g);

x4 + 4x3 − 35x2 − 6x + 144

> h := simplify(f/g);

h :=x + 8

x + 2

In this next tiny example, we assign the output of an operation (multiplication ofpolynomials) to the label k.

> k := h*gobolyguk(x);

k :=(x + 8)(x3 + 8)

x + 2

We can now refer to the output later and perform other operations upon it.

> simplify(k);

(x + 8)(x2 − 2x + 4)

Now let’s look at some useful commands for solving equations. Many times inmathematics the solution to a problem involves finding the roots of an expression.

Definition 1. A value r is a root of a function f(x) if f(r) = 0.

Consider the polynomial function f(x) = x2 − 2x − 3. Enter this into Maple as

> f := x^2-2*x-3;

Maple responds with

f := x2 − 2x − 3

We know that f has 2 roots: -1 and 3, as shown by it’s graph shown in Figure 4.Recall that the Maple command for this is

Page 19: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

2. POLYNOMIALS AND GRAPHS 7

> plot(f,x=-4..4,y=-4..4);

Again, we specify the horizontal range as well as the vertical range. We can use

xK4 K3 K2 K1 0 1 2 3 4

y

K4

K3

K2

K1

1

2

3

4

Figure 4. Plot of the function f(x) = x2 − 2x − 3.

Maple to find these roots by using the solve command:

> solve(f=0,x);

3,−1

The Maple command expects an equation as the first argument (we used the name ofour expression, f , and set it equal to zero) and the independent variable as the second.Note the use of “=” instead of “:=”. The first is used to express an equation, whilethe second is used to define a function, expression or value and assign the resultingdefinition to a label.

We can also use a label to refer to an equation as shown below.

> f := x^2/4+y^2/9=1;

f :=1

4x2 +

1

9y2 = 1

We use Maple to solve the equation f . Since the label f is already an equation, notan expression, we don’t use f = 0 as the first argument for solve.

> solve(f,x);

2

3

−y2 + 9, −2

3

−y2 + 9

Page 20: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 0. FUNCTIONS 8

We might also solve for y.

> solve(f,y);

3

2

√−x2 + 9, −3

2

√−x2 + 9

Thus, we see that solve is useful for things other than obtaining numeric answers.Two other useful commands dealing with equations are rhs and lhs which take

as input an equation and return the right hand side and left hand side, respectively.For example,

> lhs(f);

1

4x2 +

1

9y2

and

> rhs(f);

1

Now, let’s consider the following function,

> f:=x->x^5-4*x^4+4*x^3-7*x^2+15*x-6;

f := x− > x5 − 4x4 + 4x3 − 7x2 + 15x − 6

If we plot the function with the below command, we generate Figure 5.

> plot(f(x),x=-1..6,y=-10..10);

It is obvious that there are at least three roots. Applying the solve command,

> solve(f(x) = 0, x);

we obtain the rather odd looking result

RootOf( Z5 − 4 ∗ Z4 + 4 ∗ Z3 − 7 ∗ Z2 + 15 ∗ Z − 6, index = 1),

RootOf( Z5 − 4 ∗ Z4 + 4 ∗ Z3 − 7 ∗ Z2 + 15 ∗ Z − 6, index = 2),

RootOf( Z5 − 4 ∗ Z4 + 4 ∗ Z3 − 7 ∗ Z2 + 15 ∗ Z − 6, index = 3),

RootOf( Z5 − 4 ∗ Z4 + 4 ∗ Z3 − 7 ∗ Z2 + 15 ∗ Z − 6, index = 4),

RootOf( Z5 − 4 ∗ Z4 + 4 ∗ Z3 − 7 ∗ Z2 + 15 ∗ Z − 6, index = 5)

Sometimes the roots of a polynomial or other function are not nice algebraic numbers.That is, RootOf indicates that the polynomial does not factor using rational numbers.In order to factor it, you must move to a “larger” field such as the real numbers orcomplex numbers. In cases like this, the solve command will fail to give a usefulanswer.

Page 21: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

3. CALCULUS AND FUNCTIONS 9

xK1 0 1 2 3 4 5 6

y

K10

K5

5

10

Figure 5. Plot of the function f(x) = x5 − 4x4 + 4x3 − 7x2 + 15x − 6.

At this point we have a choice. We can use numerical methods to try to approxi-mate the solution or ask Maple politely to approximate the solution for us. We dothe latter via the fsolve command.

> fsolve(f(x) = 0, x);

.4966512136, 1.673302548, 2.938897378

This requests Maple to use floating point arithmetic to approximate the solution(s)of an equation. If you are interested in complex solutions, you must specify thecomplex option within the fsolve command. For example,

> fsolve(f(x) = 0, x, complex);

yields two additional complex approximate solutions, for a total of five as shownbelow.

−.5544255699− 1.466031560I,−.5544255699 + 1.466031560I,

.4966512136, 1.673302548, 2.938897378

Above, I =√−1.

3. Calculus and Functions

In this section we will use Maple to explore the relationship that functions havein calculus. We will first look at the concept of limits, then derivatives and integrals.We will work with parametric and polar functions and their graphs.

Page 22: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 0. FUNCTIONS 10

3.1. Limits. First let’s look at limits. Maple has a built-in command for com-puting limits, namely limit. The basic form of the command expects an expressionor a function, a name (say x), and a limit point. In this case, Maple will perform atwo sided limit.

Recall the following basic (concept driven) definitions from calculus. We won’tneed the more rigorous ε − δ version of the limit definitions.

Definition 2. Let f(x) be a function and a ∈ R any real number, also called thelimit point. Then, we say

• “the limit of f(x) as x approaches a, equals L,” written

limx→a

f(x) = L,

if the values of f(x) can be made arbitrarily close to L by allowing x to beclose to a, but not equal to a.

• “the left-hand limit of f(x) as x approaches a from the left” equals L,” written

limx→a−

f(x) = L,

if the values of f(x) can be made arbitrarily close to L by allowing x to beclose to a and x < a.

• “the right-hand limit of f(x) as x approaches a from the right” equals L,”written

limx→a+

f(x) = L,

if the values of f(x) can be made arbitrarily close to L by allowing x to beclose to a and x > a.

As a consequence of the definitions, we have

Theorem 1. Let f(x) be a function and a ∈ R any real number or a = ±∞.Then

limx→a

f(x) = L ⇐⇒ limx→a−

f(x) = L = limx→a+

f(x).

As an example, we first define the function f(x) =x + 1

x2 − 1and find the limit as x

approaches -1, 1, and infinity. We’ll then graph the function to check the limits.

> f:=x-> (x+1)/(x^2-1);

f := x− >x + 1

x2 − 1

We compute several limits in the following tiny examples.

> limit(f(x),x=-1);

−1

2

Page 23: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

3. CALCULUS AND FUNCTIONS 11

> limit(f(x),x=1);

undefined

The next two examples show the optional arguments right and left. The optionalarguments instruct Maple to compute the right and left handed limits, respectively.

> limit(f(x),x=1,right);

> limit(f(x),x=1,left);

−∞

> limit(f(x),x=infinity);

0

> limit(f(x),x=-infinity);

0

We can intuitively verify these results by considering two graphs in Figure 6 whichwere generated by the two commands

> plot(f(x),x=-infinity..infinity);

> plot(f(x),x=-10..10,y=-10..10);

In calculus, we define vertical and horizontal (or slant) asymptotes using limits.Notice that the infinite limits actually compute the horizontal asymptote of f(x).

Definition 3. Let f(x) be a function. The line y = L is a horizontal asymptoteof f if

limx→∞

f(x) = L or limx→−∞

f(x) = L.

Of course, not all asymptotes generated by considering x → ±∞ are horizontal.

Definition 4. The line y = mx + b is a slant asymptote of the function f(x) if

limx→∞

[f(x) − (mx + b)] = 0 or limx→−∞

[f(x) − (mx + b)] = 0.

The idea of slant asymptotes can be further generalized by replacing the functionmx + b with any function r(x).

Page 24: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 0. FUNCTIONS 12

xKN 0 N

6(A) The horizontal range is −∞ < x < ∞.The vertical range is unspecified.

xK10 K5 0 5 10

y

K10

K5

5

10

6(B) The ranges truncated to −10 ≤ x ≤ 10and −10 ≤ y ≤ 10.

Figure 6. Plots of the function f(x) = x+1x2−1

.

Example 1. The function f(x) =3x3 − 5x2 − 6x − 8

x2 + 2has a slant asymptote of

y = 3x − 5 since

limx→∞

[f(x) − (3x − 5)] = limx→∞

2

x2 + 2= 0.

Of course, Maple can be used to check this statement.

Definition 5. Let f(x) be a function defined on both sides of the value a ∈ R.

Then the line x = a is a vertical asymptote if one of the following hold• lim

x→af(x) = ∞

• limx→a−

f(x) = ∞• lim

x→a+f(x) = ∞

• limx→a

f(x) = −∞• lim

x→a−

f(x) = −∞• lim

x→a+f(x) = −∞

Notice that Figure 6(A) is the plot where the x values (the horizontal range) isallowed to vary over the whole real line. A lot of information is lost. We can tell thatit crosses the y axis and that there is a vertical asymptote, but not where. However,after we truncate the graph as shown in Figure 6(B), we can more clearly see theinteresting details of the graph without loosing the apparent limits at ±∞ or the leftand right hand limits.

3.2. Differentiation. Next, let’s look at derivatives. From calculus, we learnedthe definition of a function.

Definition 6. Let f(x) be a function. Then the derivative of f , written f ′(x), is

f ′(x) = limh→0

f(x + h) − f(x)

h.

Note that this version of the derivative allows you to evaluate the derivative ofa function at any point x where the derivative is defined, a subset of the domain of

Page 25: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

3. CALCULUS AND FUNCTIONS 13

the original function. The main uses of derivatives are computing the slope of a linetangent to the curve y = f(x) and determining the instantaneous rate of change at agiven point.

In Maple there are two commands for taking the derivative of a function/expression,the diff command and the D command. The first is used to get an expression, thesecond is used to get a function.

Consider the expression

> y := x^3+2*x^2-5*x+10;

y := x3 + 2x2 − 5x + 10

The diff command can be used to find it’s derivatives of all orders.

> dydx := diff(y,x);

dydx := 3x2 + 4x − 5

In this next example, we remind you that the output of function calls (such as diff)can be used in future calls, as seen below.

> d2ydx2 := diff(dydx,x);

d2ydx2 := 6x + 4

Notice that we can obtain the second derivative (or higher derivatives) by nested callsto diff.

> diff(diff(y,x), x);

6x + 4

This is cumbersome for higher order derivatives. So, the sequence operator $ is usedto automate this a bit, as the next two examples show.

> d3ydx3 := diff(y,x$3);

6

> d4ydx4 := diff(y,x$4);

0

All higher derivatives will be 0.Next, we try the D command to see what happens.

> yp := D(y);

Page 26: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 0. FUNCTIONS 14

yp := 3D(x)x2 + 4D(x)x − 5D(x)

The D command expects a function, not an expression, and returns a function. Nextdefine y as a function and take derivatives:

> y := x-> x^3+2*x^2-5*x+10;

> dydx := D(y);

y := x− > x3 + 2x2 − 5x + 10

dydx := x− > 3x2 + 4x − 5

One method to compute higher order derivative is to use the @@ symbol followedby a number. The next example computes the third derivative. Note that it isimportant to use parentheses.

> d3ydx3 := (D@@3)(y);

d3ydx3 := 6

Notice that this is how Maple write the constant function. The x-> is not present.Since the differential operator D returns a function, it can be evaluated at points.

Please notice that diff, returns an expression, even if you pass it a function! Theexample below computes the second derivative of y, evaluated at zero.

> bob := (D@@2)(y)(0);

4

We collect some common results in the theorem below.

Theorem 2. Let f, g be functions that are differentiable over a common interval.Then the following rules hold.

• Product Rule: (fg)′(x) = f ′(x)g(x) + f(x)g′(x).

• Quotient Rule:(

fg

)′(x) =

f ′(x)g(x) − f(x)g′(x)

[g(x)]2, provided g(x) 6= 0.

• Chain Rule: Further suppose that f(x) is defined at g(x). Then the derivativeof the composition of f with g at the point x is given by

(f ◦ g)′(x) = {f [g(x)]}′ = f ′[g(x)]g′(x).

Now look at the following lines of Maple code.

> D(w*z);

> D(w/z);

Page 27: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

3. CALCULUS AND FUNCTIONS 15

The first command generates

D(w)z + wD(z)

and the second generates

D(w)

z− wD(z)

z2

If we perform the simplify command on the previous step (the previous output isreferenced by a %),

> simplify(%);

we obtain the more familiar result

−−D(w)z + wD(z)

z2

Yep, the product and quotient rules for differentiation. How about this one:In Maple, composition is indicated by using the @ symbol. Thus the derivative

of two functions w ◦ z is computed by

> D(w@z);

D(w)@zD(z)

Thus, the output is the function [D(w) ◦ z]D(z), our usual Chain Rule.Now, notice that

> D(w(z));

is simply the derivative of the function w(z), not the derivative composition of w andz. Thus, Maple returns

D(w(z))

3.3. Integration. Now let’s look at integration. One way to define the definiteintegral is using a limit of Riemann sums, as shown below.

Definition 7. Let f(x) be a function and suppose that a, b ∈ R with a ≤ b. Then,the definite integral of f from a to b is

∫ b

a

f(x) dx = limn→∞

f(x∗i )∆x,

where ∆x =b − a

n, xi = a + i∆x and x∗

i ∈ [xi−1, xi] for i = 0, 1, . . . , n provided the

limit exists. If the limit exists, we often say that f is integrable over the interval [a, b].

Of course, having survived calculus, we know that we don’t have to evaluate theintegral, which gives rise to the indefinite integral. Recall that you won’t get a uniqueanswer when performing indefinite integration – you always must add a constant toyour answer.

Page 28: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 0. FUNCTIONS 16

In a standard calculus class, this definition quickly gives rise to several properties,which we collect in a theorem.

Theorem 3. Let f(x) be integrable over the interval [a, b]. Then

•∫ b

a

f(x) dx = −∫ a

b

f(x) dx

•∫ a

a

f(x) dx = 0

•∫ b

a

cf(x) dx = c

∫ b

a

f(x) dx for any c ∈ R

•∫ b

a

f(x) dx =

∫ c

a

f(x) dx +

∫ b

c

f(x) dx for suitable c ∈ R

•∫ b

a

[f(x) ± g(x)] dx =

∫ b

a

f(x) dx ±∫ b

a

g(x) dx

These properties are commonly used when a CAS package such as Maple is used.Suppose we wish to integrate the function defined in Maple by

> f := x -> x^2+2*a*x+a^2;

with respect to x. The integration command in Maple has two forms, int and Int.The former command performs the integration. Notice that even thought there areno limits of integration used, Maple does not tack on the arbitrary constant on theend. Maple assumes that we know enough to put it there (and you will rememberto put it there!). The latter integral generates a “pretty print” or inert form of theintegral. Thus, the two commands

> intf := int(f(x),x);

> Intf := Int(f(x),x);

return

intf :=1

3x3 + ax2 + a2x

Intf :=

x2 + 2ax + a2 dx

Of course, we can also evaluate definite integrals.

> intf := int(f(x),x = 3..12);

> Intf := Int(f(x),x = 3..12);

intf := 567 + 135a + 9a2

Intf :=

∫ 12

3

x2 + 2ax + a2 dx

You may have noticed that the output to the int command is an expression nota function. If you wish the output to be a function then you do the following:

Page 29: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

4. EXERCISES 17

> intf := x-> int(f(u),u=0..x);

intf := x− >

∫ x

0

f(u) du

Now, we are free to evaluate it at various points or even variables,

> intf(1);

> intf(x);

1

3+ a + a2

1

3x3 + ax2 + a2x

Note that we use a definite integral where we pick the lower limit arbitrarily to be 0and the upper limit to be x.

4. Exercises

0.1 Define a Maple expression f =x2 + 1

x2 − 1. Plot the expression using various

ranges for x and y. Try using the built in Maple “number” ∞, or infinity,in the ranges of the plot command.

0.2 Define a Maple function f(x) = x4 − 2x3 − 12x2 + 8. Try using the solve

and/or fsolve command to find all of the roots of this function. Graph thefunction with appropriate ranges to show all of the x-intercepts. you mightneed to use the help menus and the examples therein to figure out how tomake the solve or fsolve command find each root.

0.3 Define a Maple function g(x) = x3 − 7x + 6.A Graph the function g and find all of it’s roots.

B Define the function g(x) =x3 − 1

(x − 1)(x2 − 1). Find the limits as x ap-

proaches 1, -1, and ∞.C Find the first and second derivative of the function g as an expression.

Find the third and tenth derivatives of the function g as a function.D Find the anti derivative of the function g.E Do a full text search in the help for the topic “partial fraction.” Use the

help to get the partial fraction decomposition of the function g. Does thepartial fraction decomposition confirm the answer you obtained for theanti derivative found above?

0.4 Evaluate the following definite integral:

∫ 10

0

e−x2

dx. (Note: in Maple the

natural exponential function is exp. Also, recall that fsolve was the floatingpoint equivalent of solve. Is there a fint command and how would you geta numeric approximation to a definite integral?)

Page 30: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,
Page 31: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 1

Linear Algebra

1. Introduction

Linear Algebra is the mathematics of systems of linear equations. Mainly, it isthe study of matrices.

Definition 8. Let aij , bi ∈ R for 1 ≤ i ≤ m, 1 ≤ j ≤ n, be fixed numbers. Thenthe following is a system of linear equations in the unknown variables x1, . . . , xn:

a11x1 + a12x2 + · · ·+ a1n = b1

a21x1 + a22x2 + · · ·+ a2n = b2 (1.1)

...

am1x1 + am2x2 + · · ·+ amn = bm

.

Of course, we don’t have to use real numbers. Complex numbers, rational, orother choices of objects for the aijs and bis are acceptable. In an effort to ease theprocess of solving systems of equations, matrices were developed.

Definition 9. A matrix is a rectangular array of numbers (or other objects).Thus, a matrix, A, could be represented as

A = [aij ] =

a11 a12 · · · a1n

a21 a22 · · · a2n...

.... . .

...am1 am2 · · · amn

.

The size is the number of rows and columns, respectively. Thus A has size m×n.A square has size n × n. A vector is a 1 × n or m × 1 matrix.

Often, we refer the the ith row and jth column by the shorthand notation aij.Matrices are used extensively when solving systems of linear equations. We need

a few more basic definitions.

Definition 10. The coefficient matrix of the system of linear equations givenin 1.1 is

A =

a11 a12 · · · a1n

a21 a22 · · · a2n...

.... . .

...am1 am2 · · · amn

.

19

Page 32: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 1. LINEAR ALGEBRA 20

The right hand side vector is the column vector

b =

b1

b2...

bm

and the matrix of unknowns is the column vector

x =

x1

x2...

xn

,

both taken from the linear system in 1.1. Finally, the augmented matrix of the linearsystem in 1.1 is the matrix

[A | b] =

a11 a12 · · · a1n b1

a21 a22 · · · a2n b2...

.... . .

......

am1 am2 · · · amn bm

.

Hence, the system of linear equations in 1.1 can be represented in matrix form by

Ax = b, (1.2)

where A is the coefficient matrix, x is the matrix of unknowns, and b is the right handside vector.

In Maple there is a linear algebra package that is used to work with matrices.First we need to load the linear algebra package (also note the use of the restart

command to clear the Maple memory of any previous definitions):

> restart;

> with(LinearAlgebra):

Recall that the colon after the above command to load packages suppresses Maple

output. Sometimes it is informative to not suppress the output when loading pack-ages, especially if they are not familiar to you. The typical output yields a list of allcommands the newly loaded package supplies. For example, executing the followingcommand will generate a huge number of commands.

> with(LinearAlgebra);

Of course, many of the commands will be unfamiliar to you. But some, suchas Determinant, Trace, and MatrixInverse will have a function that is somewhat“obvious” in nature. For others, more advanced mathematics courses will be requiredbefore you understand their purpose. In any event, if there is a command you arecurious about, Maple help is the first place to check. Remember, you can use theshortcut command ? MatrixInverse to quickly learn about computing the inverseof a matrix.

Page 33: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

1. INTRODUCTION 21

In order to create a matrix or vector in Maple we can use the commands Matrixand Vector. For example, enter the commands

> M := Matrix([[1,2,3],[4,5,6]]);

> v := Vector([a,b,c]);

which causes Maple to generate the following output,[

1 2 34 5 6

]

a

b

c

.

Of course, sometimes it is necessary to create matrices quickly. Maple also hasthe following shortcuts for matrix creation.

> <<1|2|3>,<4|5|6>>;

> <a,b,c>;

which will create the same matrices. You can, of course, assign a label to thesematrices during creation. Maple also allows the user to quickly create matrices withdefault values. For instance,

> Matrix(3);

> Matrix(3, fill = 2);

both generate 3 by 3 matrices. By default, the first command fills the matrix withzeros, while the latter command fills the matrix with the number 2. The output fromthe above two commands is

0 0 00 0 00 0 0

2 2 22 2 22 2 2

With Maple the optional parameter shape is used to specify various commonmatrices, such as diagonal, symmetric, identity, triangular, etc. See Maple help formore information on shape.

Definition 11. Let A = [aij ].

• A is a diagonal matrix if it is a matrix such that aij = 0 whenever i 6= j.• The transpose of A = [aij ] is the matrix AT = [aji].• A is symmetric if AT = A.• The identity matrix is the diagonal matrix where aii = 1.• A is upper triangular if aij = 0 whenever i > j. A is lower triangular if

aij = 0 whenever i < j.

Page 34: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 1. LINEAR ALGEBRA 22

It is also possible to create diagonal matrices using a vector for the diagonalelements. The optional fill parameter can be used to specify how the missingdiagonal elements should be initialized. For example, we can use a 3 by 1 vector toinitialize the diagonal of a 4 by 4 matrix. The last diagonal element will be initializedto 0 (unless otherwise specified by use of the fill option). Thus,

> v := Vector([1, 2, 3]):

> M := Matrix(4, v, shape = diagonal, fill = Pi);

generates the output

M :=

1 0 0 00 2 0 00 0 3 00 0 0 π

Note that the vector v did not appear because the colon suppresses output.

2. Basic Operations with Matrices

We next define some basic operations on matrices.

Definition 12. Let A and B be matrices.

• Matrix addition is defined whenever the matrices A and B agree in size;the resulting new matrix is computed by adding corresponding entries of thematrices together, that is

A + B = [aij + bij ].

• Let r ∈ R. Scalar multiplication is defined by multiplying each entry by thescalar r, that is rA = [raij].

• The dot product of the vectors v = (v1, . . . , vn) and w = (w1, . . . , wn) is thenumber

n∑

i=1

viwi = v1w1 + · · · + vnwn.

• Multiplication of matrices, C = AB, is defined whenever the number ofcolumns of A = [aij ] equals the number of rows of B = [bjk]. Suppose A

is m × n and B = n × q. The new matrix, C = [cik] has entries given by

cik =

n∑

j=1

aijbjk

and has size m × q.

Notice that we can perform matrix subtraction by “adding the negative,” that isA + (−1)B. Matrix multiplication looks a bit intimidating at first glance. However,it is easy if you remember that to compute the cik element, simply perform the dotproduct of the ith row of A with the kth column of B.

Let’s define several matrices.

Page 35: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

2. BASIC OPERATIONS WITH MATRICES 23

> A := Matrix([[1,2,3,4,5],[6,7,8,9,10]]);

> B := Matrix([[1,2,3],[4,5,6],[7,8,9],[10,11,12],[13,14,15]]);

> C := Matrix([[4,3,2,1,0],[7,5,3,4,5]]);

> E := Matrix([[1,2],[3,4]]);

Maple returns the following matrices in its output.

A :=

[

1 2 3 4 56 7 8 9 10

]

B :=

1 2 34 5 67 8 910 11 1213 14 15

C :=

[

4 3 2 1 07 5 3 4 5

]

E :=

[

1 23 4

]

Notice that matrices A and C both have dimensions 2×5 (two rows, five columns),B has dimensions 5 × 3, and D is a 2 × 2 (square) matrix. Recall that if we wishto add matrices, the dimensions must agree. Thus, we see that it is possible to addmatrices A and C. Note that matrix addition is commutative as can easily be shown:

A + C = [aij + cij ] = [cij + aij ] = C + A.

In Maple, matrix addition and subtraction are easy. Just use the standard “+” or “-”symbols. Scalar multiplication is just a shorthand for addition. So, 3C = C +C +C.For example,

> F:= A+3*C;

generates the the new matrix F :

F :=

[

13 11 9 7 527 22 17 21 25

]

From the definition of multiplication, we know that the number of columns of thematrix on the left must agree with the number of rows of the matrix to the right ofthe multiplication symbol. So, we could multiply a matrix X of size m × n times amatrix Y of size n × p. This would generate a matrix XY of size m× p. However, ifp 6= m, we could not form the product Y X. Thus it is possible to form the productsAB, CB, FB, DA, and DC. Since D is a square matrix, we can multiply D byitself. No other products are possible. In Maple we use a period “.” to denotematrix multiplication. This is true because scalar multiplication (the shorthand formatrix addition) is different than matrix multiplication and requires different symbols.There is a shorthand for matrix multiplication: exponentiation. Thus E2 = EE, aswe might suspect. For example,

> (A+3*C).B;

> E^2;

Page 36: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 1. LINEAR ALGEBRA 24

yields[

255 300 345769 881 993

]

[

7 1015 22

]

3. Solving Systems of Equations

Next, we shall consider some of the more useful Maple commands. For example,in mathematics, the system of equations

x + y + z = 6

x − y + z = 2

2x − 3y + z = −1

can be represented in terms of a matrix equation by

1 1 11 −1 12 −3 1

x

y

z

=

62−1

.

This matrix equation has the form Ax = b, where A is a 3 by 3 coefficient matrix, x

is a 3 by 1 variable matrix (vector) and b is the right-hand-side vector. To solve thismatrix equation in Maple we use the LinearSolve command:

> A := Matrix([[1,1,1], [1,-1,1], [2,-3,1]]):

> b := Vector([6,2,-1]):

> sols := LinearSolve(A,b);

This generates the output

sols :=

123

So x = 1, y = 2 and z = 3. Recall that when solving systems of equations it ispossible for there to be no solutions, one solution (as in this case), or an infinitenumber of solutions. If there is one unique solution to the matrix equation, then wealso know that the matrix A is invertible.

Definition 13. A square matrix, A, has inverse, A−1, if AA−1 = I = A−1A

where I is the identity matrix. Otherwise A is called a singular matrix.

Note that the definition does not guarantee that all (square) matrices have in-verses. In fact, they don’t. Simply consider the zero matrix. Any matrix multiplica-tion with the zero matrix generates another zero matrix.

Page 37: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

3. SOLVING SYSTEMS OF EQUATIONS 25

As a second example, consider the system of equations

2x + 3y − z = 5

x − y + z = 2

3x − 2y + 3z = 7

which can be represented in terms of a matrix equation by

2 3 −11 −1 13 −2 3

x

y

z

=

527

.

We can solve this system with Maple by the following series of commands.

> A := <<2|3|-1>, <1|-1|1>, <3|-2|3>>:

> b := <5,2,7>:

> sols := LinearSolve(A,b);

with the resulting solution given by

sols :=

53143

.

We can access individual elements of the solution vector by subscripting, that is

> sols[2];

> y := sols[2];

generates the output

1

y := 1

Now consider the system of equations given by

w + 3x − 2y = 1

3w + 10x − 7y + z = 2

−5w − 5x + 3y + 7z = 3

Notice that we have more unknowns than equations. This will give rise to an infinitenumber of solutions. To solve in Maple execute the following commands.

> F := Matrix([[1,3,-2,0],[3,10,-7,1],[-5,-5,3,7]]):

> c := <<1>,<2>,<3>>:

> LinearSolve(F,c);

Maple returns the following output.

−2 + 2 t41,1

56 + t41,1

t41,1

Page 38: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 1. LINEAR ALGEBRA 26

Note that Maple uses the symbol t41,1 to indicate that it is a variable and canassume any value in R. The 4 in t4 indicates that it represents the fourth variable,that is z. Thus, we have an infinite number of solutions, depending upon our choiceof z. A better way to write this solution is

w

x

y

z

=

−2 + 2z5

6 + z

z

=

−2560

+ z

2011

where z ∈ R.Notice that

F

−2560

= c

and

Fz

2011

= 0.

This happens often enough that we need to have another definition.

Definition 14. Let A be a matrix. The Kernel of A, Ker(A), or the null spaceof A, Null(A), is the set of all vectors x such that Ax = 0. That is,

Ker(A) = {x | Ax = 0}.

Thus, in the preceding example, we have a particular solution as well as an infinitenumber of solutions in the Kernel of F .

We close with the following theorem.

Theorem 4. If u is a vector so that Au = b, then every solution of the equationAx = b has the form x = u + z, for some z ∈ Ker(A).

4. Eigenvalues and Eigenvectors

One other topic in linear algebra that will be used in this course is the concept ofeigenvalues and eigenvectors.

Definition 15. Let λ ∈ C and nonzero vector v satisfy the equation

Av = λv.

Then we say that λ is an eigenvalue and v is an eigenvector. An eigenvalue hasmultiplicity n if it is repeated n times.

Page 39: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

4. EIGENVALUES AND EIGENVECTORS 27

Even if the matrix A is a real matrix, it is still possible to obtain complex eigen-values and eigenvectors. We often write the eigenvalue and eigenvector as an orderedpair (λ, v), the eigenpair. Recall that the n× n identity matrix I is defined to be thediagonal matrix with 1 on the diagonal. Thus, from the equation Av = λv, we obtainan equivalent matrix equation

(A − λI)v = 0,

where I is the identity matrix that is the same size as A.The Eigenvectors command returns a vector of eigenvalues and a matrix of

eigenvectors whose ith column corresponds to the ith eigenvalue.As an example, if A is the matrix defined in the above example, the eigenvalues

and corresponding eigenvectors for A can be found using the command

> eigenpair := evalf(Eigenvectors(A));

This generates the output

eigenpair :=

−0.5468182772.273409138− 0.5638210935I2.273409138 + 0.5638210935I

,

−.6130749014 −.04712108605 − .1938119405I −.04712108605 + .1938119405I.8537967884 .2926138014− .008807364489eI .2926138014 + .008807364489I

1 1 1

We can easily access the eigenvalue vector or eigenvector matrix by

> eigenvals := eigenpair[1];

> eigenvecs := eigenpair[2];

eigenvals :=

−0.5468182772.273409138− 0.5638210935I2.273409138 + 0.5638210935I

eigenvecs :=

−.6130749014 −.04712108605 − .1938119405I −.04712108605 + .1938119405I.8537967884 .2926138014− .008807364489eI .2926138014 + .008807364489I

1 1 1

To choose a particular eigenvalue or the associated eigenvector, enter the commands

> lambda1 := eigenvals[1];

> v1 := Column(eigenvecs, 1);

This generates the output

lambda1 := −0.546818277

v1 :=

−0.61307490140.8537967884

1

Page 40: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 1. LINEAR ALGEBRA 28

As an example, we compute the eigenpairs for the matrix

B :=

1 2 3 40 1 2 30 0 −2 10 0 0 π

.

> B := Matrix([[1, 2, 3, 4], [0, 1, 2, 3], [0, 0, -2, -1],

[0, 0, 0, Pi]]):

> evalB := Eigenvectors(B);

The output given by Maple is

evalB :=

π

−211

,

3 + 7π + 4π2

(π + 2)(π − 1)2−5

91 0

4 + 3π

(π + 2)(π − 1)−2

30 0

− 1

π + 21 0 0

1 0 0 0

The order of the eigenvalues may change. Note that the e-values ofB are 1, -2, andπ, where the e-value 1 has multiplicity 2. In this example, the matrix B is uppertriangular (zero’s in all elements below the main diagonal). If a matrix is upper (orlower) triangular then the e-values of that matrix are the diagonal elements and themultiplicity of the e-value is the number of times it appears on the diagonal.

Recall that the definition of eigenvector requires that the eigenvector be nonzero.And yet, the eigenvector corresponding to the last eigenvalue, 1, is a zero vector. Thisfrequently occurs which motivates the following definition.

Definition 16. An n × n matrix is said to be defective if it does not have n

(nonzero) eigenvectors.

Maple ’s default behavior is to return a square matrix, “padding” with columnsof zeros whenever the matrix is defective. The optional parameter output=’list’

returns eigenvalues and eigenvectors formated as a list which contains the eigenvalue,its multiplicity, and the associated eigenvector(s).

> Eigenvectors(B,output=’list’);

The output given by Maple is

evalB :=

−2, 1,

−5

9

−2

310

,

π, 1,

3 + 7π + 4π2

(π + 2)(π − 1)2

4 + 3π

(π + 2)(π − 1)

− 1

π + 21

,

1, 2,

1000

Page 41: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

5. EXERCISES 29

Note that the order of the list may change. Now, we can clearly see that 1 is arepeated eigenvalue (repeated twice) and yet there is only one eigenvector associatedwith it. Thus, matrix B is defective.

As a final example, consider:

> C := <<1,2,3>|<2,4,6>|<5,10,15>>:

> Eigenvectors(C, output=’list’);

This generates the following list of eigenpairs.

10, 1,

13231

,

0, 2,

−501

,

−210

Notice that we have eigenvalues 20 (multiplicity 1) and 0 (multiplicity 2). The eigen-value zero has two eigenvectors associated with it. Thus, matrix C is not defective.

5. Exercises

1.1 Use matrix equations to solve the following systems of equations.A

x − 2y + z = 2

3x − 4y + 5z = 15

2x + y − 3z = 1

B

x + y + z + w = 0

x − y + z − w = 6

2x − y + 2z − w = 3

x + y + 2z = 4

C

a + b + c = 5

2a − b − c = 4

a − 2b − 2c = −1

D

s + 2t − u = 2

3s − t + u = 1

s − 5t + 3u = 3

Page 42: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 1. LINEAR ALGEBRA 30

1.2 Find the e-values and e-vectors of the coefficient matrix in

x + y + z + w = 0

x − y + z − w = 6

2x − y + 2z − w = 3

x + y + 2z = 4

Page 43: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 2

Ordinary Differential Equations

1. Introduction

Applied mathematics is the study of describing the natural world. In this study weare often more interested in how things change rather than how things are currently.We want to study how things change in order to predict how things will be in thefuture. Often it is easier to measure how things change.

In mathematics, rates of change are described by derivatives. Thus, an importantfield of mathematics is that of equations which have derivatives in them. This is aextremely broad field of study that includes ordinary and partial derivatives, linearand nonlinear equations, systems of equations and numerical techniques. We willcover some of the basics.

Definition 17. An nth order, constant coefficient, linear ordinary differentialequation has the form

dny

dxn+ an−1

dn−1y

dxn−1+ · · ·+ a1

dy

dx+ a0y = f(x),

where ai are constants.

For example, the growth rate of a population with unlimited resources is propor-tional to the population size. In mathematics this statement can be modeled by thefirst order equation

dP

dt= kP,

where the function P represents the population at time t. This is one of the simplestordinary differential equations (ODE’s). We can solve this equation by the methodof separation of variables and we get a solution of

P (t) = Cekt,

where C is an unknown constant. In order to determine C, we typically need to havemore information, such as an initial condition, say a population value P (0) = p0.

In Maple we would use the dsolve command.

> sols:=dsolve({diff(P(t),t)=k*P(t),P(0)=p0});Maple returns the solution

sols := P (t) = p0ekt

31

Page 44: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 2. ORDINARY DIFFERENTIAL EQUATIONS 32

Here we have written the differential equation in terms of the Maple diff com-mand and given the problem initial conditions of P (0) = p0. Often it helps to lookat a graph of solutions of differential equation. In order to use the previous outputwe would have to define an expression using the rhs command. So, we assign P tobe our function and choose an initial condition p0 = 1 and a particular value for ourpopulation growth, k = 0.2.

> P:=rhs(sols);

> p0:=1; k:=0.2;

p0ekt

1

0.2

Now, we can plot the solution, P .

> plot(P,t=0..10);

This generates Figure 7.

t0 2 4 6 8 10

1

2

3

4

5

6

7

Figure 7. Plot of the solution P (t) = e0.2t over 0 ≤ x ≤ 10.

If we wanted P as a function rather than an expression we would use the unapplycommand. First, we unassign the values to p0 and k using Maple’s unassign com-mand so that the previously assigned values are erased or “undone”.

> unassign(’p0’); unassign(’k’);

Now we can use the unapply command on the expression returned by rhs(sols)

> P2:=unapply(rhs(sols),t);

This generates the function

P2 := t− > p0ekt

Notice that P2 is a function, not an expression as the following Maple code suggests:

Page 45: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

2. SYSTEMS OF FIRST ORDER, LINEAR, ODE’S 33

> P2(1); P2(10);

p0ek

p0e10k

2. Systems of First Order, Linear, ODE’s

Systems of ODE’s come about when you have more than one dependent variable,one independent variable and the rate of change in the dependent variables can dependon any combination of the independent and dependent variables.

Definition 18. A system of m first order, ordinary differential equations hasthe form

dy1

dx= f1(y1, . . . , ym)

dy2

dx= f2(y1, . . . , ym)

...

dym

dx= fm(y1, . . . , ym).

For example, consider the following system that models the competition betweentwo species of animal.

du

dt= 2u − uv = f1(u, v)

dv

dt= −v +

1

2uv = f2(u, v).

If the first species is u and the second is v, then the first species is harmed by thesecond species (the −uv interaction term indicates a decrease in the rate of changeof the population of u), while the second benefits from interactions between the twospecies

(

the +12uv interaction term indicating an increase in the rate of change of the

population v(t))

. This is a simple predator-prey model. Lets see how Maple solvesthis system. Note in the following that the general form of the dsolve command is{list of equations and initial conditions}, {list of things to solve for} and then optionswhich we will see a little later. If you want to use vertical spacing (as shown below)to aid in readability, you must use SHIFT-ENTER. Note that square braces can beused in place of curly braces.

> restart;

> sols:=dsolve([diff(u(t),t)=2*u(t)-u(t)*v(t),

diff(v(t),t)=-v(t)+u(t)*v(t)/2,

u(0)=5,v(0)=5]);

Page 46: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 2. ORDINARY DIFFERENTIAL EQUATIONS 34

Warning, computation interrupted

Well, that didn’t work. Note that Maple ran for several minutes before we gave upand interrupted the computations (using the Red Hand button next to the explanationpoints). This is one of the ways that Maple uses to indicate that it couldn’t solve theproblem. As a side note, the most common other ways that Maple uses to indicateit’s inability to arrive at an answer “in closed form” is to output a blank solution(indicating an unsolvable problem) or to output a “proc...end” (indicating that thesolution arrived at is a Maple procedure).

In this case we need to see if we can approximate the solution and generate agraph to investigate the dynamics of this system. We turn to Maple’s help forthe commands dsolve, dsolve systems and dsolve numeric to see how to do anumerical approximation. Note that for a numerical solution the initial conditionsmust be numbers, not unknown constants. Here we illustrate the use of dsolve withseveral options.

> sols2:=dsolve({diff(u(t),t)=2*u(t)-u(t)*v(t),diff(v(t),t)=-v(t)+u(t)*v(t)/2,

u(0)=5,v(0)=5}, type=numeric, output=listprocedure);

By requesting type=numeric, Maple uses (as a default) a fifth order Runge-KuttaFehlberg method. This generates the weird output

[t = proc(t) . . . end proc; , u(t) = proc(t) . . . end proc; , v(t) = proc(t) . . . end proc; ]

This output is generated because of our optional request output=listprocedure.The function dsolve returns the independent variable t and the dependent variablesu(t), v(t) in terms of procedures. These returned procedures can then be used toestimate the variables.

For example, let’s try and get a graph of the solution.

> us:=subs(sols2,u(t)); vs:=subs(sols2,v(t));

us := proc(t) . . . end proc;

vs := proc(t) . . . end proc;

The subs command is used here to “pull out” the solutions. At this point the labelsus and vs are functions. If we want to look at graphs of these functions we would usethe function form of the plot command:

> plot(us,0..20);

> plot(vs,0..20);

This generates the state spaces of u(t) and v(t) shown in Figure 8 over the domain0 ≤ t ≤ 20. In other words, the independent variable, t, is on the horizontal axis andthe dependent variables, u and v, are on the vertical axis.

Another way to represent the solution is by a phase space plot where u(t) is plottedversus v(t) over a common range for the independent variable t. Here we are thinking

Page 47: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

2. SYSTEMS OF FIRST ORDER, LINEAR, ODE’S 35

0 5 10 15 20

1

2

3

4

5

6

7

8

8(A) The state space of u(t).

0 5 10 15 20

1

2

3

4

5

8(B) The state space of v(t).

Figure 8. Plot of the state space of u(t) and v(t) from 0 ≤ t ≤ 20.

Option Possibilitiescolor Black, Blue, Brown, Gold, Gray, Green, Orange, Pink, Purple, Red,

Silver, Tan, Violet, White, Yellowstyle line(default), point, polygon, polygonoutlinesymbol asterisk, box, circle, cross, diagonalcross, diamond, point, solidbox,

solidcircle, soliddiamondTable I. Selected Maple plot options.

of u and v as being parametric functions of t. Hence, we will use the “parametric”form of the plot command. In this process, we suppress the output of the plot

command with a “:”. The resulting “plot structure” (output from the commandplot) is assigned to a label. Thus, we can refer to the outputs later. Before we canuse Maple’s display command, we need to load a new package, with(plots):. Thecommand display is used to display Maple plot structures. Thus, we can displaymultiple graphs on the same plot.

Below, the first call to plot creates a parametric plot of u(t) vs v(t) over thecommon domain t ∈ [0, 20]. The second call to plot generates a single point at (5, 5)for the initial conditions. We’ve also included several options to plot. These optionsinstruct Maple that it is plotting a single point (style=point), using an open circle(symbol=circle) in the color black (color="Black"). See Table 2 for other optionsor refer to Maple help. Note that Maple has a huge number of colors available. Seeplot,colornames for a complete listing.

> p1:=plot([us,vs,0..20]):

> p2:=plot([[5,5]],style=point,symbol=circle,color="Black"):

> with(plots): display(p1,p2);

We’ve now generated the phase space plot shown in Figure 9.Sometimes it is necessary to solve a system of ODE’s with several different ini-

tial conditions. Maybe several initial populations for the predator while the preypopulation has the same initial conditions.

Page 48: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 2. ORDINARY DIFFERENTIAL EQUATIONS 36

1 2 3 4 5 6 7 8

1

2

3

4

5

Figure 9. Phase space plot of u(t) vs v(t) over 0 ≤ t ≤ 20 with initial conditions.

As an example, we solve the previous system with initial condition of u(0) = 5and v(0) = 2, 4, 5, and 7.

Here we have four different solutions we need to find. First define a list of the v

initial conditions. We’ll see lists in much more detail in Chapter 4.

> v0:=[2, 4, 5, 7];

[2, 4, 5, 7]

We can access individual positions in the array as follows

> v0[1]; v0[2]; v0[3]; v0[4];

2

4

5

7

Note the use of square brackets when referencing individual elements of v0. Now usea seq command to solve the four systems of equations.

> sols3:=seq(dsolve({diff(u(t),t)=2*u(t)-u(t)*v(t),diff(v(t),t)=-v(t)+u(t)*v(t)/2, u(0)=5,v(0)=v0[k]},type=numeric, output=listprocedure), k=1..4);

Page 49: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

2. SYSTEMS OF FIRST ORDER, LINEAR, ODE’S 37

Table II. Common Arguments for Vector

Argument Choicesdatatype integer, float, complexfill valueorientation row, column

[t = proc(t) . . . end proc; , u(t) = proc(t) . . . end proc; , v(t) = proc(t) . . . end proc; ],

[t = proc(t) . . . end proc; , u(t) = proc(t) . . . end proc; , v(t) = proc(t) . . . end proc; ],

[t = proc(t) . . . end proc; , u(t) = proc(t) . . . end proc; , v(t) = proc(t) . . . end proc; ],

[t = proc(t) . . . end proc; , u(t) = proc(t) . . . end proc; , v(t) = proc(t) . . . end proc; ]

Note how sols3 is a list of four solutions of the type we saw above. To graph thesesolutions we need to define a list of graphics objects and then display the list.

We could use the array type to store our data, but it has been deprecated innewer versions of Maple. So, we’ll try using Vector instead.

> p := Vector(4):

The single argument used is the number of spots in our vector. There are many otheroptional arguments that we have not used. In fact, all arguments are optional. SeeTable II for a brief list of interesting arguments. For example, the following commandcreates a vector of size three that can hold integers. Each location is initialized tothe value 1. See Maple help for more information.

> w := Vector(3, datatype=integer, fill=1);

w :=

111

Now, let’s return to our problem.

> for j from 1 to 4 do

us:=subs(sols3[j],u(t)):

vs:=subs(sols3[j],v(t)):

p[j]:=plot([us,vs,0..20]):

od:

> icp:=plot([seq([5,v0[k]],k=1..4)],style=point,symbol=circle,

color=‘‘Black’’):

> display(icp,seq(p[k],k=1..4));

O.K. Lots of fun stuff to talk about. First the Vector command. This commanddefines the variable p to be a list with four elements, so that we can reference itlater. Second the for command. This is a looping command. The index, j, of thiscommand takes on the values of 1, 2, 3, and 4. For each value of the index the

Page 50: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 2. ORDINARY DIFFERENTIAL EQUATIONS 38

2 4 6 8 10

1

2

3

4

5

6

7

Figure 10. Phase space plot of u(t) vs v(t) over 0 ≤ t ≤ 20 withinitial conditions v0 = 2, 4, 5, 7.

commands bracketed by the do and od are executed. So, for each j, we choose thejth solution and assign the appropriate procedure to us and vs. Next, a phase plot isgenerated and stored in the jth location of the array, p. Thus, by executing the forloop, we define four phase plots corresponding to the four solutions. Next we use aseq command in a plot to define the graph of the four initial conditions. Finally, weuse the display and seq commands to show the graphs of the solutions and initialconditions.

The resulting output is shown in Figure 10.

3. Exercises

2.1 Use the dsolve command to solve the following problems. If a closed formsolution is possible (and aesthetically pleasing) then show that solution. IfMaple does not give a nice closed form solution, then find a numerical solutionwith initial conditions of y(0) = 1 and graph the solution.

Ady

dx= 2y − 1

Bdy

dx= xy

Cdy

dx= x2y − xy2 + x

2.2 Use the dsolve command to numerically solve the following systems of equa-tion. Generate both state and phase space graphs of the solution (try differentranges of the independent variable to see what works).

Page 51: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

3. EXERCISES 39

A

dy

dt= x + xy x(0) = 1

dy

dt= x2 − y y(0) =

1

2B

dy

dt= xy sin(t) x(0) = 1

dy

dt= xy cos(t) y(0) = 2

C

dy

dt= 2x − 1

2xy x(0) = 3, 6, 9, 12, 15

dy

dt=

1

5xy − y y(0) = 1

Page 52: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,
Page 53: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 3

Population Models in Biology

1. Introduction

The interaction between mathematics and theoretical biology has been long andrich. Some of the earliest differential equations involved descriptions of how popula-tions grow and change in time. Perhaps more interestingly, theoretical biology haschallenged mathematicians with novel nonlinear equations and nonlinear phenomena.Even now, some of the most interesting nonlinear equations which mathematiciansstudy are derived from models of population biology.

In this chapter, you will be introduced to a range of population models, froma simple exponential model of bacteria growth to a complicated nonlinear set ofequations describing the population in a chemostat, or biological reactor. Early onwe will discover how much simpler it is to use symbolic aids to take care of mechanicalmanipulations.

2. Malthusian Models - Exponential Growth

In 1798 Malthus applied a simple differential model to the growth of the humanspecies and predicted that, barring natural disaster and disease, the human populationwould grow exponentially, use all available resources, and then die of starvation.This model failed to include limitations due to disease and other population densitydependent processes. To begin the modeling work, let P (t) denote the number ofindividuals in a population at any given time, t. We will assume that the modelmeasures the population continuously over time. We must realize that this model isat best an approximation of the real population. In reality, births and deaths occurdiscretely in time. However, if we model a large population over a long period oftime, then the process can be modeled using continuous equations.

The Malthusian model states that a population grows in proportion to the numberof individuals in the population. Mathematically that is,

dP

dt= kP (t)

where the proportionality constant, k, is called the growth rate constant or net re-production rate. To complete this first order Ordinary Differential Equation (ODE)model we need an initial condition. Thus, let t = 0 be a reference time at which weknow that the population has P0 individuals. So the full model of population growth

41

Page 54: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 3. POPULATION MODELS IN BIOLOGY 42

(as of now) isdP

dt= kP (t), P (0) = P0.

This is one of the first types of problems one encounters in a basic course in Ordi-nary Differential Equations. One method to solve such a problem is the method ofseparation of variables. Using the algebra of differentials the ODE becomes

dP = kPdt.

Next, divide both sides by P to obtain

dP

P= kdt.

Integrating both sides yieldsln(P ) = kt + C1.

Exponentiating gives us the solution

P (t) = ekt+C1 = eC1ekt = Cekt.

This is the general solution (or family of solutions) to the ODE. In order to find theparticular solution that corresponds to the initial conditions, we substitute the initialconditions into the general solution and solve for C.

P (0) = P0 ⇒ Cek·0 = P0.

So C = P0, and the solution to the initial value problem is

P (t) = P0ekt.

In Maple we would arrive at this solution by doing the following:

> restart;

> sols:=dsolve({diff(P(t),t)=k*P(t),P(0)=P0});

sols := P (t) = P0ekt

> P:=unapply(rhs(sols),t);

P := t → P0ek∗t

Now we can substitute values for P0 and k and graph the results. For instance, ifP0 = 1 and k = 0.1 we have

> P0:=1; k:=.1;

P0 := 1

k := .1

Page 55: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

2. MALTHUSIAN MODELS - EXPONENTIAL GROWTH 43

> plot(P(t),t=0..20,title="Exact Model Solution",labels=[t,’P(t)’],

labelfont=[TIMES,ITALIC,12]);

See Figure 11 for the graph of the solution at these particular parameter values. Thehorizontal axis is time, t, and the vertical axis is P (t), the population size at time t.Notice, that with our parameter choices, P (t) = e0.1t. So, the population explodesexponentially, as we expected.

We snuck in a few new commands in order to customize the appearance of theMaple plot. One is title, which assigns a title to the graph. We also wanted tospecify the labels of the axes. This took two commands, labels and labelfont. Thelabels command specifies the horizontal and vertical labels for the plot. In orderto typeset P (t), we must use unasign quotes . These single quotes instruct Maple

to typeset using the label of the expression rather than the expression itself. Finally,the labelfont command that alters the font specifications for the labels. You canalso use the font command to alter the fonts in the entire plot. However, this wouldeffect all text typeset in the plot, including the title as well as the axes. The commandlabelfont (as well as axesfont and titlefont) use the same options as font, whichare listed in Table III. The command font requires a font family, font style, and fontsize. The family as well as the style must be in upper case.

Table III. List of font Options

Family StyleTIMES ROMAN, BOLD, ITALIC, or BOLDITALICCOURIER BOLD, OBLIQUE, or BOLDOBLIQUEHELVETICA BOLD, OBLIQUE, or BOLDOBLIQUESYMBOL None Available

If we wanted to see how the growth rate effects the solution, we could graph thesolution for a variety of k values. In what follows we use a for loop to generate severalsolutions then a display command to plot them simultaneously. See Figure 12 forthe output. Again, the horizontal axis is time, and the vertical axis is the populationsize.

> g:=Vector(6):

for j from 1 to 6 do

k:=(2*j-1)*.1:

g[j]:=plot(P(t),t=0..20):

od:

> with(plots):

> display(seq(g[j],j=1..6),view=[0..20,0..20],labels=[t,’P(t)’],

labelfont=[TIMES,ITALIC,12]);

Here we used k values of .1, .3, .5, .7, .9, and 1.1. As k increases so does the rate atwhich the population grows (hence we call k the growth rate constant).

Page 56: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 3. POPULATION MODELS IN BIOLOGY 44

Exact Model Solution

1

2

3

4

5

6

7

P(t)

0 2 4 6 8 10 12 14 16 18 20

t

Figure 11. Malthusian Growth – Exact Solution for p0 = 1, k = 0.1.

0

2

4

6

8

10

12

14

16

18

20

P(t)

2 4 6 8 10 12 14 16 18 20

t

Figure 12. Malthusian Growth – Exact Solution for p0 = 1, k = 0.1,.3, .5, .7, .9, and 1.1.

3. The Logistic Model

Clearly it is not realistic to expect ongoing exponential growth. As a populationgrows, it consumes resources. That in turn influences how rapidly it can continue togrow. One model, first proposed by Verhulst in 1838, that reflects this consumptionof resources is the logistic model. Again, let P (t) denote the number of individualsin some population and let C(t) denote the amount of some limiting resource, suchas arable land in the case of human populations. As the population increases the

Page 57: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

3. THE LOGISTIC MODEL 45

amount of land needed to support the population must also increase. So, if there isa limited amount of land then the population will also be limited.

Mathematically we must write equations that relate the rate of change in popula-tion and the use of the limiting resource. To do this we assume that the growth rateof the population varies jointly with the current population and the unused amountof the limiting resource available. That is

dP

dt= aCP.

where a is a positive net-growth constant. The other relationship is that of how theunused amount of the limiting resource changes when the population changes. In thiscase as the population increases the amount of unused resources will decrease. If weassume that these rates are proportional then

dC

dt= −b

dP

dt,

with the constant b > 0. The initial conditions that go along with this system ofODE’s would be

P (0) = P0, and C(0) = C0.

In this case the system of ODE’s can easily be reduced to a system of one equation.We do this by integrating the second ODE to obtain

C(t) = −bP (t) + C1.

Plugging in the initial conditions for C gives us

C(t) = C0 − bP (t).

Next substitute the expression for C into the first ODE to reduce the problem to

dP

dt= aP (C0 − bP ) , P (0) = P0.

Let’s see if Maple will solve this initial value problem for us.

> unassign(’P’,’P0’);

> Logistic:=dsolve({diff(P(t),t)=a*P(t)*(C0-b*P(t)),P(0)=P0});

Logistic := P (t) = − P0C0

−bP0 − e−aC0tC0 + e−aC0tbP0

> simplify(rhs(Logistic));

− P0C0

−bP0 − e−aC0tC0 + e−aC0tbP0

If we do a little post-processing on this we get

P (t) =C0P0e

aC0t

P0b (eaC0t − 1) + C0.

Page 58: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 3. POPULATION MODELS IN BIOLOGY 46

This looks somewhat complicated, so we will assume that the initial condition areboth unitary (i.e. 1 unit of population and 1 unit of available resources).

> P:=unapply(rhs(Logistic),t);

P := t− > − P0C0

−bP0 − eaC0tC0 + e−aC0tbP0

> C0:=1; P0:=1;

C0 := 1

P0 := 1

> P(t);

P := t− > − 1

−b − eat + e−atb

To see how a effects the solution we can look at several plots of the total population,P (t) over time holding b fixed (at say .1) and varying a.

> b:=.1; a:=.1;

b := 0.1

a := 0.1

Graphing this particular solution in Maple can be done using the following command

> g1:=plot(P(t),t=0..50,title="Logistic Solution",labels=[t,’P(t)’],

labelfont=[TIMES,ITALIC,12]): display(g1);

which has an output shown in Figure 13(A). Looking at several other values for a wehave

> a:=.2;

g2:=plot(P(t),t=0..50,title="Logistic Solution",labels=[t,’P(t)’],

labelfont=[TIMES,ITALIC,12]):

display(g2);

> a:=.3;

g3:=plot(P(t),t=0..50,title="Logistic Solution",labels=[t,’P(t)’],

labelfont=[TIMES,ITALIC,12]):

display(g3);

> display(g1,g2,g3);

with outputs given in Figures 13(B) and 13(C). In Figure 13(D), we have a compositegraph of the three previous plots.

Page 59: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

3. THE LOGISTIC MODEL 47

Logistic Solution

2

4

6

8

P(t)

0 10 20 30 40 50

t

13(A) Logistic Solution – b = 0.1, a = 0.1.

Logistic Solution

2

4

6

8

10

P(t)

0 10 20 30 40 50

t

13(B) Logistic Solution – b = 0.1, a = 0.2.

Logistic Solution

2

4

6

8

10

P(t)

0 10 20 30 40 50

t

13(C) Logistic Solution – b = 0.1, a = 0.3.

Logistic Solution

2

4

6

8

10

P(t)

0 10 20 30 40 50

t

13(D) Logistic Solution – composite plot.

Figure 13. Logistic Solution – varying a value.

Note that in all of the above cases the solution approaches the value 10 as timeincreases. The parameter a effects how fast the solution approaches it’s limiting value.To see how b effects the population, P (t), as time varies, graph it holding a fixed at.2 and vary b.

> a:=.2:

> b:=.05:

g4:=plot(P(t),t=0..50,title="Logistic Solution",labels=[t,’P(t)’],

labelfont=[TIMES,ITALIC,12]):

> b:=.2:

g5:=plot(P(t),t=0..50,title="Logistic Solution",labels=[t,’P(t)’],

labelfont=[TIMES,ITALIC,12]):

> b:=.3:

g6:=plot(P(t),t=0..50,title="Logistic Solution",labels=[t,’P(t)’],

labelfont=[TIMES,ITALIC,12]):

> display(g4,g5,g6);

with output given in Figure 14.

Page 60: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 3. POPULATION MODELS IN BIOLOGY 48

Logistic Solution

2

4

6

8

10

12

14

16

18

20

P(t)

0 10 20 30 40 50

t

Figure 14. Logistic Solution – varying b value.

In this case the limiting value of the solution is effected by changing b. Now letslook at changing the initial population. Let’s use a = .2 and b = .1, and graph initialpopulations from 1 to 15 over time.

> g:=Vector(15):

> a:=.2: b:=.1:

> for j from 1 to 15 do

P0:=j:

g[j]:=plot(P(t),t=0..30):

od:

> display(seq(g[j],j=1..15),title="Logistic Growth",labels=[t,’P(t)’],

labelfont=[TIMES,ITALIC,12]);

with output given in Figure 15. It appears that starting with a positive initial pop-ulation leads to a population of 10 (for the values of the other parameters we haveused). Let’s see why.

4. Equilibrium Solutions and the Logistic Model

An equilibrium solution to a differential equation is a constant that solves theequation. If Peq is an equilibrium solution then for this solution we have

d

dt(Peq) = 0.

That means the right hand side of the differential equation is zero at an equilibriumsolution. For the Logistic equation,

aPeq (C0 − bPeq) = 0,

Page 61: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

4. EQUILIBRIUM SOLUTIONS AND THE LOGISTIC MODEL 49

Logistic Growth

2

4

6

8

10

12

14

P(t)

0 5 10 15 20 25 30

t

Figure 15. Logistic Solution – varying initial populations.

where Peq is the equilibrium solution. In this case we have two solutions to thequadratic equation in Peq, namely

Peq = 0, or Peq =C0

b.

The first equilibrium solution is the trivial solution. If you start with zero populationin a closed system (neither immigration nor emigration), then you always have zeropopulation. The second equilibrium solution is called the carrying capacity for thesystem. From the graphics we had above the behavior of these two equilibriumsolution is quite different.

In particular, the stability of these two solutions is different. Stability in this casemeans: if we start with initial conditions “close” to the equilibrium solution then doesthe solution stay close to the equilibrium solution? For the trivial solution the answerto this question is no, so we say that Peq = 0 is an unstable equilibrium solution.For the other equilibrium solution, small changes in initial condition do not changethe solution much, so this equilibrium solution is called stable. Mathematically we“prove” this as follows.

Consider the differential equation

dP

dt= f(P ),

where f is a differentiable function of P and that f (Peq) = 0 by our definition ofequilibrium. To analyze the stability of an equilibrium solution we add a “small”perturbation to the equilibrium solution and see what happens to the solution of thedifferential equation. Formally, we start by setting

P (t) = Peq + εp(t),

Page 62: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 3. POPULATION MODELS IN BIOLOGY 50

and take ε to be small: 0 < ε � 1 (read this as ε is much smaller than 1, but stillpositive). Next substitute the perturbed function into the differential equation. Thiswill give an equation of the form

d

dt(Peq + εp(t)) = f (Peq + εp(t)) .

The linearity of the derivative implies that

d

dt(Peq) + ε

d

dt(p(t)) = f (Peq + εp(t)) .

The first term on the left is zero since Peq is a constant. To simplify our notation,we write p instead of p(t). Next, expanding the right hand side in a Taylor seriescentered at Peq yields the infinite series

εdp

dt= f(Peq) +

[

df

dP(Peq)

]

εp +1

2

[

d2f

dP 2(Peq)

]

(εp)2 + . . .

The first term on the right is zero. If we divide by ε we obtain

dp

dt= f ′ (Peq) p + O(ε).

The O notation indicates that the remaining terms are of order ε. If we think of ε assmall then we have approximately

dp

dt= αp, where α =

df

dP(Peq).

Notice that α is a constant since it is a derivative evaluated at a number (the equi-librium Peq). We’ve already discussed the solutions to linear differential equationswith constant coefficients. This particular differential equation has, by inspection,the solution p(t) = p(0)eαt and there are three possible types of behavior that canoccur, which are summarized in Table IV.

Table IV. Possible Behavior ofdp

dt= αp.

Parameter Behaviorα < 0 the solution, p(t), will decay to zeroα = 0 the solution remains constant, p(t) = p(0)α > 0 the solution will grow rapidly away from zero

These behaviors tell us that the perturbed solution will in (1) decay to the equilib-rium solution (stable), (2) stay approximately the same distance from the equilibriumsolution (could be stable or unstable we can’t tell by this analysis), or in (3) moveaway from the equilibrium solution (unstable). Thus, to check the stability of anequilibrium solution we must look at the derivative of the right hand side evaluatedat the equilibrium. Let’s check the Logistic model.

First define the right hand side of the Logistic model as a function of P .

Page 63: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

5. LINEAR STABILITY EXAMPLE 51

> unassign(’a’);unassign(’b’);

> f:=P->a*P*(C[0]-b*P);

f := P− > aP (C0 − bP )

Next differentiate with respect to P .

> dfdP:=D(f);

dfdP := P− > a (C0 − bP ) − aPb

Then evaluate the derivative at the equilibrium solutions.

> dfdP(0);

aC0

> dfdP(C[0]/b);

−aC0

From this we can see that the zero solution is unstable (aC0 > 0), while the nontrivialsteady state solution is stable (−aC0 < 0).

Note: steady state solutions is another way of saying equilibrium solutions.

5. Linear Stability Example

In this example we will look at the stability of the steady-state solutions to

dx

dt= x2(1 − x)3.

First calculate the steady-states:

> f:=x->x^2*(1-x)^3;

> plot(f(x),x=-1..2,y=-.2..(.2),labels=[x,’f(x)’],

labelfont=[TIMES,ITALIC,12]);

f := x− > x2(1 − x)3

Based on the graph in Figure 16 (and some simple algebra) there are two equilibriumsolutions:

x = 0 and x = 1.

If we try the linear stability analysis on these solutions we find:

Page 64: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 3. POPULATION MODELS IN BIOLOGY 52

–0.2

–0.1

0

0.1

0.2

f(x)

–1 –0.5 0.5 1 1.5 2

x

Figure 16. Graph of f(x) = x2(1 − x)3.

> df:=D(f);

> df(0);

> df(1);

df := x− > 2x(1 − x)3 − 3x2(1 − x)2

0

0

Referring back to Table IV, we see that in both cases the linear stability analysis failsto provide any information about the stability of the steady-state solutions. However,

we can obtain information about stability from the graph of f(x) =dx

dt. Recall

from first semester Calculus, a positive first derivative implies that the function isincreasing whereas a negative derivative implies that the function is decreasing. Whenthe derivative is zero, then we have a horizontal tangent and we gain no informationabout increasing/decreasing. Consider Figure 16. When x < 0, f(x) > 0. Since f

really represents the first derivative of x(t), we know that x(t) is increasing. When0 < x < 1, clearly f(x) > 0 and hence x(t) is increasing. Finally, whenever x > 1, wesee that f(x) < 0 and hence x(t) is decreasing.

Recall from D.E. that solutions through a point are unique. Another way ofsaying that, is that two different solutions can not intersect. That is, in a state spacegraph, if a solution starts below an equilibrium solution, then it must stay below theequilibrium solution. If a solution starts above an equilibrium solution, then it muststay above the equilibrium solution.

So, in this example, if we have IC’s x(0) < 0, then the solution increases towards0, but can not cross the t-axis (x = 0). If we have IC’s between 0 and 1, then the

Page 65: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

6. MODELING THE CHEMOSTAT 53

solution will increase toward 1, but can not cross x = 1. If we start with IC’s greaterthan 1 then the solution will decrease towards 1, but will not cross x = 1. Put thatall together to conclude that x = 1 is a stable steady-state solution and x = 0 is asemi-stable (stable on one side) steady-state solution.

Next, graph several solutions to verify our analysis. In Figure 17, the horizontalaxis it time, t, and the vertical axis is x(t).

> with(plots):

> sols:=seq(dsolve({diff(x(t),t)=f(x(t)),x(0)=.2*j},type=numeric, output=listprocedure), j=-10..15):

> p:=Vector(26):

> for j from 1 to 26 do

xs:=subs(sols[j],x(t)):

p[j]:=plot(xs,0..20,color="Black"):

od:

> display(seq(p[j],j=1..26),labels=[t,’x(t)’],

> labelfont=[TIMES,ITALIC,12]);

–2

–1

0

1

2

3

x(t)

2 4 6 8 10 12 14 16 18 20

t

Figure 17. Graph of solutions with various initial conditions.

In conclusion, if solutions are increasing for values below the steady-state and de-creasing for values above the steady-state, then the steady-state is stable. Otherwise,the steady-state is not stable, but could be semi-stable (or stable on one side).

6. Modeling the Chemostat

An interesting population system to analyze is bacterial growth in a chemostat,or biological reactor. This is a system used in many labs, where it is necessary tomaintain a fresh culture of a desired bacteria. The idea is to supply a culture, orreaction tank, with a constant supply of fresh nutrient through an inlet valve. The

Page 66: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 3. POPULATION MODELS IN BIOLOGY 54

reactor is stirred constantly, and mixed effluent is tapped off at the same bulk rateas fluid is supplied from the nutrient tank. A mathematical model for this systemwas proposed by Segel (1984). As we discuss the chemostat model, please refer to thecompartmental diagram in Figure 18.

Nutrient Tank

Reactor Tank

C = 1

α1

N, C

Figure 18. Compartmental Diagram for the Chemostat.

Let N(t) be the relative population density of the bacteria in the reactor, and C(t)be the concentration of nutrient in the reactor. The relative population density is ameasure of the number of bacteria per unit volume in the chemostat. From a practicalpoint of view it would be impossible to count the total number of bacteria in the tank.Instead, we will estimate the density. Then an estimate of the total number of bacteriacan be computed based on the volume of the tank. The concentration of nutrient isrelative to the influent nutrient concentration. The influent concentration will benormalized to one. For example, if the concentration of nutrient in the chemostat is0.98, this implies that the concentration level is 98% of the concentration of nutrientbeing pumped into the system.

One example of a set of modeling equations describing the temporal dynamics ofthe process is given in equations (6.1) and (6.2).

dN

dt= f(N, C) = α2

C

1 + CN − N (6.1)

dC

dt= g(N, C) = −N

C

1 + C− C + α1 (6.2)

The negative linear term on the right-hand-side of equation (6.1) represents the lossof bacteria due to material being drained out of the chemostat. The negative termson the right-hand-side of equation (6.2) characterize the reduction in concentrationof the nutrient due to consumption by the bacteria and due to material being drainedoff the tank. The positive term in equation (6.1) reflects the increase in the bacteriadue to the nutrient being injected into the tank. The positive constant, α2, is the

Page 67: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

6. MODELING THE CHEMOSTAT 55

growth rate constant for the bacteria. The positive constant, α1, is the amount ofnutrient being added to the tank.

What do we want to determine about the physical system from the mathematicalmodel we are developing?

(1) Is there a way to maintain a certain density of bacteria that is useful for labexperiments?

(2) What parameter values will maintain a specified density of bacteria in thechemostat?

(3) In these types of equilibrium states, can we guarantee stability of the pro-cess? That is, if the system gets bumped or the concentration of the influentnutrient is perturbed slightly, will the equilibrium state be maintained?

The computations to answer these questions can be rather complicated to do byhand. Conceptually, we already have some idea of what we need to do to analyze themodel. For equilibrium states we need the derivatives to be zero and for stability weneed to look at the solution of the linearized, perturbed problem. We can use Maple

to do the calculations:First, define the right-hand-sides of the two equations in our system.

> f:=(N,C)->alpha[2]*C/(1+C)*N-N;

> g:=(N,C)-> -C/(1+C)*N-C+alpha[1];

f := (N, C)− >α2CN

1 + C− N

g := (N, C)− > − CN

1 + C− C + α1

Notice that alpha[2] is typeset by Maple as α2. Thus, Maple understands manyGreek letters and can do subscripts.

Note that f and g are functions of the two variables N and C. Next we want tofind equilibrium solutions by setting f and g to zero and solving for N and C.

> eqsols:=solve({f(N,C)=0,g(N,C)=0},[N,C]);

eqsols :=

[

[N = 0, C = α1],

[

N =α2(−1 + α1α2 − α1)

α2 − 1, C =

1

α2 − 1

]]

The first steady state is the trivial case where there are no bacteria and we arejust flushing nutrient through the system. If this steady state solution is stable thenwe will have a hard time raising bacteria. If it is unstable and the non-trivial steadystate is stable then we can introduce (or start with) a small sample of the bacteriaand over time the concentration of bacteria will grow to a much larger amount. Thissecond situation is the desired outcome.

There is more information that can be gleaned from the above results on steadystates. In order for the non-trivial steady state to be positive (i.e. make sense), wemust impose several restrictions.

Page 68: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 3. POPULATION MODELS IN BIOLOGY 56

In order for the solution

C =1

α2 − 1

to be positive, we must assume that

0 <1

α2 − 1=⇒ 1 < α2. (6.3)

For the equilibrium N to be positive, we note that

N =α2(−1 + α1α2 − α1)

α2 − 1,

implies

−1 + α1α2 − α1 > 0 =⇒ 1

α2 − 1< α1. (6.4)

To see this using Maple we do the following.

> solve(rhs(eqsols[2][1])=0,alpha[1]);

1

α2 − 1.

With a little algebraic logic we arrive at the condition mentioned above. Recall thatrhs returns the right hand side of expressions and eqsols[2][1] selects the firstequation of the second set of solutions. That is, eqsols[2][1] is equal to

N =α2(−1 + α1α2 − α1)

α2 − 1.

We also have that

α1α2 − α1 − 1 > 0

to insure that N is positive.So, given this condition we have a positive equilibria,

C =1

α2 − 1(6.5)

N =α2(−1 + α1α2 − α1)

α2 − 1. (6.6)

Now we are faced with a more difficult question: is this a stable steady state?To answer this we linearize the general solution about the steady state and examinesolutions to the linear equations as follows.

Page 69: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

6. MODELING THE CHEMOSTAT 57

6.1. Stability for the System of Ordinary Differential Equations. Firstsome notation. Let u be a vector whose components are N and C. That is

u =

[

N

C

]

.

Notice that since N and C are functions of time, u should be written as u(N(t), C(t)).For simplicity, we shall use u, u(t) or u(N, C), whichever seems clearer at the time.Let F (u) be the vector valued function whose components are the right-hand-sides ofthe system of differential equations. That is

F (u) =

[

f(N, C)g(N, C)

]

.

Then the system of differential equations can be represented in vector (matrix) formas

d

dt

[

N

C

]

=

[

f(N, C)g(N, C)

]

,

or the general system isdu

dt= F (u).

Now suppose that we have found an equilibrium solution, u0, of the general system.This means that

du

dt

u=u0

= ~0 = F (u0),

where ~0 =[

0 0]′

is the zero vector. For simplicity, we shall adopt the conventionthat

d

dtu0 =

d

dtu

u=u0

.

Now if we introduce a perturbation to the equilibrium solution of the form εv,where v is a vector function and 0 < ε � 1, then the perturbed vector would be

u = u0 + εv.

Substituting into the left-hand-side of the general system gives

d

dtu =

d

dt(u0 + εv) = ε

dv

dt,

sinced

dtu0 = 0.

Next we need to deal with the right-hand-side of the general solution. In the onedimensional analysis of the Logistic equation we used Taylor series expansion in theparameter ε about the equilibrium solution. An analogous procedure will be usedin the case of systems of ODE’s. In particular, we let the parameter ε vary and we

Page 70: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 3. POPULATION MODELS IN BIOLOGY 58

expand F (u0 + εv) about the point u0. The formal Taylor series can be found in acalculus textbook as

F (u0 + εv) = F (u0) + ε

df

dN

df

dCdg

dN

dg

dC

v + O(ε2).

Again, the term O(ε2) represents all terms in the Taylor series that are multipliedby at least a factor of ε2. Note that the matrix

J =

df

dN

df

dCdg

dN

dg

dC

is called the Jacobian matrix for the function F (u), and is the analogy of the derivativein the usual one dimensional Taylor series. At this point we will not focus on thederivative expansion above. We will assume that it is well defined and proceed to thenext step. The entries in the matrix are all evaluated at the equilibrium solution u0.We shall denote the Jacobian matrix evaluated at the equilibrium solution by J(u0).

Using a shorthand notation for the Taylor expansion in terms of the Jacobian wecan now write the general equation for the perturbed system as follows:

du

dt= ε

dv

dt= F (u0) + εJ(u0)v + O(ε2).

Barring notation this is virtually the same as the result we found in the onedimensional analysis. If we note that F (u0) = 0, divide through by ε and drop anyremaining term in ε (since 0 < ε � 1), then we have linearized the system and writeit in the following manner

dv

dt= J(u0)v.

Since the Jacobian has fixed entries, this is a constant coefficient, linear systemof ODE’s. Before we explore the issue of stability, let’s take a look at how one goesabout solving (in closed form) a system like this.

6.2. Solving Constant Coefficient Linear Systems of ODE’s. Before pro-ceeding, we need to recall some more linear algebra. We begin this discussion withthe fundamental definitions that lead to the formulation of a smallest set (a basis)which can be used to describe any element in a vector space.

The notion of “describing an element” is written down carefully in the followingdefinition.

Definition 19. Let S = {x1, x2, . . . , xn} be a set of vectors in a vector space, V .If for a non-zero v ∈ V , there exists scalars c1, c2, . . . , cn ∈ R such that

v = c1x1 + c2x2 + · · ·+ cnxn,

Page 71: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

6. MODELING THE CHEMOSTAT 59

then we say that v is a linear combinationof vectors in S. If every non-zero vector inV can be written as a linear combination of vectors from S, then we say that S spansV .

This next definition allows us to describe the amount of redundant informationfound inside a set of vectors.

Definition 20. Let c1, c2, . . . , cn ∈ R. A set of vectors {x1, x2, . . . , xn} in a vectorspace are linearly independent if

c1x1 + c2x2 + · · ·+ cnxn = 0

impliesc1 = c2 = · · · = cn = 0.

Otherwise the set of vectors is said to be linearly dependent.

Thus, an (linearly) independent set of vectors has no redundant information. If,however, they are dependent, then at least one of the vectors can be written in termsof the others.

Now we can precisely describe what is meant by describing a vector space with a“smallest set.”

Definition 21. A set of vectors {x1, x2, . . . , xn} in a vector space, V , is a basisfor V if it is a linearly independent spanning set. The dimension of V is the numberof elements in its basis.

Now, we really didn’t justify that the concept of dimension is well defined. Thatis, can you have two different bases for a vector space that have different sizes? Theanswer is no, you can’t.

The importance of bases is that, once chosen, all vectors can be written as a linearcombination in a unique way.

Theorem 5. If a basis is given for a vector space, then each vector in the spacehas a unique expression as a linear combination of elements in that basis.

Of course, this is not necessarily true for a spanning set that is not a basis. Thisnext theorem gives us the connection between invertible matrices and bases for Rn.

Theorem 6. The set of columns of any n× n invertible matrix is a basis for Rn.

Thus, Rn can have many different bases. The canonical basis or standard basis

for Rn is the one induced by the columns of In, the n × n identity matrix. Often,we’ll write this as

e1 =

100...0

, e2 =

010...0

, · · · , en =

000...1

where each vector is an element of Rn.

Page 72: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 3. POPULATION MODELS IN BIOLOGY 60

One important theorem states that every vector space has a basis. We’ve includeddefinitions for finite bases since we’ll be dealing with Rn, a finite dimensional vectorspace. However, these definitions can be extended to include infinite bases. In thiscase, we say that the dimension of the vector space is infinite.

Recall that an eigen pair (λ, µ) of a square matrix J is an eigenvalue, λ and aneigenvector µ satisfying the equation

Jµ = λµ.

The following theorem (and corollary) gives an easy condition for determining theindependence of a set of eigenvectors.

Theorem 7. Any set of eigenvectors corresponding to a distinct set of eigenvaluesare linearly independent.

This statement holds for both complex as well as real eigenvalues and eigenvec-tors. However, the following corollary gives us an immediate answer concerning theexistence of a basis of eigenvectors for Rn.

Corollary 1. If A is an n × n matrix with n distinct real eigenvalues, then theassociated eigenvectors are a basis for Rn.

Note that if there are repeated real roots, then further analysis of the eigenvectorsmust be performed.

Now, we return to the problem of solving constant coefficient linear systems ofODEs. For this analysis we will restrict ourselves to 2 by 2 systems. Suppose thatthe 2 by 2 matrix J has two distinct, real eigenvalues, λ1, λ2 and two correspondingeigenvectors µ1, µ2, then the eigenvectors can be used as a basis for R2. Therefore,any two dimensional vector can be written as a linear combination of the eigenvectors.

Thus, we can writev(t) = v1(t)µ1 + v2(t)µ2,

for any perturbation vector v whose derivative is given by

dv

dt=

dv1

dtµ1 +

dv2

dtµ2.

In terms of the linearized systemdv

dt= Jv,

we havedv1

dtµ1 +

dv2

dtµ2 = J(v1µ1 + v2µ2) = λ1v1µ1 + λ2v2µ2,

where we have used the fact that (µi, λi) are an eigenpair for J ; that is they satisfythe equation

Jµi = λiµi, i = 1, 2.

Since the eigenvectors are linearly independent, we can “decouple” the equationsalong the directions of the eigenvectors. That is, we get two, one dimensional linearODE’s

dv1

dt= λ1v1 and

dv2

dt= λ2v2.

Page 73: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

6. MODELING THE CHEMOSTAT 61

Solving each of these equations separately, we obtain

v1(t) = c1eλ1t and v2(t) = c2d

λ2t,

where c1 and c2 are arbitrary constants. Then the solution to the linearized systemis the linear combination of the two solutions above with the associated eigenvectors,that is

v(t) = v1(t)µ1 + v2(t)µ2 = c1eλ1tµ1 + c2e

λ2tµ2.

Now, suppose that we have two complex eigenvalues, λ1, λ2 and their associatedeigenvectors µ1, µ2. We know that the eigenvectors are linearly independent, but theywon’t form a basis for R2 since they have imaginary components. However, due toindependence, we can perform the same basic steps above, “decouple” the system andobtain two solutions of the form

v1(t) = k1eλ1t and v2(t) = k2d

λ2t,

where k1 and k2 are arbitrary constants.We could write the general solution as a linear combination of the two above

solutions. However, it is not too hard to write them using sines and cosines. So, firstwe recall Euler’s formula

eiθt = cos(θt) + i sin(θt).

Suppose that λ1 = a + bi. Then λ2 = a − bi. Now, notice that

v1(t) = eλ1t = e(a+bi)t = eatebit = eat[cos(bt) + i sin(bt)].

Similarly,v2(t) = eλ2t = eat[cos(bt) − i sin(bt)].

Therefore, the complete solution can be written as follows

v(t) = k1v1(t) + k2v2(t)

= k1eat[cos(bt) + i sin(bt)] + k2e

at[cos(bt) − i sin(bt)]

= eat[c1 cos(bt) + ic2 sin(bt)],

where c1 = k1 +k2 and c2 = k1−k2 are constants. Typically, we would use any initialconditions to determine c1 and c2 directly, instead of trying to find k1 and k2 first.

Finally, let’s suppose that λ = λ1 = λ2. If we obtain two linearly independenteigenvectors, µ1, µ2, then we can write the solution as

v(t) = µ1eλ1t + µ2e

λ2t = eλt(µ1 + µ2).

Unfortunately, it is not always the case that there are two linearly independenteigenvectors associated with λ. For this case we need to learn about generalizedeigenvectors. In order to find two linearly independent (generlized) eigenvectors, firstfind a non zero solution to the equation

(J − λI)2µ2 = 0.

Note that there could be many choices for µ2. Pick one. Next, use µ2 to find anotherindependent generalized eigenvector by solving the equation

(J − λI)µ2 = µ1

Page 74: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 3. POPULATION MODELS IN BIOLOGY 62

such that µ1 6= 0. Two independent solutions are given by

v1(t) = µ1eλt and v2(t) = (µ1t + µ2)e

λt.

Hence, the general solution to the system is given by

v(t) = c1v(t) + c2v(t)

= c1µ1eλt + c2(µ1t + µ2)e

λt

= eλt[(c1 + c2t)µ1 + c2µ2],

where c1 and c2 are arbitrary constants.The nice thing about this theory is that it all extends to Rn when n > 2. Thus,

if you have (possibly repeated or complex) eigenvalues λ1, . . . , λ2 with associated(perhaps generalized) independent eigenvectors µ1, . . . , µn, then the general solutionto the matrix differential equation

dx

dt= Jx

is given by the compact equation

v(t) = µ1eλ1t + · · · + µne

λnt.

However, be careful when dealing with generalized eigenvectors. Things get excitingwhen dealing with complex repeated eigenvalues. We recommend that you refer tothe literature such as [4].

One final theorem in this section which states conditions that force the solutionv(t) to zero as t → ∞.

Theorem 8. Let v(t) = µ1eλ1t + · · ·+µne

λnt where λ1, . . . , λn are the eigenvaluesfor the Jacobian matrix J . If all eigenvalues are negative or have negative real parts,then lim

t→∞v(t) = 0.

6.3. Stability of the System of ODE’s. Now that we have the solution tothe linearized problem we can investigate the stability of the chemostat problem. Inorder to guarantee stability we must have v(t) shrink to the zero vector. This willonly occur if both eigenvalues of J are negative (or at least have negative real part).

We need a few more tools from Linear Algebra so that we can compute eigenvalues.

Definition 22. If A = [aij] is a square n × n matrix, then the trace of A is thesum of the diagonal elements. That is,

trace(A) =

n∑

i=1

aii.

Definition 23. The determinant of a n × n matrix is a function satisfying thefollowing three properties,

(1) The determinant of a triangular matrix is the product of its diagonal ele-ments.

Page 75: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

6. MODELING THE CHEMOSTAT 63

(2) If a matrix B results from a matrix A by adding a multiple of one row ontoanother row, then det(B) = det(A).

(3) If the matrix B results from a matrix A by multiplying one row of A by aconstant c, then det(B) = c det(A).

This definition doesn’t guarantee the existence of a unique function. It is easy toshow that there is a unique function satisfying these three properties. The interestedparty should see [2] for justification.

Theorem 9. If the square matrix B results from A by interchanging two rows,then det(B) = − det(A).

Finally, it can be shown from the above properties that the determinant of any

2 × 2 matrix A =

(

a b

c d

)

,

det(A) = ad − bc.

Now, we define the characteristic polynomial. This polynomial is important be-cause it’s roots are the eigenvalues we seek.

Definition 24. The characteristic polynomial of a square matrix A is

p(λ) = det(A − λI)

where I is the appropriately sized identity matrix.

At this point we can proceed in one of two ways. The first is to compute theeigenvalues directly from the matrix J . The other is to use some properties of matricesand the characteristic polynomials of 2 by 2 matrices to find the relevant informationabout the eigenvalues. Consider a general 2 by 2 matrix.

> with(LinearAlgebra):

> A := Matrix([[a, b], [c, d]]);

Maple gives the output

A :=

[

a b

c d

]

In Maple we can use the CharacteristicPolynomial command to obtain thecharacteristic polynomial.

> p := CharacteristicPolynomial(A, lambda);

Thus, we have

p := λ2 − λd − aλ + ad − bc.

Note that when simplified the characteristic polynomial is

p(λ) = λ2 − (a + d)λ + ad − bc.

The eigenvalues are the roots of this polynomial. If we knew the eigenvalues thenwe could write p(λ) in factored form as

p(λ) = (λ − λ1)(λ − λ2).

Page 76: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 3. POPULATION MODELS IN BIOLOGY 64

Multiplying out this expression gives

p(λ) = λ2 − (λ1 + λ2)λ + λ1λ2.

Comparing this result with the characteristic polynomial above gives two conditionson the eigenvalues:

a + d = λ1 + λ2 and ad − bc = λ1λ2.

Notice that the trace of the matrix A is given by

trace(A) = a + d

and the determinant of A isdet(A) = ad − bc.

For the 2 by 2 matrix A, the Maple commands Trace and Determinant give usthe left-hand-sides of the above expressions. Equating, we obtain the conditions forstability

trace(A) = λ1 + λ2 and det(A) = λ1λ2.

Recall that for stability, both eigenvalues (or the real part of both eigenvalues) mustbe negative. We have two cases to consider here. Suppose that λ1, λ2 are real andnegative. Clearly the trace is negative and the determinant is positive. Conversely,suppose that the trace is negative and the determinant is positive. Since det(A) =λ1λ2 > 0, then both eigenvalues have the same sign. However, since the trace isnegative, both eigenvalues are negative.

If λ1, λ2 are complex with negative real parts, then they must be complex conju-gates. Thus, λ1 = a + bi and λ2 = a− bi for a, b ∈ R. Note that trace(A) = 2a < 0 ifand only if Re(λ1) = Re(λ2) = a < 0. For this case, note that

det(A) = λ1λ2 = (a + bi)(a − bi) = a2 + b2 > 0

is always true. Thus, for pairs of complex eigenvalues, it is not necessary to check thedeterminant only the trace.

We’ve now verified the following theorem.

Theorem 10. For any 2 × 2 matrix A, trace(A) < 0 and det(A) > 0 if and onlyif the associated eigenvalues are negative or have negative real parts.

6.4. Stability of the Chemostat. In the chemostat problem the Jacobian ma-trix can be found using Maple as follows

> jacm:=Matrix([[diff(f(N,C),N),diff(f(N,C),C)],

[diff(g(N,C),N),diff(g(N,C),C)]]);

jacm :=

α2C

1 + C− 1

α2N

1 + C− α2CN

(1 + C)2

− C

1 + C− N

1 + C+

CN

(1 + C)2− 1

The determinate and trace of this matrix are

Page 77: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

6. MODELING THE CHEMOSTAT 65

> tracejacm:=simplify(Trace(jacm));

> detjacm:=simplify(Determinant(jacm));

tracejacm :=α2C + α2C

2 − 2 − 4C − 2C2 − N

(1 + C)2

detjacm := −α2C2 − C2 − 2C + α2C − N − 1

(1 + C)2

Notice that the determinant evaluated at the trivial equilibrium (0, α1) is givenby

> simplify(subs([N = 0, C = alpha[1]], detjacm));

−−1 + α1α2 − α1

α1 + 1.

Recall from inequality (6.4), that −1 + α1α2 − α1 > 0. Hence, the determinant atthis equilibrium is negative. Thus, this equilibrium is always unstable.

Recall that the nontrivial equilibrium is given respectively by equations (6.6) and(6.5),

N =α2(−1 + α1α2 − α1)

α2 − 1, C =

1

α2 − 1.

We evaluate the trace and determinant of the Jacobian matrix at this equilibrium asfollows:

> traceateq:=simplify(subs(eqsols[2],tracejacm));

> detateq:=simplify(subs(eqsols[2],detjacm));

traceateq := −1 + α1α22 − 2α1α2 + α1

α2

detateq :=(−1 + α1α2 − α1)(α2 − 1)

α2

Recall from inequalities (6.3) and (6.4) that α2 > 1 and −1 + α1α2 − α1 > 0 inorder to have N and C positive. Thus the determinate of the Jacobian is positive.So now we only need to know what parameter values make the trace of the Jacobiannegative. If we rearrange the trace we obtain

trace(J) = −1 + α1(α2 − 1)2

α2.

Based on the allowable values of the parameters this trace is clearly negative. Thusthe non-trivial steady state solution to the chemostat problem is stable.

Page 78: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 3. POPULATION MODELS IN BIOLOGY 66

6.5. Solutions to the Chemostat Problem. Now lets solve the chemostatproblem. First pick values for α1 and α2. Ordinarily, these values would dependon the types of bacteria and nutrient used, but we will just assign arbitrary values(keeping in mind the restrictions from above).

> alpha[1]:=3; alpha[2]:=2;

α1 := 3

α2 := 2

Next let’s build a “function” that allows us to solve the system with differentinitial conditions.

> chemo:=(n0,c0)->

dsolve({diff(N(t),t)=f(N(t),C(t)),diff(C(t),t)=g(N(t),C(t)),N(0)=n0,C(0)=c0},{N(t),C(t)},type=numeric,output=listprocedure);

chemo := (n0, c0)− > dsolve

({

d

dtN(t) = f(N(t), C(t)),

d

dtC(t) = g(N(t), C(t)),

C(0) = c0, N(0) = n0

}

, {N(t), C(t)}, type = numeric, output = listprocedure

)

Lets test this with initial conditions (.1,.1).

> sols1:=chemo(.1,.1);

sols1 := [t = proc(t)...end proc; , C(t) = proc(t)...end proc; ,

N(t) = proc(t)...end proc; ]

> ns:=subs(sols1,N(t)); cs:=subs(sols1,C(t));

ns := proc(t)...end proc;

cs := proc(t)...end proc;

Next, we plot the solutions from 0 ≤ t ≤ 20.

> plot([cs,ns,0..20],labels=["C(t)","N(t)"]);

See Figure 19 for the graph of the solutions at these particular parameter values.Recall that this is a phase space plot. For the values of the parameters and initial

conditions used we see that first the concentration of the nutrient increases with little

Page 79: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

7. EXERCISES 67

C(t)0.5 1.0 1.5 2.0 2.5

N(t)

1

2

3

4

Figure 19. Plot of N(t) vs C(t) with initial conditions (.1, .1).

change in the concentration of the bacteria. When the concentration of nutrientreaches 2-2.5, the concentration of bacteria starts to increase. Then as the numberof bacteria increase, the concentration of nutrient decreases. The system reaches anequilibrium at about (1,4).

If we wanted to graph the solutions using several initial conditions, we could dothe following.

> gr:=Vector(16);

> for j from 1 to 16 do

sols:=chemo(.5*j,.5*j);

ns:=subs(sols,N(t)); cs:=subs(sols,C(t));

gr[j]:=plot([cs,ns,0..20]):

od:

> with(plots):

> eqgr:=plot([[1,4]],style=point,symbol=circle,color="Black"):

> display(eqgr,seq(gr[j],j=1..16),labels=["C(t)","N(t)"]);

See Figure 20 for the graph of the solutions at these particular parameter values.

7. Exercises

3.1 For the general system

dx

dt= f(x)

we have learned to start a qualitative analysis by determining the location ofthe equilibrium solutions and the stability of the equilibrium solutions. Foreach of the cases below, determine the equilibrium solutions and the stabilitycharacteristics of the equilibrium solutions. In some cases, there will be in-finitely many equilibria. In these cases, characterize the first few equilibrium

Page 80: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 3. POPULATION MODELS IN BIOLOGY 68

C(t)1 2 3 4 5 6 7 8

N(t)

2

4

6

8

10

12

Figure 20. Plot of N(t) vs C(t) with initial conditions(.5, .5), (1, 1), (1.5, 1.5), . . . , (8, 8).

solutions closest to the origin, x = 0. Some hints: (1) It may not be alge-braically possible to compute solutions. So, you might have to consider set-tling for approximations. In these cases, consider using solve and/or fsolvecommands to find the equilibrium solutions. (2) To analyze the stability youcan compute the derivatives using the D command in Maple . (3) Recall thatif the derivative is zero at an equilibrium solution we cannot tell about thestability of the equilibrium solution. That is, we would say the stability is stillindeterminate. See problem 2 and 3.A dx

dt= x3(x − 1)(x + 1).

B dxdt

= sin(x).

C dxdt

= ex − cos(x).

D dxdt

= tan(x) − x.

E dxdt

= x tan(x).3.2 For this problem we will consider the differential equation

dx

dt= x2

(

1 − x2)

.

Perform the following steps towards analyzing the stability of equilibrium so-lutions.A Graph the right hand side as a means of visually identifying the locations

of the equilibrium solutions (i.e. right hand side equals zero).B Use the derivative test to ascertain the stability of the two non-trivial

equilibrium solutions. In addition, show that the test does not tell usanything about the stability of the equilibrium solution x = 0.

Page 81: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

7. EXERCISES 69

C Now use the graph of the function to determine the stability of the solutionx = 0. To understand this, consider what happens when dx

dt> 0, and

dxdt

< 0. In the first case x must be increasing and in the second case,x must be decreasing. If x is increasing to the left of an equilibriumsolution and x is decreasing to the right of the same equilibrium solution,then the equilibrium solution must be stable. If the opposite occurs, theequilibrium must be unstable.

3.3 Repeat problem 2 for the system defined in problem 1a.3.4 In a model for the barred tiger salamanders, Ambystoma tigrinum mavortium,

the adults are modeled as the following differential equation,

dA

dt= −rA + bφ(A)A,

where r and b are positive parameters for the model. The parameter r is thedeath rate of tiger salamanders due to environmental conditions and predation.The parameter b indicates the proportion of eggs that survive to become adultsalamanders in ideal conditions. Since conditions in nature are rarely ideal,we assume that birth is a density dependent function. The function φ(A)models the density dependence and is assumed to be a non-negative functionwith φ(0) = 1. An additional restriction is φ(A) is strictly decreasing (orφ(A) ≡ 1), so that the inverse of φ(A) exists. Thus bφ(A) is the proportion ofeggs that survive to become an adult tiger salamander when in the presenceof other salamanders and limited resources such as food.A Assume that φ(A) ≡ 1. Determine the stability of the equilibria.B Assume that φ(A) = 1

1+cA, where c > 0 is constant. Determine the

stability of the equilibria.C Assume that φ(A) = e−cA, where c > 0 is constant. Determine the

stability of the equilibria.3.5 Beddington and May (1982) proposes a model to describe the interaction be-

tween baleen whales and krill. Krill are the primary food resource for baleenwhales which means the whales are the predators in the system and the krill arethe prey in the system. Let’s let y(t) denote the population density of baleenwhales and x(t) denote the population density of krill. The model proposedwas defined by the following system of ordinary differential equations.

dx

dt= rx

(

1 − x

k

)

− axy

x + ddy

dt= sy

(

1 − y

bx

)

,

where a, b, d, r, s, and K are parameters of the system that depend on thecharacteristics of the whales and krill. The parameters r and s are reproductionrates. K is a carrying capacity for the krill. The parameter b is a relativecarrying capacity for the whales given x number of krill. Parameters a and d

Page 82: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 3. POPULATION MODELS IN BIOLOGY 70

are constants that describe the predation of the whales on the krill. Finally, x

and y are densities which might have values of tons per square mile of ocean?Answer the following questions:

A Determine all potential steady states (equilibrium solutions) of the systemusing Maple. Discuss the solutions in terms of the real system.

B Determine the stability of all steady states for the system. Be sure to usethe simplify command to reduce your answers.

C Discuss the qualitative behavior of the system, using phase space plotswhere appropriate.

Note: Parts of this problem will require a little extra thought. You will haveto make assumptions about parameter values (maybe in order to guaranteestability). The steps you will follow should be similar to the ones used in thechemostat problem. Good luck and tally-ho!

Page 83: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 4

Lists

As always, it is a good idea to issue the restart command if you’ve done otherwork during the same session. Throughout this chapter, we will assume that you’veincluded the with(plots) command.

1. Lists in Maple

Definition 25. A list is an ordered collection of objects. The objects are alsocalled elements of the list.

A list is quite similar to the notion of a set. The only difference is that sets areunordered collections of objects. For those familiar with programming, you can thinkof a list as an vector or array of objects.

It is relatively simple to enter a list into Maple. For example we may have a dataset of the form:

> list1:=[[-1.0,0.5],[-0.65,1.1],[-0.1,0.75],[0.4,0.3],[1.0,-0.2]];

which generates output

[[−1.0, 0.5], [−0.65, 1.1], [−0.1, 0.75], [0.4, 0.3], [1.0,−0.2]]

This defines a list of ordered pairs. The list of ordered pairs can be thought ofas a list of lists: a list whose elements are simple, two-member lists. The bracketsaround the ordered pairs are recognized as a list in the software.

Let’s graph this list of ordered pairs. To graph a list of points we use the plot

command in the following way:

> plot(list1,x=-1.5..1.5,y=-0.5..1.5,color="Black");

This generates Figure 21(A). Note that we’ve specified the ranges for x and y axes,which is a convenience that allows us to more easily view the edges of the plot.

The default in the plot command is to join the points with line segments. If wewanted to see just the points we could include a style=point option. You’ve seenthis before when you studied differential equations. Refer to Table 2 in Chapter 2 formore options.

> plot(list1,x=-1.5..1.5,y=-0.5..1.5,style=point);

This generates Figure 21(B).The default point symbol is a point (or small circle). From Table 2 or Maple’s

help, we see that the other symbols that we can use are asterisk, box, circle, cross,diagonalcross, diamond, point, solidbox, solidcircle, soliddiamond. A partial list of

71

Page 84: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 4. LISTS 72

xK1.5 K1.0 K0.5 0 0.5 1.0 1.5

y

K0.5

0.5

1.0

1.5

21(A) Plot of the list list1.

xK1.5 K1.0 K0.5 0 0.5 1.0 1.5

y

K0.5

0.5

1.0

1.5

21(B) Plot of the list list1 using style=point.

xK1.5 K1.0 K0.5 0 0.5 1.0 1.5

y

K0.5

0.5

1.0

1.5

21(C) Plot of the list list1 usingstyle=boxand color=”Green”.

Figure 21. Plot of the list list1 using style=s and color=”C”.

colors found in Table 2 include Black, Blue, Brown, Gold, Gray, Green, Orange,Pink, Purple, Red, Silver, Tan, Violet, White, Yellow. See Maple help for a full listof colors. Recall that these colors are entered with double quotes. If we wanted thepoints to be plotted as green boxes we would do the following:

> plot(list1,x=-1.5..1.5,y=-0.5..1.5,style=point,symbol=box,

color="Green");

See Figure 21(C).In the above list we have distinct points forming a function. That is, the x

coordinate of each point is unique in the list. Suppose we have date taken from severalrepetitions of performing the same experiment. For instance, let’s say we performsome experiment twice and collect date at the same x values for both experiments,say as follows:

> list2:=[[[-1.0,0.5],[-0.65,1.1],[-0.1,0.75],[0.4,0.3],[1.0,-0.2]],

[[-1.0,0.5],[-0.65,1.03],[-0.1,0.74],[0.4,0.25],[1.0,-0.25]]];

Page 85: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

1. LISTS IN MAPLE 73

Maple generates the following output.

[[[−1.0, 0.5], [−0.65, 1.1], [−0.1, 0.75], [0.4, 0.3], [1.0,−0.2]],

[[−1.0, 0.5], [−0.65, 1.03], [−0.1, 0.74], [0.4, 0.25], [1.0,−0.25]]]

In this case we have a list of lists of lists, or a list of two lists of ordered pairs.We could look at the two lists of ordered pairs individually by taking a subset of themain list using the following command

> L1 := list2[1];

L1 := [[−1.0, 0.5], [−0.65, 1.1], [−0.1, 0.75], [0.4, 0.3], [1.0,−0.2]]

and

> L2 := list2[2];

L2 := [[−1.0, 0.5], [−0.65, 1.03], [−0.1, 0.74], [0.4, 0.25], [1.0,−0.25]]

If we wanted the x coordinate of the third point in the second list we would do

> list2[2][3][1];

or simply use the second list which we saved in L2 and request the first coordinate(typically x) of the third ordered pair.

> L2[3][1];

Both of the above commands generate the output

−0.1

If we wanted to graph both list simultaneously we would do the following:

> p1:=plot(list2[1],x=-1.5..1.5,y=-0.5..1.5,style=point,

symbol=circle,color="Red"):

> p2:=plot(list2[2],x=-1.5..1.5,y=-0.5..1.5,style=point,

symbol=circle,color="Red"):

> display(p1,p2);

Again, an equivalent sequence of statements would be

> p1:=plot(L1,x=-1.5..1.5,y=-0.5..1.5,style=point,symbol=circle,

color="Red"):

> p2:=plot(L2,x=-1.5..1.5,y=-0.5..1.5,style=point,symbol=circle,

color="Red"):

> display(p1,p2);

In either case, we obtain Figure 22(A).Here it is hard to tell which point belongs to which list. We could use different

colors. See Figure 22(B).

Page 86: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 4. LISTS 74

> p1:=plot(list2[1],x=-1.5..1.5,y=-0.5..1.5,style=point,

symbol=circle,color="Red"):

> p2:=plot(list2[2],x=-1.5..1.5,y=-0.5..1.5,style=point,

symbol=circle,color="Blue"):

> display(p1,p2);

That helps some, but what if you need to print it out in black and white? Wecould use different symbols. See Figure 22(C).

> p1:=plot(list2[1],x=-1.5..1.5,y=-0.5..1.5,style=point,symbol=circle,

color="Red"):

> p2:=plot(list2[2],x=-1.5..1.5,y=-0.5..1.5,style=point,symbol=cross,

color="Red"):

> display(p1,p2);

We still have problems with some of the points. In this case it might be better toplay connect the dots. See Figure 22(D).

> p1:=plot(list2[1],x=-1.5..1.5,y=-0.5..1.5,color="Red"):

> p2:=plot(list2[2],x=-1.5..1.5,y=-0.5..1.5,color="Blue"):

> display(p1,p2);

Note that we also used different colors for the lines, but that even with black andwhite we could determine that two sets of data are plotted. If we wish to combinethe two sets of data into one list we could do the following:

> list3:=[list2[1][],list2[2][]];

This generates the new list as shown below.

list3 := [[−1.0, 0.5], [−0.65, 1.1], [−0.1, 0.75], [0.4, 0.3], [1.0,−0.2],

[−1.0, 0.5], [−0.65, 1.03], [−0.1, 0.74], [0.4, 0.25], [1.0,−0.25]]

Note that if we graph this new list we obtain:

> plot(list3,x=-1.5..1.5,y=-0.5..1.5);

This plot is shown in Figure 23(A). In the first graph the individual points were joinedby straight line segments, while in the second the individual points were graphedwithout the connecting line segments. The command for this is shown below and it’soutput appears in Figure 23(B).

> plot(list3,x=-1.5..1.5,y=-0.5..1.5,style=point,symbol=circle,

color="Blue");

We can also pull out the x and y coordinates of the data points. To see the valuesof a Maple variable, simply enter it on the command line. For instance on list1 wehave:

> list1;

returns the list of five points in list1.

[[−1.0, 0.5], [−0.65, 1.1], [−0.1, 0.75], [0.4, 0.3], [1.0,−0.2]]

Page 87: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

1. LISTS IN MAPLE 75

xK1.5 K1.0 K0.5 0 0.5 1.0 1.5

y

K0.5

0.5

1.0

1.5

22(A) Plot of the list list2.

xK1.5 K1.0 K0.5 0 0.5 1.0 1.5

y

K0.5

0.5

1.0

1.5

22(B) Plot of the list list2 using red and bluecircles.

xK1.5 K1.0 K0.5 0 0.5 1.0 1.5

y

K0.5

0.5

1.0

1.5

22(C) Plot of the list list2 using the circleand plus symbols.

xK1.5 K1.0 K0.5 0 0.5 1.0 1.5

y

K0.5

0.5

1.0

1.5

22(D) Plot of the list list2 connecting thepoints with lines.

Figure 22. Plot of the list list2 using various style=s and color=”C” options.

xK1.5 K1.0 K0.5 0 0.5 1.0 1.5

y

K0.5

0.5

1.0

1.5

23(A) Plot of the list list3.

xK1.5 K1.0 K0.5 0 0.5 1.0 1.5

y

K0.5

0.5

1.0

1.5

23(B) Plot of the list list3 using blue circles.

Figure 23. Plots of the list list3.

We specify the range of values 1 . . . 5 to choose all five data points.

Page 88: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 4. LISTS 76

> xvals:=list1[1..5,1];

> yvals:=list1[1..5,2];

xvals := [−1.0,−0.65,−0.1, 0.4, 1.0]

yvals := [0.5, 1.1, 0.75, 0.3,−0.2]

2. Data at Distinct Points and Interpolating Polynomials

To start, consider interpolation of the input data. Interpolation is when you builda function whose graph passes through all data points. Because interpolation is donewith functions the data must represent a function. In the above examples, list1 is afunction while list3 is not. This is true because the x coordinates are repeated withvarying y coordinates in list3.

Suppose that a set of data consisting of n points comes from some function, f ,and we wish to define an interpolating function, g, for that data. That is, the datahas the form (xi, f(xi)) and we want to define g(x) such that

g(xi) = f(xi), for i = 1, . . . , n.

So the interpolating function must have the same values as the original functionat the data points. There are many ways of defining interpolating functions. In fact,one could define g just to be the piecewise linear function connecting each data point,like the joined graphs above. The problem with this approach is that piecewise linearfunctions usually are not differentiable at the joints. If the data comes from a smoothprocess, then we should probably keep the interpolating function differentiable. Sincewe want differentiability (maybe), we can try to use polynomials to interpolate thedata. That is, let pn−1(x) be a polynomial of degree n − 1. Then p has n degrees offreedom (n coefficients). Thus, we can find the coefficients that satisfy

pn−1(xi) = f(xi),

where 0 < i <= n.

Theorem 11. If x1, x2, . . . , xn are distinct real numbers, then for arbitrary valuesf(x1), f(x2), . . . , f(xn), there is a unique polynomial, pn−1, of degree at most n − 1such that pn−1(xi) = f(xi) for i = 1, 2, . . . , n.

The proof of this theorem is constructive. That is, the proof gives a method forfinding the coefficients. Lagrange interpolating polynomial is one method of generatingsuch a polynomial. For others, see, for example, [5].

Definition 26. Suppose x1, x2, . . . , xn are distinct real numbers. The cardinalfunctions have the form

li(x) =

n∏

j=1

j 6=i

x − xj

xi − xj, where 1 ≤ i ≤ n.

Page 89: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

2. DATA AT DISTINCT POINTS AND INTERPOLATING POLYNOMIALS77

We use cardinal functions to define the Lagrange interpolating polynomial.

Definition 27. Let x1, x2, . . . , xn be distinct real numbers and for arbitrarilydefined numbers f(x1), f(x2), . . . , f(xn), the Lagrange interpolating polynomial is de-fined to be

g(x) =

n∑

i=1

f(xi)li(x).

What has happened here is that we have defined separate n−1 degree polynomials(the li(x)), which are zero at all of the data points except the ith data point, wherethey are one. The sum of all these polynomials, weighted with the correct value of f

at xi, gives us a polynomial of the correct degree with the precisely desired value ateach xi.

We can have Maple generate Lagrange interpolating polynomials as follows. Letxi and f(xi) be the data from one of our five data point lists above, then

> ndat:=5;

> xd:=[seq(xdat[k], k = 1 .. ndat)];

> yd:=[seq(ydat[k], k = 1 .. ndat)];

> l:=Vector(ndat);

ndat := 5

xd := [xdat1, xdat2, xdat3, xdat4, xdat5]

yd := [ydat1, ydat2, ydat3, ydat4, ydat5]

l :=

00000

The Maple command product performs repeated symbolic multiplications. The gen-eral form of the command is product(a[i],i=m..n) which would form the product

n∏

i=m

= amam+1 · · ·an.

We use the command to create the cardinal products, l1(x), . . . , lndat(x). (Remember,ndat = 5 in this example.)

> for i from 1 to ndat do

l[i]:=product((x-xd[j])/(xd[i]-xd[j]),j=1..i-1) *

product((x-xd[j])/(xd[i]-xd[j]),j=i+1..ndat):

od:

Page 90: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 4. LISTS 78

Before we move on, notice that our for loop is indexed from 1 to ndat. However,the product statements run from j = 1..i−1 and j = i+1..ndat. When i = 1, the firstproduct statement is indexed from j = 1..0, which causes Maple to automaticallyreturn a 1 because the beginning value of the range is equals one plus the ending.Thus, the first polynomial is based solely on the second product statement runningfrom j = 2..ndat. Similarly, when i = ndat, the second product statement evaluatesto 1 because i + 1 = ndat + 1.

Let’s see what some of these cardinal functions looks like:

> l[1]; l[3]; l[ndat];

(x − xdat2)(x − xdat3)(x − xdat4)(x − xdat5)

(xdat1 − xdat2)(xdat1 − xdat3)(xdat1 − xdat4)(xdat1 − xdat5)

(x − xdat1)(x − xdat2)(x − xdat4)(x − xdat5)

(xdat3 − xdat1)(xdat3 − xdat2)(xdat3 − xdat4)(xdat3 − xdat5)

(x − xdat1)(x − xdat2)(x − xdat3)(x − xdat4)

(xdat5 − xdat1)(xdat5 − xdat2)(xdat5 − xdat3)(xdat5 − xdat4)

Now, let’s evaluate some of these polynomials at various points. Since we didn’tdefine true functions, we must use the subs command.

> simplify(subs(x = xd[1], l[3]));

> simplify(subs(x = xd[3], l[3]));

0

1

Note that the simplify command is used to “clean up” the Maple output.Before we continue, it is worth noting that sum is not a very well behaved proce-

dure. For example, if you issue the command

> sum(i,i=1..50);

Maple will respond with the error message “Error, (in sum) summation variablepreviously assigned, second argument evaluates to 6 = 1 .. 50” because the variablei is already assigned a value (6) from previously executed code.

The procedure sum also has some issues with vectors.

> sum(l[bob], bob = 1..ndat);

Maple responds with the error “Error, bad index into Vector.” This occurs becauseMaple tries to evaluate l[bob] before the variable bob is defined. So, you need to useunevaluation quotes

> sum(’i’, ’i’=1..50);

to obtain the correct sum 1275. You need to use the unevaluation quotes on thevector. Try the command

> sum(’l[bob]’, bob = 1..ndat);

Page 91: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

2. DATA AT DISTINCT POINTS AND INTERPOLATING POLYNOMIALS79

We’ll see the output later. Of course, we can have a “double whammy” effect bytrying to execute the code

> sum(l[i], i = 1..ndat);

If we wish to avoid this nonsense of having to use unevaluation quotes, then wecan use the procedure add. Executing the command

> add(l[i], i = 1..ndat);

works (try it!) without the hassle of quotes. Also, the add command resides in theMaple kernel, so it may execute faster in some cases that sum.

Now, we can form the interpolating polynomial of degree 4:

> g:=add(yd[k]*l[k],k=1..ndat);

g :=ydat1(x − xdat2)(x − xdat3)(x − xdat4)(x − xdat5)

(xdat1 − xdat2)(xdat1 − xdat3)(xdat1 − xdat4)(xdat1 − xdat5)

+ydat2(x − xdat1)(x − xdat3)(x − xdat4)(x − xdat5)

(xdat2 − xdat1)(xdat2 − xdat3)(xdat2 − xdat4)(xdat2 − xdat5)

+ydat3(x − xdat1)(x − xdat2)(x − xdat4)(x − xdat5)

(xdat3 − xdat1)(xdat3 − xdat2)(xdat3 − xdat4)(xdat3 − xdat5)

+ydat4(x − xdat1)(x − xdat2)(x − xdat3)(x − xdat5)

(xdat4 − xdat1)(xdat4 − xdat2)(xdat4 − xdat3)(xdat4 − xdat5)

+ydat5(x − xdat1)(x − xdat2)(x − xdat3)(x − xdat4)

(xdat5 − xdat1)(xdat5 − xdat2)(xdat5 − xdat3)(xdat5 − xdat4)

Here we’ve used the Maple command sum which is the additive analogue to product.Now let’s see what happens when we define the x and y data:

> xdat:=list1[1..ndat,1]; ydat:=list1[1..ndat,2];

xdat := [−1.0,−0.65,−0.1, 0.4, 1.0]

ydat := [0.5, 1.1, 0.75, 0.3,−0.2]

If we ask Maple to display the function g,

> g;

we obtain

0.5668934245(x + 0.65)(x + 0.1)(x − 0.4)(x − 1.0)

−3.298289013(x + 1.0)(x + 0.1)(x − 0.4)(x − 1.0)

+2.754820936(x + 1.0)(x + 0.65)(x − 0.4)(x − 1.0)

−0.6802721090(x + 1.0)(x + 0.65)(x + 0.1)(x − 1.0)

−0.09182736457(x + 1.0)(x + 0.65)(x + 0.1)(x − 0.4)

Page 92: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 4. LISTS 80

We could graph the data and this interpolating polynomial as follows.

> p1:=plot(g,x=-1.5..1.5,y=-1.5..1.5):

> p2:=plot(list1,x=-1.5..1.5,style=point,symbol=circle,color="Blue"):

> display(p1,p2);

This plot is shown in Figure 24. Note that the second plot statement plots the pointsthat g interpolates as blue circles.

xK1.5 K1.0 K0.5 0 0.5 1.0 1.5

y

K1.5

K1.0

K0.5

0.5

1.0

1.5

Figure 24. Plot of the Lagrange interpolating polynomial, g.

Is the interpolating polynomial a “good” description of the function that generatedthe data? There is no way to answer this question without knowing more about howthe data was generated or what physical meaning the data represents. Interpolatingpolynomials (curves) will always pass through the data, provided the data forms afunction, but the interpolating function may not be the same as the real function thatproduced the data. To see this, suppose we generate data from a known function suchas the following.

> for i from 1 to ndat do

xdat[i]:=-1+(i-1)*0.5:

ydat[i]:=xdat[i]^2*exp(Pi*xdat[i])-sin(xdat[i]):

od:

Now compare the interpolating polynomial to the original function in a graph.

> p1:=plot(g,x=-1..1,y=-1..2,color="Red"):

> p2:=plot(x^2*exp(Pi*x)-sin(x),x=-1..1,y=-1..2,color="Blue"):

> display(p1,p2);

Refer to Figure 25 for this output. Note that the original function (in blue) and theinterpolating polynomial (in red) match at the sample data points, but they do notmatch “well” overall.

Page 93: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

2. DATA AT DISTINCT POINTS AND INTERPOLATING POLYNOMIALS81

xK1.0 K0.5 0 0.5 1.0

y

K1

1

2

Figure 25. Plots of the original function x2eπx−sin(x), and Lagrangeinterpolating polynomial g for x ∈ [−1, 1]. The original function and g

show in blue and red, respectively.

Maple also has a package created for fitting curves, CurveFitting. The commandto find interpolating polynomials is PolynomialInterpolation. This command canbe used in the following ways

PolynomialInterpolation(xydata, v, form=opt) orPolynomialInterpolation(xdata, ydata, v, form=opt)

In the first, xydata is typically a list of ordered pairs of the form

[[x1, y1], . . . , [xn, yn]]

while in the second, xdata and ydata are typically lists having the form

[x1, . . . , xn] and [y1, . . . , yn],

where xdata is considered the independent values and ydata is considered the de-pendent values.

The argument v typically represents the variable for the interpolating polynomial.If v is a number, then the interpolating polynomial is evaluated at that point. Finally,form=opt is an optional argument that specifies the type of interpolation. Note thatopt may be chosen from Lagrange, monomial, Newton, or power. For informationabout these types of interpolation, please see the literature, such as [1,5,9].

Let’s see how it works.

> with(CurveFitting):

> gm:=PolynomialInterpolation(xd,yd,x);

Page 94: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 4. LISTS 82

gm := −.9979777744x− .1666666667e1.0πx − .6666666663e−1.0πx3

+.6666666667e−1.0πx4 + .3333333332e.5πx − .3333333335e−.5πx

+.166666667e−1.0πx − .1666666667e1.0πx2 + .6666666664e.5πx2

+.6666666663e−.5πx2 − .166666666e−1.0πx2 + .6666666667e1.0πx3

−.3333333332e.5πx3 + .3333333335e−.5πx3 + .6666666667e1.0πx4

−.6666666664e.5πx4 − .6666666663e−.5πx4 − 4.00000000010−10x4

+.1565067897x3 + 5.10−10x2

Let’s simplify both g and gm and see what we get.

> simplify(g);

> simplify(gm);

g = −3.313358292x + 12.11036641x4 + 14.02062667x3 − 0.5184131190x2

gm = −3.313358294x + 14.02062667x3 + 12.11036640x4 − 0.5184131220x2

They are the virtually identical, as we would expect, since the theorem said thatthe interpolating polynomial is unique. Note that due to possible round off error,generating the interpolating polynomial in two different ways may lead to two differ-ent, but similar answers. In any case, all correct methods for generating interpolatingpolynomials should be the same up to round off errors.

3. Linear Regression

In the sequel, we’ll be needing several packages. You should ensure that yourestart Maple and load them.

> restart; with(plots):

> with(LinearAlgebra):

One way to think about the interpolating polynomial discussed before is that itwas a function of the form

pn−1(x) = a0 + a1x + · · ·+ an−1xn−1 =

n−1∑

i=0

aixi

with the ai chosen so that the graph of the polynomial is forced to pass through the n

data points. The order of the interpolating polynomial is tied to the number of datapoints, but as the order of the polynomial increases so do the number of spuriousoscillations it may inflict on the approximating function g. Is it possible to choosea lower-order polynomial that is, in some sense, a good representation of the data?This is where linear regression, or minimizing least square error, comes in.

Page 95: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

3. LINEAR REGRESSION 83

To start, let’s look at a more general problem. Suppose we wish to approximatea function f by a function g of the form

g(x) =

m∑

k=1

akϕk(x)

where the functions ϕk(x) are known and we must choose the coefficients ak to satisfysome criteria. In the case of interpolating polynomials,

ϕk(x) = xk−1

and the criteria is that g and f must agree at m data points. Another example wouldbe approximation of f by trigonometric functions, i.e.

g(x) =n∑

k=0

(ak sin(kx) + bk cos(kx))

where the criteria is to minimize the maximum error between f and g on the interval[0, 2π]. That is, minimize the quantity

E(~a) = max(|f(x) − g(x)|)where the maximum is taken over the interval [0, 2π] and ~a is a vector with componentsak and bk.

The “least squares” idea is to minimize the “distance” between the approximatingfunction, g, and the data. In this case the method of measuring distance, or error, isto use the function

E(~a) =n∑

i=1

[f(xi) − g(xi)]2

where again ~a is really a vector with components ak. Our goal is to make this errorfunction as small as possible through the choice of the coefficients ak, k = 1, 2, ..., m.To accomplish this minimization we use a result from multivariate calculus: At alocal extreme value of E the following condition must hold

∂ajE = 0,

for j = 1, ..., m. The solution of these equations provides the coefficients ak thatminimize the error function E and give us the approximate representation we want.It can be shown that the critical point thus obtained does indeed occur at a minimum.

As an example of how this works, consider the problem of finding a line,

g(x) = ax + b

that best represents a set of data, (xi, yi) for i = 1, ..., n. In this case, the unknowncoefficients are a and b, and the square error function is

E(a, b) =

n∑

i=1

[yi − g(xi)]2 =

n∑

i=1

[yi − axi − b]2.

Page 96: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 4. LISTS 84

The partial derivatives to be set to zero are

∂aE = −2

n∑

i=1

xi[yi − axi − b] = 2

(

a

n∑

i=1

x2i + b

n∑

i=1

xi −n∑

i=1

xiyi

)

∂bE = −2

n∑

i=1

[yi − axi − b] = 2

(

a

n∑

i=1

xi + nb −n∑

i=1

yi

)

.

Setting these two partial derivatives to zero gives a system of linear equations inthe unknown constants a and b. Solving the system for a and b gives,

a =

n∑

i=1

xiyi

n∑

i=1

x2i

and b =1

n

n∑

i=1

yi.

In general, fitting data with m functions generates a linear system of m equationsfor the coefficients in the definition of g(x) above.

4. How Maple Does It

Since linear regression is used in the analysis of data it is often thought of as astatistical tool. Because of this Maple includes the least square error fit commandin the statistical package. So the first thing we need to do is load the stats package.

> with(stats);

[anova, describe, fit, importdata, random, statevalf, statplots, transform]

Also notice that several other commands come with the stats package. Namely,importdata can be used to import external data into Maple. For example if we havean external file named “regdata” in the same directory as the notebook then we couldimport the data in that file as follows.

> data:=importdata(‘regdata‘,2);

Notice that the 2 in the above command separates the data into two lists, the firstlist in this case is the x-coordinates of the data points and the second list is the y-coordinates. Also note that the quotes are not the normal ones used in text messages.A third note, it may be necessary to use the currentdir command to change theworking director to where we have the data stored (use the help to discover how to

Page 97: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

4. HOW MAPLE DOES IT 85

use the currentdir command). The output from the importdata is shown below.

[0.50000000, 1.0000000, 1.5000000, 2.0000000, 2.5000000, 3.0000000, 3.5000000,

4.0000000, 4.5000000, 5.0000000, 5.5000000, 6.0000000, 6.5000000, 7.0000000,

7.5000000, 8.0000000, 8.5000000, 9.0000000, 9.5000000, 10.000000, 10.500000,

11.000000, 11.500000, 12.000000, 12.500000, 13.000000, 13.500000, 14.000000,

14.500000, 15.000000, 15.500000, 16.000000, 16.500000, 17.000000, 17.500000,

18.000000, 18.500000, 19.000000, 19.500000, 20.000000, 20.500000, 21.000000,

21.500000, 22.000000, 22.500000, 23.000000, 23.500000, 24.000000, 24.500000,

25.000000], [0.53154646, 1.0138431, 1.4468596, 2.1929966, 2.1419979,

2.6840517, 2.7787804, 2.9922643, 3.4467083, 3.5454615, 3.8963445, 3.7208598,

4.0154568, 4.2206534, 4.1052527, 4.3011206, 4.2647360, 4.0920930, 4.2619999,

3.9631953, 4.3291277, 3.9059832, 4.1413377, 3.9946621, 3.6941548, 3.5445565,

3.5811202, 3.8225854, 3.7056945, 3.2316432, 3.4784447, 3.2156345, 2.7752180,

2.9157000, 2.6769020, 2.4495243, 2.2919492, 2.0958393, 1.9160771, 2.1602128,

1.6270659, 1.9087093, 1.4970932, 1.5327761, 1.5068807, 0.95175148,

0.80720237, 0.73499157, 0.44651459, 0.46531736]

If we want to graph the data we will need to convert it into a list of points asin the previous sections on data. To do this we first need to know how many datapoints we are dealing with. To find the length or dimension of a list we can use theDimension command (part of the LinearAlgebra package). Note that we need tocast data[1] as a vector since Dimension expects either vectors or matrices.

> Dimension(Vector(data[1]));

50

In this case, we have 50 data points. To convert the data from it’s present forminto a list of [x, y] points we can use the seq command. Note that the output hasbeen suppressed for brevity. See Figure 26.

> dp:=[seq([data[1,j],data[2,j]],j=1..50)]:

> p1:=plot(dp,style=point,symbol=circle,color="Black"): display(p1);

The data looks at first glance kind of like a quadratic. If we wanted to find thebest quadratic fit to the data we would use the fit[leastsquare...] command asfollows.

> eq_fit:= fit[leastsquare[[x,y], y=a*x^2+b*x+c, {a,b,c}]]([data]);

y = −0.02165357417x2 + 0.4793840834x + 1.315669124

Page 98: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 4. LISTS 86

Figure 26. Plot of data.

Here the independent and dependent variables are x and y, and the parameterswe need to find are a, b, and c. The output to the fit command is the expressionthat minimizes the square error between the given data and the form of the equationwanted. To graph this expression we use the plot command as usual. Figure 27shows this graph.

> p2:=plot(rhs(eq_fit),x=0..25, color="Red"): display(p2);

If we want to show both the data and the best fit quadratic simultaneously we dothe following. Figure 28 shows these two graphs.

> display(p1,p2);

Looking at both the data and the best fit quadratic reveals that the data maynot be quadratic in nature (the data and the quadratic don’t look symmetric). Let’stry a cubic equation. The following command generates the degree 3 least squarepolynomial. Figure 29 shows these graphs.

> eq_fit2:= fit[leastsquare[[x,y], y=a*x^3+b*x^2+c*x+d,

{a,b,c,d}]]([data]);

y = 0.001188367569x3 − 0.06710863494x2 + 0.9476306468x + 0.2717177855

Page 99: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

4. HOW MAPLE DOES IT 87

Figure 27. Plot of the Leastsquares interpolation polynomial for data.

Next, we plot the data, quadratic and cubic least squares regression functions.

> p3:=plot(rhs(eq_fit2),x=0..25,color="Blue"):

> display(p1,p2,p3);

Hopefully, it is obvious that the best fit cubic does a better job of approximatingthe data then the best fit quadratic. This should not be surprising, because thereare more degrees of freedom (more parameters) in the cubic than there are in thequadratic. In actuality, the data came from the function

f(x) =1

25e−x/20x(26 − x) +

1

2rand

where “rand” is a random number generator that gives values between 0 and 1. Oftenit is the case that real world data has some random noise in it.

The idea behind examples in linear regression is to graph the data and try toget a feeling for how the data is behaving. Does the data look linear, quadratic,etc. Then choose a set of basis function which might be powers of x, exponential, ortrigonometric functions. Finally look at the best fit solution and decides if it trulydescribes the data. If not, then try a different combinations of functions.

Page 100: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 4. LISTS 88

Figure 28. Plot of the Leastsquares quadratic interpolation polyno-mial for a given data set and data.

5. Exercises

4.1 Given the following data use Lagrange interpolating polynomials and thePolynomialInterpolation command to compute the interpolating polyno-mials through the data sets. Compare the graphs of the polynomials to thegraphs of the data. Show that the Lagrange polynomials and the results ofthe PolynomialInterpolation command are the same.A

x −1.0 −0.75 −0.5 0.5 0.75 1.0f(x) 1.0 1.0 1.0 −1.0 −1.0 −1.0

Bx −1.0 −0.75 −0.1 0.1 0.75 1.0

f(x) 1.0 1.0 1.0 −1.0 −1.0 −1.0

Cx −1.0 −0.75 −0.01 0.01 0.75 1.0

f(x) 1.0 1.0 1.0 −1.0 −1.0 −1.0

4.2 Given the following data use the fit command with the best linear and cubicpolynomial fits. Compare your results to the interpolating polynomials in thehomework on lists.

Page 101: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

5. EXERCISES 89

Figure 29. Plot of the Leastsquares quadratic and cubic interpolationpolynomials for a given data set and data.

Ax −1.0 −0.75 −0.5 0.5 0.75 1.0

f(x) 1.0 1.0 1.0 −1.0 −1.0 −1.0

Bx −1.0 −0.75 −0.1 0.1 0.75 1.0

f(x) 1.0 1.0 1.0 −1.0 −1.0 −1.0

Cx −1.0 −0.75 −0.01 0.01 0.75 1.0

f(x) 1.0 1.0 1.0 −1.0 −1.0 −1.0

4.3 Import the data from the file “regressiondata.txt”. Using techniques similarto that above, graph the data then determine a good set of functions to fit thedata. Use the fit command to find the function and plot the data and functionon the same graph. Use another set of functions and repeat the problem. Youmay want to include exponential and/or trigonometric functions along withpower functions in one of your attempts.

Page 102: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,
Page 103: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 5

Parameter Estimation - Nonlinear Regression

Unless you’ve just started a new session, issue the restart command. Through-out this chapter, we will assume that you’ve executed the following commands:with(plots), with(Statistics), and with(LinearAlgebra) commands.

1. Introduction

In the section on linear regression, we saw that it is relatively simple to fit a setof data of the form (xi, yi), i = 1, 2, ..., n, to an approximate function of the form

g(x) =

m∑

j=1

ajϕj(x).

Requiring that the sum of squared errors be minimal will always give a linear systemof m equations for the “weights,” aj , that can be solved using standard linear algebratechniques. Since the algorithm is so straightforward, it has already been implementedin Maple, in the fit command.

A big part of doing linear regression is coming up with a more or less inspiredguess for the “basis” functions, ϕj(x). However, it is often the case that the functionswe might pick have implicit parameters. For example, consider the following set ofdata:

> dp:=Matrix(readdata(‘nlreg1.txt‘, 2)):

Dimension(dp);

dpx := convert(SubMatrix(dp, [1..-1], [1]), Vector, datatype=float):

dpy := convert(SubMatrix(dp, [1..-1], [2]), Vector, datatype=float):

202

A few words of wisdom. Most likely you will have to use the currentdir commandwith an appropriate path, for example "z:/CAMMaple/Maple 12", so that readdatacan find the file you wish to import. In the sequel, we shall need to split the matrixdp into columns. So, we use the SubMatrix command to pick off an entire column.When forming the x-values, dpx, theSubMatrix’s parameter [1..-1] tells Maple touse row one through the last row (the minus one indicates the last possible entry, aminus two would indicate the second to last entry, etc.) and [1] indicates that weneed the first column of the matrix dp. The command convert allows you to convertthe submatrix into a vector. Here we specified that the entries of the vector shouldbe of type float.

91

Page 104: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 5. PARAMETER ESTIMATION - NONLINEAR REGRESSION92

> dataplot:=plot(dp,style=point,symbol=circle,color="Black"):

display(dataplot);

These commands generate the following image shown in Figure 30. From the graph

2 4 6 8 10

K1

0

1

2

Figure 30. Plot of data found in nlreg1.txt.

we can see that the data goes from x = 0 to x = 10, is sinusoidal and that it has adecreasing amplitude. We can also see that the data does not form a function (lookat x = 0 for instance). This might be two repetitions of an experiment that has aslightly random component. In order to describe this data with a function we mightguess that the periodic component looks like sin(kx) for some value of k. To explainthe decrease in amplitude we might think of exponential decay. Hence, a reasonablemodel for this data could be

g(x) = aeλx sin(kx).

The trouble with this model is that we have no ideal what to choose for the parametersk and λ, although if we did know these values we could use linear regression to finda.

The goal of this chapter will be to figure out some ways of estimating parameterswhich are embedded in the approximating function, g(x). One technique is to usenonlinear regression which will be discussed later. Other methods depend on knowingmore knowledge about the data, for instance, that it should have been produced bya differential equation, or have some particular functional form. These lead to otherways to estimate parameters, which is what we will discuss first. The data we willuse (not the above data) comes from the 1906 plague epidemic in Bombay, studiedby Kermack and McKendrick, and the model we will attempt to fit comes from thetheory of epidemics. See [8].

Page 105: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

2. BASIC THEORY OF EPIDEMICS 93

2. Basic Theory of Epidemics

In this section we will discuss an example from the theory of epidemics. In thetheory of epidemics, populations of people are divided into three classes:

(1) The susceptible class, S, who have not yet been infected,(2) The infected class, I, who have caught the disease, and(3) The removed class, R, who have recovered and are immune from this point

forward (if that is possible), or died.

If N is the total population, then the following relation is assumed:

N = S + I + R.

This is a statement that these three classes make up the whole population, and thereare no others. In particular, there is no death other than from the infection. Ingeneral, for epidemics that occur rapidly, one may neglect the effects of birth rate,natural death, and population redistribution to derive a system of equations relatingthe three types of people in the population,

dS

dt= −βSI,

dI

dt= βSI − νI, (2.1)

dR

dt= νI.

The parameter β defines a frequency at which encounters between infected individualsand susceptible individuals results in infection, and ν defines the rate at which infec-tion results in death (or recovery). The reason that the varying terms on the righthand side of the equations are repeated, but with different signs, is that a loss fromone equation must be a gain for another. If a susceptible person becomes infected,then the infected population must grow, and the same with the death of infectedpeople. This fact is reflected mathematically in the following way. If you sum allthree equations, the right hand sides cancel, giving

d

dt(S + I + R) = 0.

Integrating this simple equation gives that the total population is constant, as statedabove.

The total population, N , is called a “constant of the motion,” and can help ussolve the equations governing an epidemic. By replacing the variable S according tothe rule

S = N − I − R,

Page 106: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 5. PARAMETER ESTIMATION - NONLINEAR REGRESSION94

we can reduce the equations to a system of two equations,

dR

dt= νI, (2.2)

dI

dt= β(N − I − R)I − νI.

Finally, we can differentiate the first equation and substitute into the second:

d2R

dt2= ν

dI

dt, and I =

1

ν

dR

dt,

so we obtain,

d2R

dt2= (βN − ν)

dR

dt− βR

dR

dt− β

ν

(

dR

dt

)2

. (2.3)

(An interesting note in the theory of immunology: if

βN < ν,

then the right hand side is negative-definite whenever the death rate goes up. Hence,the number of deaths must decelerate, and the epidemic can not become self-sustaining.)

We can take a page out of physics and use an energy method to rewrite theequation as

−β

ν

(

dR

dt

)2

=d

dt

[

dR

dt+

1

2βR2 − (βN − ν)R

]

. (2.4)

If we make the assumption that the left hand side (in particular the derivative of R

with respect to t) is small in relation to the other terms (which an immunologist wouldsay means that the rate of removal is small in relation to the removed population),then the above equation can be integrated as follows:

dR

dt+

1

2βR2 − (βN − ν)R = K,

for K some constant.Before the epidemic begins, both the rate of removal and the removed popula-

tion must be zero, so the constant of integration, K, must be zero. Hence, undersimplifying assumptions, the equation for the removed population becomes

dR

dt+

1

2βR2 − (βN − ν)R = 0.

This looks very like the logistic equation we met in the sections for population models.We can put the equation into Maple and solve it:

> eqn1:=dsolve(diff(r(t),t)+beta*r(t)^2/2-(beta*N-nu)*r(t),r(t));

eqn1 := r(t) =2(βN − ν)

β + 2e−(βN−ν)tC1βN − 2e−(βN−ν)tC1ν.

Page 107: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

3. CURVE FITTING BY INSPIRATION 95

If we change variables, letting λ = βN − ν, this solution can be written

R =2λ

β + 2C1λe−2λt. (2.5)

A different way to write this solution would be

R =λ

β[1 + tanh(λ(t − t0))] .

The rate of removal, or number of deaths per unit time, would be

dR

dt=

λ2

βsech2 [λ(t − t0)] .

3. Curve Fitting by Inspiration

In this section we will examine how we might use our knowledge about the theoryof epidemics to fit a functional form to the Bombay plague data. We will not worryabout anything so sophisticated as minimizing error; instead we will just attempt areasonable guess for parameter values.

The city of Bombay, India kept records of mortality through the plague of 1906.Over a period of thirty weeks many thousand people died, and on a weakly basis thenumber of deaths were recorded. The data is as follows:

> dpw:=Vector([20.,22.,25.,31.,40.,60.,66.,93.,120.,182.,

293.,388.,451.,636.,765.,778.,721.,701.,872.,920.,

794.,582.,411.,207.,102.,66.,49.,45.,36.,30.],

datatype = float):

> len:=Dimension(dpw):

wks:=Vector([seq(j,j=1..len)], datatype = float):

> dpts:=plot(wks, dpw,style=point,symbol=circle,color="Black",

title="Deaths/week"):

display(dpts);

This generates Figure 31.Our goal is to fit this data with a functional form and thereby estimate parameters

in the differential equations that describe how epidemics proceed. Notice that theinformation plotted is in deaths per week, which we would think of as the derivativeof R, or the rate of removal. Hence, we will use inspirational guessing techniques tofit the solution

dR

dt=

λ2

βsech2[λ(t − t0)]

to the plague data.First notice that the rate of removal is symmetric about the point in time t = t0.

This point is the center of mass of the analytic description for the rate of removal. Itseems reasonable that it should be chosen to match the center of mass of the data.The center of mass of the data is

> t[0]:=add(j*dpw[j],j=1..len)/add(dpw[j],j=1..len);

Page 108: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 5. PARAMETER ESTIMATION - NONLINEAR REGRESSION96

5 10 15 20 25 30

100

200

300

400

500

600

700

800

900

Deaths/week

Figure 31. Deaths per week of the Bombay plague.

17.25573322

Here we use the add command to sum the vectors. Please don’t use sum, it doesn’tplay well with Vectors. So, 17.2557 weeks is the point in time about which theepidemic is “centered.”

If we had a reasonable value for λ, we could perform a linear regression againstthe function

sech2[λ(t − t0)]

to fit the data. Recall that the hyperbolic secant is defined by

sech[λ(t − t0)] =2

eλ(t−t0) + e−λ(t−t0).

Taking λ > 0, then for t − t0 large,

sech2[λ(t − t0)] ≈ 4e−2λ(t−t0).

Thus, if we fit the tail end of the plague data to an exponential function, we may beable to estimate λ. To fit something exponentially, we wish to find coefficients a andb so that

eatj+b =dR

dt[tj ],

where we may take the equals to mean a least-squares best fit and the right hand sideis the experimentally measured removal rate at week tj . Hence, taking the logarithmof the data, we would have

atj + b = ln

(

dR

dt[tj ]

)

,

Page 109: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

3. CURVE FITTING BY INSPIRATION 97

meaning that we wish to find a line which fits the logarithm of the data according toleast squares. This isn’t too hard in Maple. The commands are:

> tail1:=SubVector(dpw, [1..8]):

tail2:=SubVector(dpw, [23..30]):

Take the first and last eight data points on the removal rate, that are the visual“tails” of the data and isolates them from the bulk of the data. We can put the logsof the tails together:

> tail:=Vector([seq(ln(tail1[j]),j=1..8),seq(ln(tail2[j]),j=1..8)],

datatype=float):

The corresponding t values for this list are:

> interface(rtablesize=25):

twks:=Vector([seq(j,j=1..8),seq(31-j,j=23..30)], orientation = row,

datatype=float):

[1., 2., 3., 4., 5., 6., 7., 8., 8., 7., 6., 5., 4., 3., 2., 1.]

The interface command with the option rtablesize=25 instructs Maple to displayvectors of dimension 25 or less. A vector of size greater than 25 will be shown with theplaceholder notation. An additional option used in the construction of this vector isorientation. This instructs Maple to treat it as a row vector instead of the defaultcolumn vector. It’s not really needed, we just mention it here so in conjunction withthe interface command so that we save white space when displaying the vector.Here we are using the symmetry of the problem to get more data points and tocapture the rate of decay at both ends of the data. With this accompished, we fit thedata using the Maple command Fit.

> logfit:=Fit(a*x+b,twks,tail, x);

logfit := .291386702089285798x + 2.69465075791071394

The coefficient of x in this expression is twice the λ we are looking for, so:

> lambda:=diff(logfit,x)/2;

λ := 0.1456933510

Now we can perform a linear regression:

> eq:=Fit(a*(sech(lambda*(x-t[0])))^2, wks,dpw, x);

eq := 784.245807241146281sech(.1456933510x− 2.514045597)2

> f_eq:=unapply(eq, x);

Page 110: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 5. PARAMETER ESTIMATION - NONLINEAR REGRESSION98

t → 84.245807241146281sech(.1456933510x− 2.514045597)2

> p_eq:=plot(f_eq(x),x=0..30):

display(dpts,p_eq);

This code generates Figure 32.

0 10 20 30

100

200

300

400

500

600

700

800

900

Deaths/week

Figure 32. Linear regression for the Bombay plague model.

This fitted function seems to do a fair job of capturing the initial growth of thedata, and peaks out more or less where the actual plague data peaks. It misses thecomplicated behavior at the peak of the death rate distribution, and doesn’t seem todo very well as the epidemic dies out. On the other hand, it’s not clear that the weirdbehavior at the peak of the epidemic is not due to some effect we are not accountingfor. For example, people trying hard not to come in contact with plague victims atthe peak of the epidemic, or perhaps a two-week spell of cooler weather. The originalresearchers, following pretty much the methodology we have, predicted an amplitudeof 890, λ = 0.2, and t0 = 17. Given the fact that both sets of researchers, we andthey, neglected a term in our simplified model, maybe we’ve done as well as can beexpected with this methodology.

4. Nonlinear Regression

An alternative to our heuristic fitting technique would be to attempt a full nonlin-ear regression. As with linear regression, the idea is to minimize the square error be-tween the actual data and some representation we have chosen. Let g(t; a1, a2, . . . , am)

Page 111: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

4. NONLINEAR REGRESSION 99

be a model representation we have chosen for the data, that depends on the param-eters a1, a2, . . . , am.

Definition 28. Suppose that the data are given by the set of points (tj , fj), j =1, 2, . . . , n, then the error can be defined as

E =n∑

j=1

[fj − g(tj)]2, (4.1)

where E is a function of the parameters ak, k = 1, 2, . . . , m.

As before, our goal is to minimize the size of the error. From multivariable calcu-lus, we know that at such a minimum the partial derivatives must be zero, or

∂ak

E = −2n∑

j=1

∂ak

g(tj)[fj − g(tj)] = 0. (4.2)

This gives a system of m equations for the parameters, ak, at which such a min-imum can occur. The problem is that the equations are essentially nonlinear. Ingeneral, there is no way to solve the nonlinear equations. However, since we arealready dealing with numerical data, looking for a numerical approximation to thesolution is sufficient.

Let’s see how this works with our plague problem. In this case the representativefunction has the form:

g(t; a, λ, t0) = asech2[λ(t − t0)],

and the error function is defined above. In Maple we can accomplish this as follows.The function we are fitting is

> unassign(’lambda’,’t[0]’);

> g:=t-> a*(sech(lambda*(t-t0)))^2;

t → a sech(λ(t − t0))2

The error function would then be

> err:=add((dpw[j]-g(wks[j]))^2,j=1..len):

The three partial derivatives of this error function are given by

> eqna:=diff(err,a):

eqnl:=diff(err,lambda):

eqnt0:=diff(err,t0):

Next we want to solve for a critical point. We find a numerical approximation forthe critical point of interest by using the fsolve command. Since we are trying tosolve complicated nonlinear equations the numerical routine is much more efficient ifwe can give it a good initial guess for the solution. Based on the work we did above,a good initial guess might be a = 890, λ = 0.2, and t0 = 17. Plugging these valuesinto the fsolve command gives:

Page 112: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 5. PARAMETER ESTIMATION - NONLINEAR REGRESSION100

> cpts:=fsolve({eqna=0,eqnl=0,eqnt0=0},{a=890.,lambda=.2,t0=17.});

cpts := {ta = 882.1172044,0 = 17.79860179, λ = 0.1800914042}

To plot this new approximating function we would do the following:

> nlp:=plot(subs(cpts,g(t)),t=0..30,color=blue):

display(dpts,nlp);

We obtain Figure 33.

0 10 20 30

100

200

300

400

500

600

700

800

900

Deaths/week

Figure 33. Nonlinear regression for the Bombay plague data.

The command

> display(dpts,nlp,p_eq);

allows us to compare this with the result we obtained by intuition in Figure 34.It is clear that the nonlinear regression approach does a much better job of ap-

proximating the data then the educated guessing we did earlier. However, it stillmisses the complicated behavior near the peak and does not do a great job at theend of the epidemic. As before, given that we have neglected terms in an attempt tosimplify the differential equation used to model the epidemic, we’ve done reasonablywell.

5. Fitting the Differential Equation

The trouble with linear regression is that it can only give the relative weights ofa linear combination of known function in a fit. Nonlinear regression is more general,in that it can be use to find parameters wherever they occur in an approximatingfunction. However, in each case you have to have a guess as to the form of the

Page 113: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

5. FITTING THE DIFFERENTIAL EQUATION 101

0 10 20 30

100

200

300

400

500

600

700

800

900

Deaths/week

Figure 34. Comparison of Linear and Nonlinear regression for theBombay plague data.

approximating function or functions. In the epidemic case we were provided with areasonable guess for the basis function: a square hyperbolic secant function. We foundthis guess by making some simplifying assumptions about the differential equationthat models the epidemic so that we could solve the DE in closed form. Instead ofusing this approximation, we might consider fitting the original DE to the data andthen solve the DE numerically.

Recall the equation of interest for the number of deaths, R, from equation (2.3),

d2R

dt2= (βN − ν)

dR

dt− βR

dR

dt− β

ν

(

dR

dt

)2

.

If we again write λ = βN − ν, then we have the equation:

d2R

dt2= λ

dR

dt− β

[

RdR

dt+

1

ν

(

dR

dt

)2]

.

If we knew λ, β, and ν, then we could solve this equation numerically and fit thatsolution to the data using boundary conditions. The right hand side of the aboveexpression is a polynomial in R and the derivative of R, and we know from experiencethat polynomials are pretty easy to fit.

To make things a little more clear, let’s change variables by letting

x = R, y =dR

dt, and f(x, y) =

d2R

dt2.

Page 114: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 5. PARAMETER ESTIMATION - NONLINEAR REGRESSION102

Then the differential equation becomes a function of two variables,

f(x, y) = λy − β

(

xy +y2

ν

)

. (5.1)

The data we have on the plague in Bombay then needs to be in terms of (xj , yj),which is the total number of deaths at week j and the deaths per week at week j,respectively. We do not have direct data on the total number of deaths at week j, xj ,nor do we have direct data for f(xj, yj), the derivative of the removal rate at week j.However, we generate this data based on what we do have.

The total number of deaths is just the sum of the weekly deaths over the first j

weeks. That is

xj =

j∑

k=1

yk.

The dependent variable, f , is really the derivative in time of the rate of removal,y. From basic calculus, we know that

dy

dt= lim

∆t→0

y(t + ∆t) − y(t − ∆t)

2∆t.

Thus, we may make the following approximation for fj = f(xj , yj) :

fj =yj+1 − yj−1

2.

We should note that this approximation is only valid for j = 2, 3, ..., (n − 1). InMaple, we can generate xj , yj, and fj for j = 2, 3, . . . , (n − 1) as follows:

> unassign(’x’,’y’,’f’);

yd:=Vector([seq(dpw[j],j=2..(len-1))], datatype = float):

xd:=Vector([seq(add(dpw[k],k=1..j),j=2..(len-1))], datatype=float):

fd:=Vector([seq((dpw[j+1]-dpw[j-1])/2,j=2..(len-1))],

datatype = float):

M:=Matrix([xd, yd], datatype=float):

When using more than one independent variable, you should place them in a matrix,one column for each independent variable. Now we want to do a best (linear) fit tothe polynomial above:

> eqde:=Fit(a*y+b*x*y+c*y^2,M,fd, [x,y]);

eqde := 0.165312609987494308y − 0.0000778199993897761978xy

+0.000349716383577298366y2

> lambda:=subs(x=0,coeff(rhs(eqde),y));

λ := 0.1653126100

Page 115: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

5. FITTING THE DIFFERENTIAL EQUATION 103

> beta:=-coeff(coeff(rhs(eqde),y),x);

β := 0.0000778199993897761978

> nu:=-beta/coeff(rhs(eqde),y^2);

ν := −0.2225231732

Now we can use these values to solve the differential equation numerically. Notethat we will need initial conditions to solve the DE. We can use any one week as ourinitial conditions. Also note that it may be better to convert to a system of first orderdifferential equations:

dR

dt= S, (5.2)

dS

dt= λS − βRS − βS2

ν.

To solve these equations we would do the following:

> de:= diff(r(t),t)=s(t),

diff(s(t),t)=lambda*s(t)-beta*r(t)*s(t)-beta/nu*s(t)^2;

d

dtr(t) = s(t),

d

dts(t) = 0.1653126098s(t)− 0.00007781999906r(t)s(t) + 0.0003497163813s(t)2

> sols:=dsolve({de,r(20)=xd[19],s(20)=yd[19]},type=numeric,output=listprocedure);

[t = proc(t)...end proc; , r(t) = proc(t)...end proc; , s(t) = proc(t)...end proc; ]

> ss:=subs(sols,s(t));

proc(t)...end proc;

> ssp:=plot(ss,0..30):

display(dpts,ssp);

Page 116: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 5. PARAMETER ESTIMATION - NONLINEAR REGRESSION104

0 10 20 30

100

200

300

400

500

600

700

800

900

Deaths/week

Figure 35. Plot of the solution of the Bombay plague system of dif-ferential equations with initial condition from week 20.

So, we have Figure 35.Notice that we have used week 20 as our initial condition. If we want to use week

5 instead, we would get:

> sols:=dsolve(de,r(5)=xd[4],s(5)=yd[4], type=numeric,

output=listprocedure):

ss:=subs(sols,s(t)):

ssp:=plot(ss,0..30):

display(dpts,ssp);

With these new initial conditions, we obtain Figure 36.Clearly the choice of initial condition will effect the outcome of this method. We

can now experiment with the fits generated by using various initial conditions fromthe data. The fit generated by the week 20 data may not be more accurate then thenonlinear regression we did before, but it does have a more qualitative correctness.That is, including all of the terms in the differential equations captures trends in thedata more accurately. For example, the fact that the epidemic dies out more rapidlythan it starts up.

None of the techniques for parametric estimation capture the strange behavior ofthe data near the peak of the epidemic, which is part and parcel for trying to model“real life” data with relatively simple mathematical models.

6. Exercises

5.1 In earlier sections, we examined solutions to some different population-dynamicmodels. The most realistic model for a single population with limiting growth

Page 117: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

6. EXERCISES 105

0 10 20 30

100

200

300

400

500

600

700

800

900

Deaths/week

Figure 36. Plot of the solution of the Bombay plague system of dif-ferential equations with initial condition from week 5.

due to resource consumption was the logistic model,

dP

dt= aP (1 − bP ).

A great deal of data has been taken to see whether or not this theoreticalmodel is valid. Bodenheimer and Nolan took the following growth data on beehives near Baltimore (there should be 19 data points):

Table V. Data for number of bees, counted in thousands.

Day 7 14 21 28 35 42 49 56 63 70Bees 0.6 1.0 1.4 2.0 2.5 3.3 6.8 10.5 15.9 20.2

Day 77 84 91 98 105 112 119 126 133Bees 30.0 39.7 47.2 54.6 61.4 65.9 71.4 76.4 76.9

where the number of bees is counted in thousands. Below you will explorehow well the logistic equation describes this data set. Be clear about whatassumptions you make and your rationale for making them.A Approximate the derivatives of the population and choose parameters to

fit the logistic equation to the data. How well do solutions to the fittedequation fit the data?

B Choose parameters in the logistic equation to fit the asymptotic behaviorof the data. Fit an analytic solution with these parameters to the databy choosing the free constant to match something else you know about

Page 118: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 5. PARAMETER ESTIMATION - NONLINEAR REGRESSION106

the behavior of the logistic equation. Compare with the results from thefirst part.

C Use nonlinear regression to fit logistic equation solutions to the data.Compare your fit with the data and with the results from the first twoparts.

D Based on your work with this data set, is the logistic equation a gooddescription of the growth of a bee hive? What are the pros and consof the three methodologies applied above? In what circumstances is itappropriate or inappropriate to apply each methodology?

Page 119: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 6

Gambler’s Ruin

1. When Can a Farmer Turn a Profit?

In agriculture, often the difference between success and failure for a farmer isentirely dependent on the cards dealt by nature. Weather, populations of insects,weeds and many other factors can cause significant problems in a farmer’s abilityto produce enough to make the effort profitable. If these types of problems cannotbe overcome, no amount of extra work will produce enough to allow the farmer tocontinue. Trying to determine or even guess how all of these types of factors willimpact the farmer’s efforts in a given year is impossible. However, the history ofthese factors over a long period of time can be used to approximately determine theability of the farmer to make a living over a longer period than a single growingseason.

For example, weather forecasting is becoming much more sophisticated. Recordsover many years allow meteorologist to estimate the average precipitation levels in aregion with some accuracy. Over a period of years these averages can be used to tellif, on average, a farmer’s effort will provide an opportunity for the farmer to make aliving.

In this discussion, we will not consider short term decision making. The ability offorecasters to predict the weather over short periods of time is getting significantlybetter. The five day forecasts that many weather reports give are for the most partbecoming more accurate. This kind of information can be used to make decisionsabout harvesting crops and when to apply pesticides and herbicides. However, thistype of information does not extend to the entire growing season. Our interest willbe in determining the chance that a person can make a living over a long period oftime given recorded data. The following example is a simplified case of the farmingproblem.

Example - Dryland farmers depend entirely on annual precipitation in the formof rain and snow to provide moisture necessary to raise crops. The processes thatdetermine the amount of rainfall are far too complicated to allow the farmer to makedecisions about planting cros from one year to the next. The farmer must considerquestions such as

(1) How much precipitation is in the ground at planting?(2) How much rain will fall during the growing season?(3) How often rain will fall during the growing season?(4) Should herbicides, pesticides, and/or fertilizers be applied and when to apply

these?

107

Page 120: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 6. GAMBLER’S RUIN 108

(5) When to harvest the crop?

There are a number of other questions that must be answered along with these.No simple rule exists for determining the right thing to do. The situation is just toocomplicated.

Lets simplify the problem to the point where we can consider one of the questionsabove by itself. Suppose that everything is perfect except that we do not knowwhen the rain will fall. From past history we might know that the chance that rainwill fall on any day during the growing season is 10% and that the average value ofprecipitation is 0.1 inches. The question is whether or not the farmer can expect toget enough rain to grow a crop.

The dryland farmer in the example above gambles each year on whether or notthe conditions will be good enough to make the farm profitable. The example is asimplified version of the farming problem which only considers one factor. In general,to solve complicated problems it is usually necessary to try to understand how tosolve the simplest cases. In the next section, a simple problem that can be analyzedis presented.

2. Markov Chains

Concepts from probability and statistics appear in a wide variety of applicationsin everyday life. All of us have heard reports on the chance of rain, odds on afootball game, or chances of surviving a life threatening diseases. There are a varietyof reasons for using probability and statistics to try to understand the behavior ofsocial and scientific phenomena. One reason is that the underlying process is far toocomplicated to understand. Using probability theory and statistics will at least givesome qualitative and approximate quantitative information about the phenomena.For example, the weather that we are experiencing today is due to physical processesthat have occurred over the recent past. You can see this on most weather forecastswhere a movie of the cloud patterns is shown during the weather forecast taken from asatellite. The problem is that determining all the factors and relationships necessaryto predict the impact of of past events on the weather is next to impossible. Althoughresearchers have made a good deal of progress on local weather prediction there is nofeasible way currently of predicting global weather patterns.

Another important place where probability and statistics is used is in the casewhen it is only necessary to have an estimate of some quantity, such as the totalannual precipitation in some region. If decisions must be made based on the averagevalue of some measurable quantity, the concepts from probability and statistics canbe used to find appropriate quantitative information about a given process. For athorough development of probability and statistics, see [3,6,7]

First, we shall define the classic notion of the probability of a set of outcomes toan experiment.

Definition 29. The sample space, C , is the set of all outcomes of a randomexperiment. A set of outcomes, C, is a subset of the sample space C .

Page 121: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

2. MARKOV CHAINS 109

Often, for discrete experiments, we can compute the probability of an outcome,C ⊆ C by

P (C) =|C||C | ,

where | · | is the cardinality or size of a set. We assume that when the outcome set,C ⊆ C is “simple enough,” we can determine how likely it is to occur based uponthe experiment. When this fails to hold, the following definition comes to our rescueby allowing us to break up the set C into “atomic” sets whose probabilities we cancompute.

Definition 30. A probability set function, P , is a real valued function on thesample space, C satisfying

(1) P (C) ≥ 0 for all C ∈ C .(2) P (C1 ∪ C2 ∪ · · · ) = P (C1) + P (C2) + · · · where C1, C2, . . . ∈ C must satisfy

Ci ∩ Cj = ∅ whenever i 6= j.(3) P (C ) = 1.

Now, we change directions slightly. Often, the sample space, C , is not a set ofnumbers. A random variable assigns elements of C to numbers. Often with randomvariables, we count occurrences of outcomes. Also, note that random variables maybe discrete or continuous. A discrete random variable measures finite or countablyinfinite values, such as the number of blue cars that pass in an hour. A continuousrandom variable can take on all values in an interval, that is they have uncountablymany values. An example of a continuous random variable is the true (unrounded)weight of an apple. (Note that if we actually weigh the apple ourselves, then itbecomes a discrete random variable because most scales must round.)

Definition 31. A random variable, X, is a function from the sample space C tothe real numbers. The space of X, A , is

A = {x | x = X(c), c ∈ C }.We can use the notion of a random variable to define the probability of the oc-

currence of an event.

Definition 32. An event, A, is a subset of the space of the random variable X,A .

Before we continue, an example is used to clarify some of these definitions. Withthis preliminary notation in hand, we can define the probability of the random variableX.

Definition 33. The probability of an event where A ⊆ A is Pr(X ∈ A) = P (C)where C ⊆ C is the set of outcomes associated with the event A.

For simplicity (or laziness?), for A ⊆ A we often write

P (A) = P (X ∈ A).

Page 122: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 6. GAMBLER’S RUIN 110

Often, the definition listed above for the probability of an event is called an inducedprobability because it depends upon the previously defined notion of the probabilityof a set.

Example 2. A typical example is flipping n unbiased coins. So, suppose that theprobability of heads is 0.5 and the probability of tails is 0.5. (We say a coin is unbiasedor fair because the outcomes are equally likely.) Our experiment is we flip the cointwice and record the results as an ordered tuple. Thus, the sample space is

C = {(H, H), (H, T ), (T, H), (T, T )}.Thus, we can easily compute the probability of C = {(H, H), (T, H)} by

P (C) = P [(H, H)] + P [(T, H)] =1

4+

1

4=

1

2.

We can create a random variable, X, that simply counts the number of heads in anoutcome of an experiment. That is,

X[(H, H)] = 2, X[(H, T )] = 1, X[(T, H)] = 1, X[(T, T )] = 0.

The space of X is

A = {0, 1, 2}.We can now ask questions such as what is the probability of receiving one head, thatis the probability of the event 1 occurring, written

Pr[X = 1] = P [{(H, T ), (T, H)}] = P [(H, T )] + P [(T, H)] =1

4+

1

4=

1

2.

Similarly, the probability of at most one head is written

Pr[X ≤ 1] = P [{(H, T ), (T, H), (T, T )}] =3

4.

Now, let’s continue our basic probability review with the notion of conditionalprobability.

Definition 34. Given two outcomes C, D ⊆ C , the conditional probability thatC occurs given that D has already occurred to be

P (C | D) =P (C ∩ D)

P (D),

assuming that P (D) > 0. Furthermore, we say that the outcomes are independent if

P (C | D) = P (C) or P (D | C) = P (D).

Note that P (C | D) = P (C) implies that

P (C ∩ D) = P (C)P (D).

Sometimes this latter statement is used for the definition of independence.

Page 123: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

2. MARKOV CHAINS 111

Example 3. Suppose that we flip a biased coin twice and record the results. Forthe biased coin, the probability for heads is 0.7 and the probability for tails is 0.3.We assume the coin is tossed in an independent manner. Thus, we may compute theprobability

P [(H, H)] = P (H) · P (H) = 0.7 · 0.7 = 0.49.

In the context of random variables, we have to work a little harder. We first definethe concept of a probability mass function for given random variable X.

Definition 35. Suppose that X is a discrete random variable with space A .Then, the probability mass function or p.m.f. of X is defined to be

f(x) = Pr(X = x), x ∈ A .

Furthermore, for A ⊆ A , we have

P (A) = Pr(X ∈ A) =∑

x∈A

f(x).

Notice that the p.m.f. f(x) is always non-negative since it is defined based upona probability. Also,

x∈A

f(x) = Pr(X ∈ A ) = 1.

These two conditions (especially the latter) are often useful when testing whether ornot an unknown function is a probability mass function.

Definition 36. Given a random variable X with associated probability mass func-tion, space A , and a function u(x), we define the expected value of the function u

E[u(X)] =∑

x∈A

u(x)f(x).

The mean, µ, of X is the expected value of X, that is

µ = E[X] =∑

x∈A

xf(x).

The variance, σ2, of X is the expected value of (X − µ)2, where µ is the mean of X.That is,

σ2 = E[(X − µ)2] =∑

x∈A

(x − µ)2f(x).

In all cases, we assume that the series is absolutely convergent (NOT conditionallyconvergent), otherwise the expected value does not exist.

Please notice the use of capital and lower case. This is a convention we’ll usein this book. We’ll use a capital letter for the random variable and lower case whencomputing things such as summations. For example, the expected value of the random

Page 124: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 6. GAMBLER’S RUIN 112

variable X is written E[X], not E[x]. However, when computing the expected value,we use lower case when evaluating the sum

x∈A

xf(x).

These results extend in a natural way when dealing with more than one randomvariable. In the sequel we’ll investigate two random variables.

Definition 37. Let X and Y be two random variables associated with the samplespace C and probability set function P . The state space or space of the random vector(X, Y ) is defined to be

A = {(X(c), Y (c)) | c ∈ C } ⊆ R2.

We define the (induced) probability of a A ⊆ A to be

Pr[(X, Y ) ∈ A] = P (C),

where C ⊆ C is the associated set of outcomes for the event A. In other words,

C = {c | c ∈ C and [X(c), Y (c)] ∈ A}.Thus, we can make the following definition for a joint probability mass function.

Definition 38. Let X and Y be two random variables with state space A . Thejoint probability mass function of X and Y , denoted fX,Y (x, y) is defined to be

fX,Y (x, y) = Pr(X = x, Y = y).

Notice that this definition satisfies the following three properties:

(1) fX,Y (x, y) ≥ 0 for all (x, y) ∈ A .

(2)∑

(x,y)∈A

fX,Y (x, y) = 1.

(3) For all A ⊆ A , P (A) ≡ Pr[(X, Y ) ∈ A] =∑

(x,y)∈A

fX,Y (x, y).

Given a joint p.m.f., it is sometimes nice to compute probabilities for a singlerandom variable.

Definition 39. Let X, Y be two random variables with joint p.m.f. fX,Y (x, y).Suppose that the spaces of X and Y are AX and AY , respectively. The marginalprobability mass function of X is

fX(x) =∑

y∈AY

fX,Y (x, y), x ∈ AX

and the marginal p.m.f. of Y is

fY (y) =∑

x∈AX

fX,Y (x, y), y ∈ AY .

Page 125: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

2. MARKOV CHAINS 113

Now, we can define conditional probability in terms of random variables, theirjoint p.m.f. and their marginal p.m.f.s. The idea here is that we are given extra infor-mation, which must then change the probability mass function. As a tiny example, onany day, the probability of walking outside and getting wet may be small. However,if I give you some extra information that rogue kids are waiting outside with waterballoons, the chance of getting wet just got larger.

Definition 40. Let two random variables X and Y have joint p.m.f. fX,Y (x, y),marginal p.m.f.s fX(x) and fY (y), and support spaces AX , AY . Let X | y1 denote therandom variable X given that Y = y1. Similarly, Y | x1 is the random variable Y

given that X = x1. The conditional p.m.f. of X | y1 is

fX|y1(x | y1) =

fX,Y (x, y1)

fY (y1), fY (y1) > 0, x ∈ AX .

The conditional p.m.f. of Y | x1 is defined to be

fY |x1(y | x1) =

fX,Y (x1, y)

fX(x1), fX(x1) > 0, y ∈ AY .

Next, we define conditional probability of two random variables.

Definition 41. Let X and Y be two random variables with support spaces AX , AY .Suppose that for a fixed y1 ∈ AY , the random variable X | y1 has conditional proba-bility mass function fX|y1

(x | y1) where x ∈ AX. Then, for any A ⊆ AX , we define

P (X ∈ A | y1) =∑

x∈A

fX|y1(x | y1).

Of course, since we have a probability mass function, we can find conditionalexpected values of functions, means, and variances in a similar manner. We needonly use the appropriate conditional p.m.f.

Definition 42. Let two random variables X and Y have joint p.m.f. fX,Y (x, y),marginal p.m.f.s fX(x) and fY (y), and support spaces AX , AY . The conditionalexpected value of u(X) | y1 is

E[u(X) | y1] =∑

x∈AX

u(x)f(x | y1).

The conditional mean of X | y1 is

µX|y1= E[X | y1] =

x∈AX

xf(x | y1).

The conditional variance of X | y1 is

σ2X|y1

= E[(X | y1 − µX|y1)2] =

x∈AX

(x − µX|y1)2f(x | y1).

We assume that all sums are absolutely convergent.

We can now define the extremely important (for us) idea of independent events.

Page 126: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 6. GAMBLER’S RUIN 114

Definition 43. Let two random variables X and Y have joint p.m.f. fX,Y (x, y)with joint space A , marginal p.m.f.s fX(x) and fY (y) with associated spaces AX andAY . We say that X and Y are independent if

(1) The joint space A = AX × AY .(2) fX,Y (x, y) = fX(x)fY (y).

Now, we have a common framework of knowledge to begin our study of MarkovProcesses. Suppose that we have a collection of discrete random variables

{X1, X2, . . . , Xn, . . .}.Then, we adopt the convention that the probability mass function associated withthe random variable Xn with space An is

pi(n) = Pr(Xn = i), n = 1, 2, . . . .

Thus we have a family of probability mass functions {pi(n)}. Since we have a p.m.f.,it is clear that

i∈An

pi(n) = 1.

for any given n = 1, 2, . . ..

Definition 44. A discrete time stochastic process is a collection of random vari-ables

X1, X2, X3, . . . , Xn, . . .

with common sample space C . For each fixed c ∈ C , we have a sample path

X1(c), X2(c), . . . , Xn(c), . . . .

A discrete time Markov chain is a discrete time stochastic process {Xn}∞n=0 that sat-isfies the Markov property if

Pr[Xn = x0 | X0 = x0, X1 = x1, . . . , Xn−1 = xn−1] = Pr[Xn = xn | Xn−1 = xn−1],

where xi ∈ N for all i ∈ {0, 1, 2, . . .}.With Markov chains, it is convenient to talk about the probability of moving from

one state to another. That is, given that you are at state i, what is the probabilityof moving to state j? Note that when i = j, you have remained at the current state.

Definition 45. Let the collection of random variables

{X1, X2, . . . , Xn, . . .}be a discrete Markov chain. The one-step transition probability from state i to statej is defined to be

pji(n) = Pr(Xn+1 = j | Xn = i)

where n = 1, 2, . . . . If the one-step transitions do not depend upon time, then they arecalled stationary and denoted pji. Otherwise they are nonstationary.

Page 127: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

2. MARKOV CHAINS 115

A word of caution is needed. Some books define the one-step transition probabilityof moving from state i to state j by pij rather than pji. This is an equivalent wayof constructing them, but there will be small variations in the wording of the theory.Just be aware and always check definitions carefully.

For a discrete Markov chain with stationary one-step transition, when you are atstate i, you either stay there or move to another state, j. Mathematically, we have

∞∑

j=1

pji =

∞∑

j=1

Pr(Xn+1 = j | Xn = i) = 1, i ∈ N.

Therefore, for i fixed, {pji}j∈N is a p.m.f.

Definition 46. The transition matrix of a discrete time Markov chain with statespace N and stationary one-step transition probabilities {pji}i,j∈N is

P =

p11 p12 · · ·p21 p22 · · ·...

.... . .

.

Note that when the state space is finite, say {1, 2, . . . , k}, then the transitionmatrix will be k × k, rather than infinite.

In either case, we have a stochastic matrix. A stochastic matrix is a matrix whosecolumns sum to one.

It is also convenient to consider the probability of moving from state i to state j

in k time steps.

Definition 47. The k-step transition probability is defined to be the probabilityof moving from state i to state j in k time steps in a stationary, discrete Markovchain with random variables {X1, X2, . . .}; that is

p(n)ji = Pr(Xk+1 = j | X1 = i).

A few comments are in order here. First, the probabilities can easily be zero sincestate j may be unreachable from state i when k steps are used. Also, when k = 0,

then p(0)ji = 1 if and only if i = j, otherwise it is zero. If k = 1, then p

(1)ji = pji. Notice

that p(k)ji is NOT pji to the kth power! Finally, we can define the k-step transition

matrix.

Definition 48. For k ≥ 0, the k- step transition matrix of a discrete time Markovchain with state space N and stationary one-step transition probabilities {pji}i,j∈N is

P (k) =

p(k)11 p

(k)12 · · ·

p(k)21 p

(k)22 · · ·

......

. . .

.

Theorem 12. If P is a stochastic matrix, then P k is also a stochastic matrix forany k ∈ N. Furthermore, P (0) = I, the identity matrix, and P (k) = P k for all k ∈ N.

Page 128: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 6. GAMBLER’S RUIN 116

3. Solution to the Gambler’s Ruin Problem

One of the simpler problems of this type is the Gambler’s Ruin problem, which hasbeen studied in some detail. This problem is similar to the Farmer’s Problem, it justhappens on a much shorter time-scale. This problem begins by trying to determinethe success or failure of a gambler who goes to a casino with some amount of moneyinitially and wants to leave with some larger amount of money at the end of theevening. For example, the goal of the gambler who comes to the casino with $100 atthe beginning of the evening might be able to leave the casino with $200.

The possible outcomes in this problem are that the gambler can achieve the goalof winning the desired amount of money or the gambler can lose all of the initialmoney. The goal of the casino, of course, is for the gambler to lose. To simplify theproblem a little assume that the gambler will wager one dollar each time the gameis played. Each time the gambler wagers, there is some chance that the result willbe a win and some chance that the gambler will lose. Thus, we need to keep trackof the sequence of results from each wager to determine the final outcome. We cantrack each win or loss when a game is played using a sequence of random variablesthe form X1, X2, ..., Xn that ends with the gambler losing or achieving the goal whereXi = ±1.

For our purposes, assume that the probability of a win is p and the probability ofa loss is q = 1− p. Note that if p > .5 the game favors the gambler, and if p < .5 theedge goes to the casino. To analyze the whole sequence requires a little more effort.

To analyze the problem we will assume that the gambler starts with a dollars andwants to end up with c dollars. Note that a and c are integers with 0 < a < c. Thendefine the amount of money the gambler has at each step as Dn = D(n) which canbe computed as

Dn = a + X1 + X2 + ... + Xn = a + Sn

where Sn keeps track of the total change in the amount of money at any level.We also need to define the entire sets of events that result in the gambler winning

or losing. So define

Aa,n = {(X1, . . . , Xn) | Dn = c, 0 < a + Sk < c, k < n}as the set of events where the gambler wins after exactly n plays and

Ba,n = {(X1, . . . , Xn) | Dn = 0, 0 < a + Sk < c, k < n}as the set of events where the gambler loses after exactly n plays. Note that thereare many ways to win and lose as well as many ways that the gambler could end upstaying forever.

We take the union of all the sets Aa,n to get all possible ways of winning and theunion of all the sets Ba,n will give all possible ways of losing. If we can figure out theprobabilities of landing in these two sets we will be able to find out the probabilitiesof the gambler’s success or failure.

Now let sc(a) = P (∪nAa,n) =∑

n P (Aa,n) be the probability of success for thegambler. The reason we can sum the probabilities is that each play is an independent

Page 129: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

3. SOLUTION TO THE GAMBLER’S RUIN PROBLEM 117

event. There are some values of sc(a) that are easy to obtain. If the gambler startswith no cash, there is no hope of winning. That means that sc(0) = 0. Also, ifthe gambler shows up with a = c, then it is not necessary to play since the goal isachieved. This means sc(c) = 1.

We can also determine a relationship at each level. The probability sc also satisfiesthe equation

sc(a) = p · sc(a + 1) + q · sc(a − 1). (3.1)

The equation comes from considering what happens on the very first wager. Onthis turn, there is a probability of p that the gambler wins one dollar and from therethe onward probability of success is determined by all sequences starting from a + 1.The other term in the equation represents the case when the gambler loses a dollarand then the success of the gambler depends on all the sequences that start froma − 1. The two can be added since the events are all independent.

The result of all this work is the definition of a second order difference equationfor the function sc. To restate the problem we want to find sc(a) in equation (3.1)satisfying the second order difference equation

sc(a) = p · sc(a + 1) + q · sc(a − 1)

with boundary conditions sc(0) = 0 and sc(c) = 1. The above process is calledfirst step analysis. There is a very straight forward analogy between solving secondorder linear ordinary differential equations and this difference equation.

Example 4. Consider the second order ordinary differential equation

y′′(t) − 3y′(t) + y(t) = 0

with the initial conditions y(0) = 1 and y′(0) = 0. Find the solution.To find the solution, we simply assume the solution form

y(t) = Cert

Substituting into the differential equation gives the equation(

r2 − 3r + 1)

Cert = 0.

Since the exponential function is never zero and the constant, C, will be assumed tobe nonzero, the other factor must be zero. Thus we have

r =3 +

√5

2or r =

3 −√

5

2,

and thus the solution is

y(t) = C1e(3+

5)t2 + C2e

(3−√

5)t2

with the coefficients determined by the initial conditions. Maple makes this easy tosolve with the commands

> sols := diff(y(t),t,t)-3*diff(y(t),t)+y(t)=0;

Page 130: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 6. GAMBLER’S RUIN 118

sols :=d

dt

(

d

dty(t)

)

− 3

(

d

dty(t)

)

+ y(t) = 0

> dsolve(sols, y(t));

y(t) = C1 e12(√

5+3)t + C2 e12(√

5−3)t

Now we return to the difference equation (3.1). The solution method is virtuallythe same. First, assume a solution form

sc(a) = za

for some unknown base value z. Then substitute the form into the equation. Thisgives the characteristic equation

za = pza+1 + qza−1.

Then collect everything on one side of the equation and factor out a common za−1 toobtain

(

pz2 − z + q)

za−1 = 0.

We do not want the solution to be zero which implies that z is not equal to 0 andza−1 is not equal to 0. So the quantity in parentheses must be zero. For practice youmight use the Maple command

> solve(p*z^2-z+q=0,z);

1

2

1 +√

1 − 4pq

p, −1

2

−1 +√

1 − 4pq

p

There are two cases to consider when solving this equation. We first assume thatp 6= q, that is, neither p nor q = 1 − p can equal one-half. Recall that the values of p

and q are related and that we can get a simpler expression using the two commands

> q:=1-p;

q := 1 − p

> solpq:=solve(p*z^2-z+q=0, z);

solpq := 1,−−1 + p

p

Note that

> solpq[2]=q/p;

Page 131: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

3. SOLUTION TO THE GAMBLER’S RUIN PROBLEM 119

−−1 + p

p=

1 − p

p

Substituting back into our assumed solution gives,

sc(a) = C11a + C2

(

q

p

)a

= C1 + C2

(

q

p

)a

.

To determine the constants C1 and C2 we can use the conditions that sc(0) = 0 andsc(c) = 1. This gives a solution of the form

sc(a) =pc

pc − qc

(

1 −(

q

p

)a)

. (3.2)

This can be messy to produce. To solve for the coefficients use the following commands

> sc:=a->c1+c2*(q/p)^a;

sc := a → c1 + c2

(

q

p

)a

> q:=1-p;

q := 1 − p

> sol2:=solve({sc(0)=0,sc(c)=1},{c1,c2});

sol2 :=

c2 =1

−1 +(

−−1+pp

)c , c1 = − 1

−1 +(

−−1+pp

)c

> simplify(subs(sol2,sc(a)))

−1 +(

−−1+pp

)a

−1 +(

−−1+pp

)c

The subs is used to substitute the values of the coefficients into the solution. Notethat with a little algebra, this matches with the above expression for the solution tothe Gambler’s Ruin problem.

Now, let’s consider the case when p = q = 12. Recall the solution of the character-

istic equation had eigenvalues given by equation (3),

Λ =1 ±√

1 − 4pq

2p.

Page 132: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 6. GAMBLER’S RUIN 120

Thus, when p = q = 12, 1 − 4pq = 0 and we have a single eigenvalue, namely λ = 1.

The general solution in this case is given by

sc(a) = c1 + c2a. (3.3)

Applying the boundary conditions sc(0) = 0 and sc(c) = 1, we have c1 = 0 andc2 = 1

2. Hence, the solution is given by

sc(a) =1

ca. (3.4)

Again, we might use Maple to solve the above difference equation using

> sc2 := a -> c1 + c2 * a;

> sol3 := solve({sc2(0) = 0, sc2(c) = 1}, {c1, c2});> simplify(subs(sol3, sc2(a)));

Maple returns with the following output

sc2 := a− > c1 + c2a

sol3 :=

{

c1 = 0, c2 =1

c

}

a

c

Summarizing, we from equations (3.2) and (3.4), the complete solution to theGambler’s Ruin problem is given by

sc(a) =

a

c, p = q =

1

2, 0 ≤ a ≤ c

pc

pc − qc

[

1 −(

q

p

)a]

, p 6= q, 0 ≤ a ≤ c.

(3.5)

Since the gambler either wins or loses, we can compute the probability of losingthe game, lc(a) = 1− sc(a). Thus, from the solution given in equation (3.5), we have

lc(a) =

c − a

c, p = q =

1

2, 0 ≤ a ≤ c

(

qp

)c

−(

qp

)a

(

qp

)c

− 1, p 6= q, 0 ≤ a ≤ c.

(3.6)

If the problem becomes more complicated, there is no guarantee that we wouldbe able to get an exact representation of the probability. The interesting thing thatyou should take away from this solution process is that it is similar to what you havedone in an ordinary differential equations course.

Now lets try plugging in some numbers.

Page 133: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

3. SOLUTION TO THE GAMBLER’S RUIN PROBLEM 121

Example 5. Suppose that a gambler is playing a game where the probability ofwinning is 0.45. Determine the probability that a gambler that begins with $15 canwin $5.

From this information, we have a = 15, c = 20, p = 0.45 and q = 0.55. Substitut-ing the numbers into the above solution gives

s20(15) =0.4520

0.4520 − 0.5520

(

1 −(

0.55

0.45

)15)

≈ 0.35499.

Thus, the chances are a little better than 1 in 3 that the goal will be achieved.

Actually, the exact solution to the Gambler’s Ruin problem is a function of threevariables: a, c, and p. We can see how the probability of successfully achieving thegambler’s goal depends on these three variables graphically in Maple by looking atthe following sequence of command. Here we fix a and c at the values in the example.

> sc3v:=(a,c,p)->p^c*(1-((1-p)/p)^a)/(p^c-(1-p)^c);

sc3v := (a, c, p) →pc(

1 −(

1 − 1−pp

)a)

pc − (1 − p)c

> plot(sc3v(15,20,p), p=0..1);

p0 0.2 0.4 0.6 0.8 1.0

0

0.2

0.4

0.6

0.8

1.0

Figure 37. Probability of winning game vs. p given a = 15 and c = 20.

In this graph notice that if p < 0.2 then the gambler has practically no chance ofsuccess, while if p > 0.6 they will most certainly achieve there goal of $20.

Page 134: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 6. GAMBLER’S RUIN 122

We can also consider the average duration of the game, τc(a). Note that whena = 0 or a = c, the game is over. Thus, the expected duration at the endpoints is

τc(0) = τc(a) = 0.

We again use first-step analysis to construct a difference equation. So, if the gamblerwins a round, then 1 + τc(a + 1) is the new expected duration. a loss indicates thatthe new expected duration is 1 + τc(a − 1). Associating these wins and losses withtheir respective probabilities p and q, we have the following difference equation:

τc(a) = p(1 + τc(a + 1)) + q(1 + τc(a − 1)),

where 1 ≤ k ≤ c − 1. Rearranging, we have

pτc(a + 1) − τc(a) + qτc(a − 1) = −1,

a non homogeneous difference equation with boundary conditions

τc(0) = τc(c) = 0.

Solutions to non homogeneous difference equations parallel that of differentialequations:

(1) Find the general solution to the homogeneous difference equation.(2) Find a particular solution to the non homogeneous difference equation.(3) Apply the initial conditions to the sum of the general solution and the par-

ticular solution.

We begin by solving the homogeneous difference equation

pτc(a + 1) − τc(a) + qτc(a − 1) = 0

when we assume that p 6= q. Notice that this difference equation is similar to equa-tion 3.1. The only difference is the variable τc(a) is used instead of sc(a). So, we’vealready solved this homogeneous difference equation. Updating our notation, thehomogeneous difference equation has solution

τc(a) = c1 + c2

(

q

p

)a

, p 6= q.

To find a particular solution to the non homogeneous difference equation, weassume that τc(a) = ca for some constant c. Plugging into the non homogeneousdifference equation and solving for τc(a), we have

τc(a) =a

q − p.

When we apply the initial conditions to

τc(a) = c1 + c2

(

q

p

)a

+a

q − p,

Page 135: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

4. APPROXIMATING THE SOLUTION OF THE GAMBLER’S RUINPROBLEM VIA SIMULATIONS 123

we find that c2 = −c1 and

c1 = − c

q − p

1

1 −(

qp

)c

.

Notice that when we use our initial conditions,

τc(a) = c1 + c2

(

q

p

)a

+a

q − p= c1

[

1 −(

q

p

)a]

+a

q − p

= − c

q − p

1

1 −(

qp

)c

[

1 −(

q

p

)a]

+a

q − p

=1

q − p

a − c ·1 −

(

qp

)a

1 −(

qp

)c

.

Now, let’s suppose that p = q =1

2. Again, “cheating” by referring to the solution

to equation 3.1, we see that the homogeneous solution is given by

τc(a) = d1 + d2a.

Therefore, the particular solution can’t be a multiple of a. Instead, use τc(a) = da2.This gives us a particular solution

τc(a) = −a2.

Applying the initial conditions to the composite solution

τc(a) = d1 + d2a − a2,

we see that d1 = 0 and d2 = c. Thus, our final solution, after factoring out an a isgiven by

τc(a) = a(c − a), p = q =1

2.

Finally, we can collect the two solutions together,

τc(a) =

a(c − a), p = q =1

2, 0 ≤ a ≤ c

1

q − p

a − c ·1 −

(

qp

)a

1 −(

qp

)c

, p 6= q, 0 ≤ a ≤ c.

4. Approximating the Solution of the Gambler’s Ruin Problem via

Simulations

The analysis above will give the probability that the gambler will win given theinitial amount of money, the amount of money that the gambler wants to win, andthe probabilities of winning and losing on each wager. For this simple problem, it is

Page 136: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 6. GAMBLER’S RUIN 124

possible to determine an exact solution. For more difficult problems, an exact solutionmay exist, but be impossible to find. In these cases, we can simulate the process ona computer and determine some quantitative information about the problem. Afterdoing a large number of these simulations, we can compute some statistics on thenumber of times the gambler would win or lose and how long these results take tohappen.

Writing a Simulator in Maple:To program this situation in Maple, follow the steps that would take place for

the gambler. First the gambler will enter the casino with a dollar amount. So thefirst step is to initialize the amount of money the gambler currently possesses:

> a:=15;

15

Next, the gambler would “play the game.” (In order to reproduce this in Maple,we need to repeatedly generate a way to tell if the gambler wins or loses one roundof the game with the same random chance as is given.) In Maple there are com-mand structures to produce conditional loops and to generate random numbers. Thefollowing is a way to simulate one game:

> c:=20; p:=0.45;

20

0.45

> while (0 < a and a < c) do

randval:=rand()*10^(-12):

if (randval <= p)

then a:=a+1 else a:=a-1 end if:

od:

The rand() command generates a (uniformly distributed) random 12 digit integer.Multiplying this by 10−12 will generate a random number between 0 and 1 with12 significant digits. The while command will repeatedly execute the Maple codebetween the do and the od. The if (condition) command will execute the then

part if the condition is true and the else part if the condition is false. To see theoutput of a:

> a;

20

Page 137: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

4. APPROXIMATING THE SOLUTION OF THE GAMBLER’S RUINPROBLEM VIA SIMULATIONS 125

In this case the gambler achieved the goal. Note that this may not always be the casesince the random number generator used will not always give the same results.

Finally, the above command structure can be embedded in a procedure or proc

to gather statistics on repeatedly playing the game.

> gambl:=proc(a0,c,p)

a:=a0:

plays:=0:

for i from 1 to 500 while (0 < a and a < c) do

plays:=plays + 1:

randval:=rand()*10^(-12):

if (randval < p)

then a:=a+1 else a:=a-1 end if:

od:

RETURN([a,plays]):

end:

Warning, ‘a‘ is implicitly declared local to procedure ‘gambl‘

Warning, ‘plays‘ is implicitly declared local to procedure ‘gambl‘

Warning, ‘i‘ is implicitly declared local to procedure ‘gambl‘

Warning, ‘randval‘ is implicitly declared local to procedure ‘gambl‘

You can safely ignore the warning messages. Note that this procedure has a limitof 500 rounds of the game to avoid the unlikely event that the game proceeds for aninordinately long time. This procedure will have both the end value of money andthe number of plays to reach that value. Now to test the procedure.

> gambl(15, 20, 0.45);

[20, 17]

This means that a gambler played 17 times and won. Sometimes a gambler will nei-ther win nor lose and the number of plays will be 500. This will happen sometimessince there is a limit on the number of plays. Please again note that your output maynot match that given here as this is a random event.

Now let’s look at what happens if a multitude of gamblers plays the game. Onaverage, will the gamblers come out ahead or are the gamblers doomed to failure?

> unassign(’win’,’lose’):

> win:=Vector(500, fill = 0):

> lose:=Vector(500, fill = 0):

> for j from 1 to 10000 do

Page 138: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 6. GAMBLER’S RUIN 126

num := gambl(15, 20, 0.45):

if (num[1] = 20)

then win[num[2]]:=win[num[2]]+1

else if (num[1] = 0)

then lose[num[2]]:=lose[num[2]]+1 end if

end if:

od:

The above command set up two arrays to count the number of rounds it takes to winor loose each game and then plays the game for 10,000 gamblers. In the loop, if agambler wins the game in say 21 rounds, then the 21st element of the “win” array willbe incremented by 1. To see the results of these commands generate the followinggraphs.

> winp:=plot([seq([j,win[j]/10000],j=1..500)],style=point,

symbol=box):display(winp);

> losep:=plot([seq([j,lose[j]/1000],j=1..500)],style=point,

symbol=box):display(losep);

100 200 300 400 5000

0.005

0.010

0.015

0.020

38(A) Frequency of winning game vs. roundsplayed.

100 200 300 400 5000

0.05

0.10

0.15

38(B) Frequency of loosing game vs. roundsplayed.

Figure 38. Simulations of the Gambler’s Ruin Problem.

In the graphs in Figures 38(A) and 38(B) we see frequency distributions for thetime it takes to win or loose the game. We can calculate the number of times thatgamblers won or lost as follows. Remember to use the add command because sum

does not work well with Vectors (you have to use the unassign operator).

> wt:=add(win[i],i=1..500);

wt := 3476

Page 139: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

4. APPROXIMATING THE SOLUTION OF THE GAMBLER’S RUINPROBLEM VIA SIMULATIONS 127

> lt:=add(lose[i],i=1..500);

lt := 6522

So, in this simulation, there were 3,476 wins and 6,522 loses out of 10,000 gamblers.Note that this does not account for all 10,000 gamblers that played the game. Thereason for this is that the games where the gamblers played for 500 rounds and didnot reach the goal of $20 or go broke were not counted. This happened 2 times.

To approximate the probability of winning or losing, calculate the portion of wins(or loses) with respect to the total number of times a win or lose occurred.

> probw:=evalf(wt/(wt+lt));

probw := 0.3476695339

or about 34.8%. The probability of losing is

> probl:=evalf(lt/(wt+lt));

probl := .6523304661

or about 65.2%. Recall that the analytical solution to the Gambler’s Ruin problemwas that the probability of a gambler winning when a = 15, c = 20 and p = .45 wasabout 35.5%. This does not match exactly with the results of the simulation, butthe simulation gives a somewhat reasonable approximation. The differences betweenthe exact value and the approximation can be attributed to several factors. A smallamount of error can be accounted for because the simulation was run for only a finitenumber of gamblers. Another small source of error is that the games have a chanceof stopping without a win or lose in the simulations, unlike in the theoretical games.

Along with the probabilities, another useful statistic is that of expected value. Ifa gambler wins, how long can he expect to be playing the game. In this case, howlong it takes a gamble to go broke would tell a casino how long it will take to get thegamblers money. Mathematically the expected value of an array of values of the typewe have is given by

E(yi) =

∑ni=1 iyi

nFor our results we have

> wexp:=evalf(add(i*win[i],i=1..500)/wt);

wexp := 40.82451093

Page 140: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 6. GAMBLER’S RUIN 128

> lexp:=evalf(add(i*lose[i],i=1..500)/lt);

lexp := 100.0490647

So this simulation suggests that the gambler would expect to win in about 41 roundswhile the casino would expect to have to wait about 100 rounds for a gambler to gobroke.

5. Exercises

6.1 Use the techniques presented in this chapter to solve the following differentialequations by hand and then using the dsolve command. Discuss the behaviorof the general solution of the differential equation. In the Maple worksheettype in the steps you used to solve the problems and give the intermediateresults.A y′(t) = 5y(t)B y′(t) = −3y(t)C y′′(t) + 5y(t) + 6y(t) = 0

6.2 Solve the following recursion relationships using the rsolve command andcheck the work by showing the solution by hand. Use the process of assumingthe solution is of the form

an = zn

and perform the algebraic steps after substituting the form in the differenceequation in each case. Note that you may need to look at the Maple help tosee how to use the rsolve command.A an = 0.3an−1 with initial condition a0 = 2.B an+1 = an − 2an−1 with initial conditions a0 = 2 and a1 = 1.C an+1 = −2an−1 with initial conditions a0 = 2 and a1 = 1.

6.3 Suppose that a gambler starts with $15 and wants to try to leave the casinowith a profit. In the notation of this chapter this means a = 15 and c > 15.If the gambler chooses roulette and always bets on black to win, the odds ofwinning are 18 out of 39. This mean p = 18

39and q = 21

38. Define a function that

represents the probability of being an arbitrary amount ahead while playingthe game. Graph the function and discuss the behavior of the function. Inaddition, do the same with a = 20 and p = 18

39and then again with a = 15 and

p = 3777

. Show the graphs of the three cases on the same plot and answer thefollowing questions.A In the second situation above, the starting amount of money is increased

and in the third case the probability of winning is increased. Which ofthe cases shows the largest difference relative to the first? Why?

B Write a Maple procedure to simulate this problem. How do the resultsof the simulation compare to the theoretical results?

6.4 Write a Maple procedure with inputs of a, the starting amount of money; c,the amount of money the gambler wishes to end up with; p, the probability of

Page 141: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

5. EXERCISES 129

winning one round of the game; the number of gamblers; and the maximumnumber of rounds a gambler may play. The output to this procedure shouldbe lists of the number of gamblers that win (and loose) indexed by the numberof rounds it take to win or go broke. Note that this procedure will be similarto the code in this section. Apply this procedure to the following cases withthe number gamblers set at 250 and number of rounds set to 100.A a = 5, c = 8, p = 0.45B a = 3, c = 8, p = 0.45C a = 5, c = 8, p = 0.35For each case compare the probability of winning using the theoretical resultsfound in this chapter with the estimated probability of winning given by thesimulation. Do the probabilities make sense?

Page 142: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,
Page 143: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 7

The Spectrum of Extinction

1. Introduction

In this chapter we will extend our exploration into basic programming in Maple.Our vehicle for doing this will be exploring the phenomenon of extinction in a dis-crete predator-prey model for the behavior of coyotes and jack rabbits in NorthernUtah/Southern Idaho. The basic equations we will examine are

xn+1 = (1 + a)xn(1 − byn) (1.1)

yn+1 = (1 + c)yn

(

1 − yn

k + dxn

)

. (1.2)

The parameters and variables in the equations are given in Table VI.

Table VI. Table of parameters for the Coyotes and Jack rabbits problem.

Variable Description

xn Population density of bunnies, year n

yn Population density of coyotes, year n

a Birth rate of uneaten bunniesb Predation ratec Small – population growth rate of coyotesd Carrying capacity of coyotes per bunnyk Carrying capacity of coyotes without bunnies

Given an initial set of population values, (x0, y0), the two equation recursivelygenerate a series of population values, (xn, yn), in successive years.

As we will see below, a very common occurrence for solutions to these equationsis for one or both species to go extinct, or hit zero population values. Largely thisis because the model above always allows predation to occur; the term bxnyn reflectsthe expected value of predation based on “mass action” assumptions: the idea thatthe rate of individual encounters is proportional to the population densities. In otherwords, this model gives the bunnies no place to hide, and extinction in this modelis analogous to the impact of habitat destruction on a predator-prey system. Theprevalence of extinction in this sort of model reflects the fact that prey species dependvery strongly on heterogeneous environments - having places to hide themselves ortheir young, the presence of refuges, and having some way to avoid contact withpredators.

131

Page 144: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 7. THE SPECTRUM OF EXTINCTION 132

We will start our analysis by defining predator and prey equations and loadingsome Maple packages for later use.

> with(plots):

with(LinearAlgebra):

with(stats):

> prey:=(xx,yy)->(1+a)*xx*(1-b*yy);

pred:=(xx,yy)->(1+c)*yy*(1-yy/(k+d*xx));

> with(VectorCalculus):

prey := (xx, yy) → (1 + a)xx(1 − b yy)

pred := (xx, yy) → (1 + c)yy

(

1 − yy

k + d xx

)

One point to note is that you could include the VectorCalculus package beforeyou define your predator-prey functions. However, if you do this, you would receiveas output

prey := (xx, yy) → (1 + a)xx(1 + V ectorCalculus : −‘ − ‘(b yy)))

pred := (xx, yy) → (1 + c)yy

(

1 + V ectorCalculus : −‘ − ‘

(

yy

k + d xx

))

This occurs because the package overloads the basic arithmetic operations. Yourresults will not change.

2. Steady States and Stability

We will begin by determining equilibrium solutions for the population, and thentry to determine if these steady state solutions are stable in the above model. In adiscrete model like the one we are using, a steady state is reached when there is noyear-to-year change in the population values. The equilibrium solution will satisfy

x = prey(x, y)

y = pred(x, y)

where the prey and pred functions are the ones defined above. We can solve theseequations using Maple in the following manner:

> sstates:=solve({x=prey(x,y),y=pred(x,y)},{x,y});

{x = 0, y = 0},{

x = −−a + ckb + ckba − ca

cdb(1 + a), y =

a

b(1 + a)

}

,

{

x = 0, y =ck

1 + c

}

Here we see that there are three steady state solutions. The only solution thatdoes not have the extinction of one or both species is,

> ss2:=sstates[2];

Page 145: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

2. STEADY STATES AND STABILITY 133

{

x = −−a + ckb + ckba − ca

cdb(1 + a), y =

a

b(1 + a)

}

The stability analysis of a steady state in a discrete model proceeds much as thestability analysis of fixed points in ordinary differential equations. The behavior ofsolutions in the vicinity of a fixed point is controlled by the linearization of the systemnear the fixed point. Write the system of equations in vector form as

vn+1 = F (vn)

where

vn = [xn, yn]T

is a 2 × 1 vector and F is a vector valued function with components given by preyand pred, the right hand side of the model, above. If a steady state solution is givenby a vector w, and we write the solution corresponding to a (small) perturbation as

vn = w + εun,

then the behavior of the perturbation is controlled by the linear system

un+1 = J(w)un.

Here J is the Jacobian matrix of F . We say the equilibrium solution is stable if thesize of the perturbation, un, shrinks over time. That is, for stability we require that

|un+1| ≤ |un|for all perturbations. From linear algebra, since

un+1 = J(w)un,

we know that the stability condition is satisfied only if all of the eigenvalues of J have(complex) magnitude less than one. If any eigenvalue has modulus bigger than one,the fixed point w is unstable (or the perturbation will grow).

Let’s see about the stability of the fixed point determined above. We could com-pute the Jacobian directly using the diff to generate a matrix of all possible partialderivatives.

> Matrix([[diff(prey(x,y),x), diff(prey(x,y),y)],

[diff(pred(x,y),x), diff(pred(x,y),y)]]);

(1 + a)(1 − by) −(1 + a)xb1 + c)y2d

(k + dx)2(1 + c)

(

1 − y

k + dx

)

− (1 + c)y

k + dx

However, since we’ve loaded the VectorCalculus package, we can access the com-mand Jacobian in Maple to generate the exact matrix.

> Jacobian([prey(x, y), pred(x, y)], [x, y]);

Page 146: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 7. THE SPECTRUM OF EXTINCTION 134

(1 + a)(1 − by) −(1 + a)xb1 + c)y2d

(k + dx)2(1 + c)

(

1 − yk+dx

)

− (1 + c)y

k + dx

Notice that with this command, you enter expressions, separated by commas, andthen the variables you wish to compute partials with respect to. Please use squarebraces to surround these two arguments. Curly braces will cause an error.

One very nice feature of the Jacobian command is that you can have Maple

evaluate the Jacobian at an equilibrium, which is what we really require. We wish toconsider the stability of the steady state solution or equilibrium where both speciessurvive.

> jmss:=simplify(Jacobian([prey(x, y), pred(x, y)],

[x, y]=[rhs(ss2[1]), rhs(ss2[2])]));

jmss :=

1−a + ckb + ckba − ca

cdc2d

1 + c1 − c

The simplify command is used to clean up the evaluation process, and the rhs

command is used because the variable ss2 contains two equations, rather than twoexpressions.

We can use Maple to find the eigenvalues of this matrix as follows:

> evals:=Eigenvalues(jmss);

evals :=

−−2 − c + c2 −√

A

2 + 2c

−−2 − c + c2 +√

A

2 + 2c,

where

A = c2 + 2c3 + c4 − 4ca + 4c2kb + 4c2kba − 8c2a + 4c3kb + 4c3kba − 4c3a.

Here we see a pair of eigenvalues. From the form of the eigenvalues it is not clearwhether the fixed point is stable or not. Let’s assign values to all of the parame-ters except one, then examine how the stability is affected by variations in that oneparameter. Since birth rates for the bunnies are the most susceptible to climaticvariations, let’s assign values to all of the parameter except a.

> b:=.18; c:=1.53; d:=1.25; k:=1.03;

Page 147: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

2. STEADY STATES AND STABILITY 135

b := 0.18

c := 1.53

d := 1.25

k := 1.03

With these values the eigenvalues now have the form:

> evals;

0.2350000000 + 0.1976284585√

19.37597575− 34.78139906a

0.2350000000− 0.1976284585√

19.37597575− 34.78139906a

To analyze the stability as a function of a, we could plot the modulus of the eigenvaluesvs a.

> p1:=plot(abs(evals[1]),a=0..2,color=blue):

p2:=plot(abs(evals[2]),a=0..2,style=point,symbol=circle):

p3:=plot(1,a=0..2,linestyle=3,color=black):

display(p1,p2,p3);

The result is shown in Figure 39.

a0 0.5 1.0 1.5 2.0

0

0.2

0.4

0.6

0.8

1.0

1.2

1.4

Figure 39. Stability of eigenvalues in the Coyote-Jack rabbits modelas a function of a.

Note that for values of a between about 0.2 and 1.25 the fixed point is stable, andthat the fixed points for values of a outside that range are unstable. That is, if thebirth rate is either too large or too small, then the steady state solution is unstable.

Page 148: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 7. THE SPECTRUM OF EXTINCTION 136

3. Generating Solutions

In this section we will examine how to use the recursion relations to generatesolutions. We will do this by writing a Maple procedure that will accept as inputinitial population values and return as output the yearly populations and the plotstructures for the graphs of these population values vs time. The following is onesuch way of writing such a procedure:

> pp:=proc(x0,y0)

xd:=Vector(51):

yd:=Vector(51):

xd[1]:=x0:

yd[1]:=y0:

for jj from 1 to 50 do

xd[jj+1]:=max(prey(xd[jj],yd[jj]),0):

yd[jj+1]:=max(pred(xd[jj],yd[jj]),0):

od:

xplot:=plot([seq([jj-1,xd[jj]],jj=1..51)],color=blue):

yplot:=plot([seq([jj-1,yd[jj]],jj=1..51)],thickness=2):

RETURN([xd,yd,xplot,yplot]):

end:

Warning, ‘xd‘ is implicitly declared local to procedure ‘pp‘

Warning, ‘yd‘ is implicitly declared local to procedure ‘pp‘

Warning, ‘jj‘ is implicitly declared local to procedure ‘pp‘

Warning, ‘xplot‘ is implicitly declared local to procedure ‘pp‘

Warning, ‘yplot‘ is implicitly declared local to procedure ‘pp‘

First, note that the warning messages are unimportant and may be ignored. Sec-ond, note that this procedure uses the pred and prey functions and generates outputsxd, yd, xplot, and yplot. Third, note that this procedure will calculate populations for50 years and that the right hand side of the recursive equations have been modifiedso that negative populations can not be generated by the numerical calculations.

To use this procedure we will first need to assign values to all of the parameters.Since we have assigned values to all of the parameters except a in a command lineabove, we will now choose values for a. First we will look at a choice of a for whichthe fixed point is unstable.

> a:=1.4;

a := 1.4

For this value of a, the corresponding steady state is

> ss2;

Page 149: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

3. GENERATING SOLUTIONS 137

{x = 3.463097555, y = 3.240740741}If we choose initial population values near the steady state and call the procedure weget,

> sols:=pp(3.2,3.0);

sols :=

1..51 V ectorcolumn

Data Type : anything

Storage : rectangular

Order : Fortran order

,

1..51 V ectorcolumn

Data Type : anything

Storage : rectangular

Order : Fortran order

, PLOT (...), PLOT (...)

Note that the output to this procedure call is a list of variables, the first two containlists of the yearly populations and the last two contain the plots of the populationsas a function of time in years. If we wish to view the graphs in the plot structureswe could use the display command as follows:

> display(sols[3],sols[4],view=[0..51,-1..6]);

10 20 30 40 50

K1

0

1

2

3

4

5

6

Figure 40. Time series of Bunny-Coyote populations with a = 1.4.

Based on Figure 40, we see that for these initial populations and value of a, the coyotepopulation (in red) goes to zero at about year 24. That is, the coyotes go extinct,leaving no predators for the bunnies, who proceeded to grow without bound. Thisis a common occurrence when the coexistence fixed point is unstable and the bunnybirth rates are high. Additional simulations, which we won’t pursue here, show thatwhen coexistence is unstable and bunny birth rates are low, then the most common

Page 150: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 7. THE SPECTRUM OF EXTINCTION 138

catastrophe is that the bunny population goes extinct, while the coyotes subsist byeating cactus (or in the case of Idaho coyotes, potatoes).

If we try a value of a that generates a stable fixed point then we get the following:

> a:=1.0;

a := 1.0

With a = 1, the steady state is,

> ss2;

x = 2.850655047, y = 2.777777778

and solutions to the model are:

> sols:=pp(3.0,2.0):

> display(sols[3]);

0 10 20 30 40 50

2.2

2.4

2.6

2.8

3.0

3.2

3.4

3.6

3.8

Figure 41. Bunny population with a = 1.

> display(sols[4]);

In Figure 41 and Figure 42 the populations oscillate about the fixed point with theamplitude of the oscillation decreasing until we have almost constant populations.Since we know that bunny and coyote populations do not remain constant fromyear to year, we would conclude that either the birth rate for bunnies is not in astable range, or our model is not quite sophisticated enough to describe the problem.However, as with most real world models, the goal is not to reproduce every detail inthe computer, but to be able to analyze general concepts (in this case about bunniesand coyotes).

Page 151: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

4. THE SPECTRUM OF EXTINCTION 139

0 10 20 30 40 50

2.0

2.2

2.4

2.6

2.8

3.0

3.2

3.4

3.6

Figure 42. Coyote population with a = 1.

4. The Spectrum of Extinction

From a management perspective, we might like to know the probable rate at whicha species is going to go extinct when its refuges are removed. Once land has beenclear-cut, how rapidly must recovery occur to keep native species from going extinct?The model above describes just such a refuge-less ecology, but the question is stillnot easy to answer. Parameters in such a model (particularly birth rates) will varyfrom year to year with climatic changes, and measurements of population density formobile species are error-prone to say the least. To account for all this variability,we will do simulations in which the parameters and the initial values of the speciesvary randomly, but with known probabilities, and examine the probability that theecosystem will collapse in a given year. This probability we refer to as the “spectrumof extinction.”

The most basic piece of information we need to know is not the multi-year historyof a predator-prey system, but the year in which one or the other of the species diesoff. We will accomplish this using the while form of the Maple for loop and a simplecounting algorithm. First let’s design a procedure that returns the year extinctionoccurs given initial values for the populations and a given value of a, the birth rate.One such procedure is as follows.

> extinct:=proc(x0,y0,a0)

global a;

a:=a0:

bn:=x0:

cn:=y0:

years:=0:

Page 152: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 7. THE SPECTRUM OF EXTINCTION 140

for jj from 1 to 50 while (bn>0 and cn>0) do

years:=years+1:

newbn:=prey(bn,cn):

newcn:=pred(bn,cn):

bn:=newbn: cn:=newcn:

od:

RETURN(years):

end:

Warning, ‘bn‘ is implicitly declared local to procedure ‘extinct‘

Warning, ‘cn‘ is implicitly declared local to procedure ‘extinct‘

Warning, ‘years‘ is implicitly declared local to procedure ‘extinct‘

Warning, ‘jj‘ is implicitly declared local to procedure ‘extinct‘

Warning, ‘newbn‘ is implicitly declared local to procedure ‘extinct‘

Warning, ‘newcn‘ is implicitly declared local to procedure ‘extinct‘

Notice the use of the while statement inside the for loop. If the conditions ofthe while are not met, then the loop will be broken and Maple will move on to theRETURN statement. One very important thing to notice, is that a semicolon, not acolon, is used after the global type declaration for our variable a. Please don’t usea colon!

To test to see if this procedure works, try it with the values from the aboveanalysis. For this choice of parameters, we should get a year of extinction of about24.

> extinct(3.2,3.0,1.4);

24

Good. Next define and initialize an array to hold the information we will collect.If we run the above procedure many times and count up how many times extinctionoccurred in year j, then we could build a relative frequency diagram of the likelihoodthat extinction will occur in a given time period. We define a vector of integersinitialized to zero.

> num := Vector(50, datatype = integer, fill = 0):

Now that we have initialized our accumulator, we need only run the above proce-dure multiple times with random inputs (for the initial populations for now) and keeptrack of the year that extinction occurs. Please note that Maple’s rand() commandreturns a 12 digit positive integer. The following loop runs the procedure 1000 timeswith initial bunny populations between 2.5 and 3.5, and initial coyote populationsbetween 2.0 and 4.0.

Page 153: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

4. THE SPECTRUM OF EXTINCTION 141

> for j from 1 to 1000 do

icb:=2.5+rand()*10^(-12):

icc:=2.0+2.0*rand()*10^(-12):

year:=extinct(icb,icc,1.4):

num[year]:=num[year]+1:

od:

Recall that the rand() function call returns a twelve digit number. Hence, the com-mand rand()*10^(-12) generates a number between 0 and 1. If you are concernedabout performance, then you should load the package RandomTools[MersenneTwister]by calling with(RandomTools[MersenneTwister]); and then generate twelve digitnumbers by using the command GenerateInteger(). Our simumlations are smallenough that we won’t bother with this command.

Now the variable, num, holds the frequency distribution of the spectrum of ex-tinction. For instance, out of 1000 simulations, the number of times that extinctionoccurred in year 24 is given by,

> num[24];

59

Note that this value may (and probably will) change each time the loop is executed,so don’t worry if you are following along and get a different value. To plot the relativefrequency of the year of extinction vs. the year we would do the following,

> plot([seq([j,num[j]/1000],j=1..50)],style=point,symbol=box);

We obtain the graph as shown in Figure 43. Again, this may vary depending on thesimulation.

While this graph brings up many interesting questions, the main question we wishto answer at this point is the average time to extinction. This questions is answeredby calculating the mean, or center of mass:

> mass:=add(num[i],i=1..50);

2000

> moment:=add(i*num[i],i=1..50);

moment := 29037

> AverageTimeToExtinction:=evalf(moment/mass);

AverageT imeToExtinction := 14.51850000

Page 154: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 7. THE SPECTRUM OF EXTINCTION 142

10 20 30 40 500.00

0.05

0.10

0.15

0.20

0.25

Figure 43. Relative frequency of the year of extinction vs the yearfor the Coyote-Jack rabbit model.

From this we see that the mean time to extinction for this given value of a is about14 years. Given the multi-modal nature of the graph, this is a number to take witha grain of salt; a large fraction of the populations went extinct well before 14 years.

5. The Spectrum with Parametric Stochasticity

An effect which could potentially have much greater impact than uncertaintyof population measurement would be variations in the parameters of the model, orparametric stochasticity. In an ecological model like the one we are examining, manyof the parameters are “known” only in the loosest sense, and may vary a good dealfrom year to year. Take, for example, the birth rate of the bunnies. In a very coldor dry year, the birth rate will be much lower because offspring have a much moredifficult time surviving in the more difficult environment. We might, therefore, viewthe value of a we examine as being the average of some yearly fluctuation due toclimatic changes. A completely sensible question, then, is how does fluctuations fromyear to year in the birth rates affect the spectrum of extinction?

First we need to create a basic solution procedure, like “extinct” above. In thisprocedure, however, we will build in the capacity for the birth rate, a, and the externalcarrying capacity, k, to fluctuate in some range. The domain of the function we createwill include initial population levels, x0 and y0, the center of the parameter ranges,a0 and k0, and the range of variation (or amount of ± about a0 and k0), called arangeand krange. The range of the function would be the year in which either of the speciesgoes extinct. We will call this function “extinct2”, and define it below:

> unassign(’x0’,’y0’,’a’,’b’,’c’,’d’,’k’,’a0’,’k0’,’arange’,’krange’,

’extinct2’);

Page 155: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

5. THE SPECTRUM WITH PARAMETRIC STOCHASTICITY 143

> b:=.18: c:=1.53: d:=1.25:

> extinct2:=proc(x0,y0,a0,arange,k0,krange)

global a,k;

local years,bn,cn,jj,newbn,newcn;

years:=0:

bn:=x0:

cn:=y0:

for jj from 1 to 51 while (bn>0 and cn>0) do

years:=years+1:

a:=a0-arange+2*arange*rand()*10^(-12):

k:=k0-krange+2*krange*rand()*10^(-12):

newbn:=prey(bn,cn):

newcn:=pred(bn,cn):

bn:=newbn: cn:=newcn:

od:

RETURN(years):

end:

Again, notice that a semicolon is used after the global and local type declarations.Now that we have the function defined, it would be wise to test it and make sure

it works. If we set the range of variation for a and k to zero, we should get the sameanswer as before given we use the other inputs as before:

> extinct2(3.2,3.0,1.4,0.0,1.03,0.0);

24

And the result is 24, just as it should be.Now we can do some simulations, just as before, to determine the spectrum of

extinction. This time, however, we will allow for a fifty percent variation in birthrates and a ninety-nine percent variation in external carrying capacity. Just to makesure it works we will only do a few (100) simulations first.

> num := Vector(50, datatype = integer, fill = 0):

> for j from 1 to 100 do

icb:=2.5+rand()*10^(-12):

icc:=2.0+2.0*rand()*10^(-12):

year:=extinct2(icb,icc,1.4,.65,1.03,1.029):

num[year]:=num[year]+1:

od:

A graph of the relative frequency of this run is shown in Figure 44:

> plot([seq([j,num[j]/100],j=1..50)],style=point,symbol=box);

A run of 1000 iterations gives the following shown in Figure 45.

Page 156: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 7. THE SPECTRUM OF EXTINCTION 144

10 20 30 40 500.00

0.05

0.10

0.15

Figure 44. Relative frequency for the spectrum of extinction in theCoyote–Jack rabbit model with 100 iterations.

> num:=Vector(50, fill = 0):

> for j from 1 to 1000 do

icb:=2.5+rand()*10^(-12):

icc:=2.0+2.0*rand()*10^(-12):

year:=extinct2(icb,icc,1.4,.65,1.03,1.029):

num[year]:=num[year]+1:

od:

> plot([seq([j,num[j]/1000],j=1..50)],style=point,symbol=box);

> mass:=add(num[i],i=1..50);

1000

> moment:=add(i*num[i],i=1..50);

moment := 7865

> AverageTimeToExtinction:=evalf(moment/mass);

AverageT imeToExtinction := 7.865000000

Page 157: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

6. EXERCISES 145

10 20 30 40 500.00

0.02

0.04

0.06

0.08

0.10

0.12

0.14

0.16

0.18

Figure 45. Relative frequency for the spectrum of extinction in theCoyote–Jack rabbit model with 1000 iterations.

Reviewing the results depicted in the above graphs and center of mass calculations,first notice there are differences between 100 and 1000 samples. The more samplesthat are taken, the truer a representation of the actual distribution of collapse times.The spectrum also displays a lot less natural periodicity, which is sensible since varyingparameters smears out the natural period of the model. The final thing to notice isthat if we do the basic statistics to calculate the mean time to extinction, we findthat the expected time to extinction has dropped to 7.9 years. In this case, themean value reflects the location of a true peak in the spectrum, representing the mostlikely time at which species have become extinct. The fact that this number hasdropped significantly from 14, the value without parametric stochasticity, illustratesa common-sense fact from ecology: environmental fluctuations exacerbate the effectsof habitat destruction.

6. Exercises

7.1 One model for predator-prey interaction between bunnies and coyotes in theinter mountain region of North America is

xn+1 = (1 + a)(xn − bxnyn)

yn+1 = cxnyn + (1 − d)yn

where:• xn is the density of bunnies in year n.• yn is the density of coyotes in year n.• a is the birth rate of bunnies (about 0.8).• b is the rate of predation of bunnies by coyotes (about 0.0735).

Page 158: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

CHAPTER 7. THE SPECTRUM OF EXTINCTION 146

• c is the birth rate of coyotes in presence of bunnies (about 0.03).• d is starvation rate of coyotes in absence of bunnies (about 0.25).

The parameter most susceptible to seasonal variations is the birth rate ofbunnies, a. Typical population density values are about 10 for the bunniesand 5 for the coyote populations.A Write a Maple program using a procedure that will allow you to exper-

iment easily with this system. Inputs should be the population values,the birth rate of bunnies, and the death rate of coyotes. The outputfrom your program should be a single graph showing the two populationsplotted simultaneously. Try a couple of different death rates. How doesaltering the death rate seem to change the dynamics?

B Write a program to examine the spectrum of extinction in this problem.Your program should include the following features:

(i) Some random fluctuation in initial measurements of population lev-els by 50% around some base measurement.

(ii) Random yearly fluctuations in birth and death rates by as much as80% around some base level.

(iii) A relative frequency diagram which illustrates the number of ex-tinctions per year over however many simulations you choose todo.

(iv) A calculation of the expected time to extinction in this model, usingthe data from your simulation.

C Discuss the behavior of the spectrum of extinction and how it relates tothe expected value you calculated.

Page 159: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

Bibliography

[1] S. C. Chapra. Applied Numerical Methods with Matlab for Engineers and Scientists. McGraw-Hill, The McGraw-Hill Companies, Inc., 1221 Avenue of the Americas, New York, NY 10020,2005.

[2] W. Cheney and D. Kincaid. Linear Algebra, Theory and Applications. Jones and Bartlett Pub-lishers, Sudbury, Massachusetts, 1 edition, 2009.

[3] M. H. DeGroot and M. J. Schervish. Probability and Statistics. Addison Wesley, 3 edition, 2002.[4] C. H. Edwards and D. E. Penney. Differential Equations and Boundary Value Problems,

Computing and Modeling. Pearson Education Inc., Upper Saddle River, New Jersey 07458,4 edition, 2008.

[5] C. F. Gerald and P. O. Wheatley. Applied Numerical Analysis. Pearson Education, Inc., 7 edition,2004.

[6] P. G. Hoel, S. C. Port, and C. J. Stone. Introduction to Probability Theory. 1971.[7] R. V. Hogg, J. W. McKean, and A. T. Craig. Introduction to Mathematical Statistics. 6 edition,

2004.[8] W. O. Kermack and A. G. McKendrick. A contribution to the mathematical theory of epidemics.

Proceedings of the Royal Society of London. Series A, Containing Papers of a Mathematical andPhysical Character, 115(772):700–721, 1927.

[9] E. Kreyszig. Advanced Engineering Mathematics. Wiley, 7 edition, 1993.

147

Page 160: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,
Page 161: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

Index

149

Page 162: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

INDEX OF MAPLE COMMANDS 150

Index of Maple Commands

:=, 3, 7=, 7I, 9→, 4’, 43?, 3@, 15@@, 14%, 15

add, 96, 126array, 37

CharacteristicPolynomial, 63composition, see @convert, 91currentdir, 84, 91

D, 13derivative

equation, see Dexpression, see diffhigher order, see @@

diff, 13Dimension, 85display, 35do, see for or whiledsolve, 31

general form, 33options, 34

listprocedure, 34numeric, 34

else, see ifequation

defining, see =root, see solve

approximation, see fsolveexpand, 5expression

defining, see :=

factorintegers, 5polynomials, 5

Fit, 97fit, 84font, 43for, 37fsolve, 9function

definition, see →evaluating, 4

help, see ?

if, 124importdata, 84Int, 16int, 16integration, see int

inert, see Intinterface, 97

rtablesize, 97interpolating

polynomialLagrange, 77

interpolationcommand

PolynomialInterpolation, 81

left hand side, see lhslhs, 8limit, 10

infinite, 10left handed, 11right handed, 11undefined, 11

Maple packages, see packagesMatrix, 21

Creation Shortcut, 21default values, 21fill, 22

Page 163: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

INDEX OF MAPLE COMMANDS 151

shape, 21matrix

addition, 23determinant, 64eigenvalues, 27eigenvectors, 27multiplication, 23scalar multiplication, 23subtraction, 23trace, 64

od, see for or whileoutput

referencing last, see %

packagesCurveFitting, 81LinearAlgebra, 20plots, 35stats, 84

plot, 2axesfont, 43color, 35font, see fontlabelfont, 43labels, 43options, 35parametric, 35range, see rangestyle, 35symbol, 35title, 43titlefont, 43

polynomialfactor, see factor

proc, 125product, 77

rand, 87, 124range

horizontal, 2default, 2

vertical, 3, 4default, 4

readdata, 91

regressionfit, 91

restart, 20rhs, 8right hand side, see rhsroot, see solve

approximation, see fsolvecomplex, 9

RootOf, 8rsolve, 128

seq, 36simplify, 6solve, 7stats

seepackagesstats, iSubMatrix, 91subs, 3sum, 79system

linear solution, 24

then, see if

unapply, 32unasign quotes, 43unassign, 32unevaluation quotes, 78

Vector, 21Creation Shortcut, 21orientation, 97

while, 124

Page 164: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

INDEX OF SUBJECTS 152

Index of Subjects

O , 50k-step transition matrix, 115

asymptotehorizontal, 11slant, 11vertical, 12

basis, 59canonical, 59

biased, 111

chain rule, see derivative, chain rulecharacteristic equation

difference equation, 118characteristic polynomial, 63chemostat, 53

dependent, see linearly dependentderivative, 12

chain rule, 14product rule, 14quotient rule, 14

differential equationinitial condition, 31linear, 31system, 33

differential equationssystems

phase space, 34state space, 34

dimension, 59

equationroot, 6systems of linear, 19

equilibrium solutioncontinuous, 48

semi-stable, 53discrete, 132

event, 109expected value, 111

conditional, 113expression, 3

fair, 110first step analysis, 117function, 1, 4

Gambler’s Ruin, 116

IC, see initial conditionindependent, see linearly independent,

110, 114integrable, 15integral

definite, 15indefinite, 15

interpolatingleast squares, 83linear regression, 82polynomial

Lagrange, 77trigonomatric, 83

interpolating function, 76interpolation, 76

piecewise linear, 76polynomial, 76

Lagrange, 76

Jacobian matrix, 58, 133

least squaresseeinterpolating

least squares, ilimit, 10

left handed, 10right handed, 10

linear regressionseeinterpolating

linear regression, ilinearly dependent, 59linearly independent, 59list, 71

Page 165: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

INDEX OF SUBJECTS 153

combining, 74element, 71graph, 71subset, 73, 74

logistic model, 44

Malthusian model, 41Markov chain

discrete time, 114Markov property, 114mass action, 131matrix, 19

addition, 22augmented, 20coefficient, 19defective, 28determinant, 62

2 × 2, 63diagonal, 21eigenvalue, 26

multiplicity, 26eigenvector, 26

generalized, 61identity, 21inverse, 24Kernel, 26multiplication, 22null space, 26scalar multiplication, 22singular, 24size, 19square, 19stochastic, 115subtraction, 22symmetric, 21trace, 62transpose, 21triangular

lower, 21upper, 21

mean, 111condition, 113

order ε, 50

predation, 131predator-prey, 33, 131probability

k-step transition, 115conditional, 110event, 109induced, 110one-step transition, 114

nonstationary, 114stationary, 114

set function, 109probability mass function, 111

conditional, 113joint, 112marginal, 112

product rule, see derivative, product rule

quotient rule, see derivative, quotientrule

random variable, 109continuous, 109discrete, 109space, 109

rangehorizontal, 2vertical, 4

regressionnonlinear

basis function, 91error, 99full, 98weights, 91

relation, 1root, see equation, root

sample path, 114sample space, 108set of outcomes, 108spans, 59stability

continuous, 49behavior, 50

stability analysisdiscrete, 133

Page 166: Tarleton State University€¦ · Computer Aided Math with Maple Peter W. White Keith E. Emmert (P. W. White) Department of Mathematics, Tarleton State University Current address,

INDEX OF SUBJECTS 154

state space, 112steady state solutions, see equilibrium

solutionsstochastic process

discrete time, 114

transition matrix, 115

unbiased, 110unstable equilibrium

continuous, 49

variance, 111condition, 113

vector, 19dot product, 22matrix of unknowns, 20right hand side, 20

Verhulst, 44