Download as pdf or txt
Download as pdf or txt
You are on page 1of 45

Numerical Methods using Maple Software

Objective:

✓ Nonlinear equations
✓ Function and data approximation
✓ Numerical differentiation and integration
✓ System of Linear equations
✓ First-order differential equations – numerical solution using Euler method, Runge-
Kutta method, round off error

Nonlinear equations(finding roots)


Bisection Method

• The Bisection command numerically approximates the roots of an algebraic function, f,


using a simple binary search algorithm.•
• Given an expression f and an initial approximate a, the Bisection command computes a
sequence 𝑝𝑘 , 𝑘 = 0. . 𝑛, of approximations to a root of f, where n is the number of
iterations taken to reach a stopping criterion. This sequence is guaranteed to converge
linearly toward the exact root, provided that f is a continuous function and the pair of
initial approximations bracket it.
• The Bisection command is a shortcut for calling the Roots command with the
method=bisection option.
• Calling Sequence
Bisection(f, x=[a, b], opts)
Bisection(f, [a, b], opts)
• Parameters:
f - algebraic; expression in the variable x representing a continuous
function
x - name; the independent variable of f

a - numeric; one of two initial approximates to the root

b - numeric; the other of the two initial approximates to the root

opts - (optional) equation(s) of the form keyword=value, where keyword is


one of functionoptions, lineoptions, maxiterations, output,
pointoptions, showfunction, showlines, showpoints,
stoppingcriterion, tickmarks, caption, tolerance,
verticallineoptions, view; the options for approximating the roots of
f

1
Example
Use Bisection method to find solutions accurate to within 10−2 for the following problems.
𝑓(𝑥) = 𝑥 3 − 7𝑥 2 + 14𝑥 − 6 [2.7,3.2]

Solution:

>
>
>

>

>

>

>

2
Secant Method
• The Secant command numerically approximates the roots of an algebraic function, f,
using a technique similar to Newton's method but without the need to evaluate the
derivative of f.
• Given an expression f and an initial approximate a, the Secant command computes a
sequence 𝑝𝑘 , 𝑘 = 0. . 𝑛, , of approximations to a root of f, where n is the number of
iterations taken to reach a stopping criterion.
• The Secant command is a shortcut for calling the Roots command with the
method=secant option.
• Calling Sequence
o Secant(f, x=[a, b], opts)
o Secant(f, [a, b], opts)
• Parameters
f - algebraic; expression in the variable x representing a continuous function
x - name; the independent variable of f
a - numeric; one of two initial approximates to the root
b - numeric; the other of the two initial approximates to the root
opts - (optional) equation(s) of the form keyword=value, where keyword is one
of functionoptions, lineoptions, maxiterations, output,
pointoptions, showfunction, showlines, showpoints,
showverticallines, stoppingcriterion, tickmarks, caption,
tolerance, verticallineoptions, view; the options for approximating
the roots of f

Example

Consider the function 𝑓 (𝑥) = 𝑥 3 − 7𝑥 2 + 14𝑥 − 6 = 0. Approximate a root of f using


Secant Method

Solution:

>

3
>
>

>

>

To play the following animation in this help page, right-click (Control-click, on Macintosh) the
plot to display the context menu. Select Animation > Play.
>

>

4
Newton Method
• The Newton command numerically approximates the roots of an algebraic function, f,
using the classical Newton-Raphson method.
• Given an expression f and an initial approximate a, the Newton command computes a
sequence 𝑝𝑘 , 𝑘 = 0. . 𝑛, of approximations to a root of f, where n is the number of
iterations taken to reach a stopping criterion. For sufficiently well-behaved functions
and sufficiently good initial approximations, the convergence of 𝑝𝑘 toward the exact
root is quadratic.
• The Newton command is a shortcut for calling the Roots command with the
method=newton option.
• Calling Sequence
o Newton(f, x=a, opts)
o Newton(f, a, opts)
• Parameters:
f - algebraic; expression in the variable x representing a continuous
function
x - name; the independent variable of f
a - numeric; the initial approximate root
opts - (optional) equation(s) of the form keyword=value, where keyword is
one of fixedpointiterator, functionoptions, lineoptions,
maxiterations, output, pointoptions, showfunction, showlines,
showpoints, showverticalline, stoppingcriterion, tickmarks,
caption, tolerance, verticallineoptions, view; the options for
approximating the roots of f

Example
Use Newton’s method to find solutions accurate to within 10−2 for the following problems.
𝑓(𝑥) = 𝑒 𝑥 + 2−𝑥 + 2 cos(𝑥) − 6 at 𝑥0 = 2.0

Solution:

>
>
>
>

>

>

5
>

Exercise

6
6. Repeat Exercise 5 using the Secant method.

Numerical Integration

• The Quadrature command returns a numerical approximation to the integral of f from a


to b, using the specified method.
• Unless the output = sum option is specified, f must be an expression than can be
evaluated to a floating-point number at all x in the range a..b. Likewise, the endpoints a
and b must be expressions that can be evaluated to floating-point numbers.
• The Quadrature command is similar to the Student[Calculus1][ApproximateInt]
command; however, the Quadrature command provides more methods to approximate
integrals numerically.
• The Quadrature command aims to introduce numerical integration methods, while the
Student[Calculus1][ApproximateInt] command aims to introduce the concept of
integration itself.
• The method of approximating the integral. By default, Simpson's rule is used.
o boole = Boole's rule
o simpson = Simpson's rule
o simpson[3/8] = Simpson's 3/8 rule
o trapezoid = trapezoid rule
o gaussian[N] = N point Gaussian quadrature rule
o romberg = Romberg integration
o newtoncotes[N] = Newton-Cotes method of order N

Trapezoidal Rule:

Simpson’s Rule:

Simpson’s Three-Eighths rule:

7
Example 1:
2
Compare the Trapezoidal rule and Simpson’s rule approximations to ∫0 𝑓(𝑥)𝑑𝑥 when 𝑓 (𝑥)
is

Solution:

>
>

>

>

>

>

>

>

8
>

INTEGRAL: Int(1/(x+1),x=0..2) = 1.09861229


APPROXIMATION METHOD: Trapezoidal Rule
---------------------------------- INFORMATION TABLE -----------------
-----------------
Approximate Value Absolute Error Relative Error
1.10156233 0.002950038 0.2685 %
----------------------------------------------------------------------
-----------------
Number of Function Evaluations: 11
>

INTEGRAL: Int(1/(x+1),x=0..2) = 1.09861229


APPROXIMATION METHOD: Simpson's Rule
---------------------------------- INFORMATION TABLE -----------------
-----------------
Approximate Value Absolute Error Relative Error
1.0986155 3.216e-06 0.0002927 %
----------------------------------------------------------------------
-----------------
Number of Function Evaluations: 21

Example 2:
48
Approximate the following integrals using the Trapezoidal rule ∫0 √1 + cos(𝑥)2 𝑑𝑥 using
Simpson's 3/8 rule

Solutions:

>
>
>

9
>
• The command to numerically approximate the integral of the expression above using
Simpson's 3/8 rule is
>

The command to create a plot of the above approximation is


>

>

INTEGRAL: Int((1+cos(x)^2)^(1/2),x=0..48) = 58.4704692


APPROXIMATION METHOD: Simpson's 3/8 Rule
---------------------------------- INFORMATION TABLE -----------------
-----------------
Approximate Value Absolute Error Relative Error
58.490286 0.01981681 0.03389 %
----------------------------------------------------------------------
-----------------
Number of Function Evaluations: 61

Exercise:

1. Use the Composite Trapezoidal rule with the indicated values of n to approximate the
following integrals.

10
2. Use the Composite Simpson’s rule to approximate the integrals in Exercise 1.
2
3. Approximate ∫0 𝑥 2 𝑙𝑛(𝑥 2 − 1) 𝑑𝑥 using ℎ = 0.25. Use
a. Composite Trapezoidal rule.
b. Composite Simpson’s rule.
c. Composite Simpson’s 3/8 rule.

Differential Equations
• dsolve solves many equations in terms of these functions. But many other differential
equations cannot be solved explicitly in terms of the functions of calculus.
• Consider, for example, the equation

• When we cannot solve a differential equation in this way, or if the formula we find is too
complicated, we turn to numerical methods to solve initial value problems

• We illustrate the use of the numerical version of dsolve by considering the initial
valuue problem
𝑑𝑦 𝑡
= , 𝑦(0) = 1 (7.1)
𝑑𝑥 𝑦

• Its exact solution is easily found to be


𝑦(𝑡) = √𝑡 2 + 1

• Since we have an explicit formula for this solution, we will be able to compare the
approximate solution 𝑦𝑎 (𝑡) and the exact solution 𝑦(𝑡).
• Commands for dsolve(...,numeric) are similar to those for dsolve. To obtain 𝑦𝑎 (𝑡), first
enter the command

>

>

>

11
>

>

>

𝑑𝑦 𝑡
Figure 7.1: Numerical Solution of 𝑑𝑡 = 𝑦 , 𝑦(0) = 1

• The result is shown in Figure 7.1. Note however that the command plot (ya(t), t =0.2)
results in an error message, because the function 𝑦𝑎 allows only numerical input.

Exercise 7.1 Display both 𝑦𝑎 (𝑡) and the exact solution 𝑦(𝑡) = √𝑡 2 + 1 on the same graph.
Can you distinguish between the two curves?

• To compare the numerical solution with the exact solution we can make a table listing
the values of each of the functions at various points.
• First, we define a function that produces the entries in each row.
• To do this type

>

>
> :
>

12
Example
Consider
𝑑𝑦
= 𝑡 + 𝑦2, 𝑦(0) = 1 (7.2)
𝑑𝑥

which cannot be solved in terms of elementary functions


The following commands will produce an approximate solution:

Solution:
>

>

>

>

Exercise 7.2 The solution 𝑦(𝑡) to (7.2) is increasing for t positive, and there is a finite value
t such that lim∗ 𝑦(𝑡) = ∞; the interval of existence of the solution is (−∞, 𝑡 ∗ ). Execute the
𝑡→𝑡
previous two commands and the command plot(y2a, 0..1, 0.100). The picture should tell
you roughly where 𝑡 ∗ is located. Now try to evaluate y2a both a bit to the left and a bit to
the right of this value. Does Maple's response reveal the value of 𝑡 ∗ ?

13
Numerical Methods

• This is Maple's numerical differential equation solver, and will be denoted We by


dsolve(..., numeric).

Calling Sequence

dsolve(odesys, numeric, method=classical)


dsolve(odesys, numeric, method=classical[choice], vars, options)
dsolve(numeric, method=classical[choice], procopts, options)

Parameters

odesys - set or list; ordinary differential equation(s) and initial


conditions
numeric - literal name; instruct dsolve to find a numerical
solution
method=classical - literal equation; numerical method to use
method=classical[choice] - equation; numerical method and submethod to use
vars - (optional) dependent variable or a set or list of
dependent variables for odesys
options - (optional) equations of the form keyword = value

procopts - options used to specify the ODE system using a


procedure (procedure, initial, start, number, and
procvars). For more information, see
dsolve[numeric,IVP].

• A number of classical methods are available through use of the choice option in the
method=classical[choice] selection.
o The default is foreuler, the forward Euler method.
o heunform is the Heun formula (also known as the improved Euler method).
o impoly is the improved polygon method (also known as the modified Euler
method),
o rk2 is the second-order classical Runge-Kutta method. This is the same as the Heun
formula.
o rk3 is the third-order classical Runge-Kutta method,
o rk4 is the fourth-order classical Runge-Kutta method,
o adambash is the Adams-Bashforth method (a predictor method),

14
o abmoulton is the Adams-Bashforth-Moulton method (a predictor-corrector
method),
• In order to give some idea about how dsolve(... , numerie) calculates approximate
values, we are going to discuss several numerical methods. We will apply each method
to problem (7.1).
• We want to approximate the solution of the initial value problem

𝑑𝑦
= 𝑓(𝑡, 𝑦), 𝑦(𝑡0 ) = 𝑦0
𝑑𝑥

on an interval to 𝑡0 ≤ 𝑡 ≤ 𝑏. For n a positive integer, we divide the interval into n parts using
points to

𝑡0 < 𝑡1 < 𝑡2 … < 𝑡𝑛 = 𝑏.

• For simplicity, we assume that each part has the same width, or step size, ℎ = 𝑡𝑖+1 − 𝑡𝑖 =
(𝑏 − 𝑡0 )/𝑛; therefore 𝑡𝑖 = 𝑡0 + 𝑖ℎ. At each point 𝑡𝑖 we seek an approximation, which we
call 𝑦𝑖 , to the true solution 𝑦(𝑡𝑖 ) at 𝑡𝑖 :
• Its exact solution is easily found to be

𝑦(𝑡𝑖 ) ≈ 𝑦𝑖

The Euler Method


The simplest numerical solution method is due to Euler and 1s based on the tangent line
approximation to a function. Given the initial value 𝑦0 , we define 𝑦𝑖 recursively by

𝑦𝑖+1 = 𝑦𝑖 + ℎ𝑓(𝑡𝑖 , 𝑦𝑖 ), 𝑖 = 0,1, . . . , 𝑛 − 1.

Example 7.1 Consider the initial value problem (7.1):

𝑑𝑦 𝑡
= , 𝑦(0) = 1 (7.1)
𝑑𝑥 𝑦
We wish to approximate 𝑦(0.3) using the Euler Method with step size ℎ = 0.1 and three steps.
We find
>
>
>

15
>

>

>

The Improved Euler Method

𝑦𝑖′ + 𝑓(𝑡𝑖+1 , 𝑦𝑖 + ℎ𝑦𝑖′ )


𝑦𝑖+1 = 𝑦𝑖 + ℎ , 𝑖 = 0,1, . . . , 𝑛 − 1.
2

Example 7.2 We again consider problem (7.1) and find an approximation to y(0.3) with
h = 0.1. We oblain
>

>

16
>

>

The Runge-Kutta Method


Given the initial value 𝑦0 . the fourth order Runge-Kutta Method is defined recursively by

>

>

>

>

17
• Comparison Errors
>

>
>
>

Controlling the Error in dsolve(... , numeric)


• The solver dsolve(... , numeric) attempts to provide an accurate by approximate
solution controlling the discretization error. The procedure controls both the absolute
error
▪ Absolute Error = |𝑦(𝑡) − 𝑦𝑎 (𝑡)|
• and the relative error
|𝑦(𝑡)−𝑦𝑎 (𝑡)|
▪ Relative Error= 𝑦(𝑡)
• The default error tolerance for the absolute error is 10−7 and for the relative error the
default is 10−6. With these tolerances, dsolve(..., numeric) attempts to approximate
y(t) with total error less than (10−7 + 10−6 |𝑦(𝑡)|). By imposing more stringent tolerances,
more accurate approximate solution might be obtained. The default changed by including

18
options that tolerances can be specify tolerance values. For example, using the default
command
>

>

>

>

>

>

>

>

gives a solution value of the initial value 2.23606805572581, which problem (7.1) at t = 2 of is
an eight-digit approximation to the exact value √5. The command

>

>

>

>

19
Changes the tolerances and yields the value 2.23606797749999 at 𝑡 = 2, which is a 13 digit
approximation to the exact value. The default values will be satisfactory for most of the problems
in this book. For other problems, however, greater accuracy will be required.

Example 7.4 Consider the initial value problem

The exact solution is 𝑦(𝑡) = 𝑒 −2𝑡 . Now we find the numerical solution using dsolve(. .. ,
numeric), and plot it (with a dashed line) together with the exact solution (with a solid
line):

>

>

>

>

Figure 7.2: Exact (solid line) and Approximate (dashed line) Solutions

20
Let's do this with our example. Specifically, we calculate and plot the numerical solution,
ya2, satistying more stringent accuracy requirements, together with the first numerical
solution, yal, and the exact solution, y. We display the exact solution with a solid line, yal
with a dashed line, and ya2 with a dotted line.

>

>

>

>

Figure 74: Effect of Increased Accuracy

21
Exercises

22
23
Solving and Analyzing Second Order Linear Equations

• The most basic second order differential equations are linear equations with constant
coefficients:

𝑎𝑦′′ + 𝑏𝑦′ + 𝑐𝑦 = 𝑔(𝑡).

• These equations model a wide variety of physical situations, including oscillations of springs,
simple electric circuits, and the vibrations of tuning forks to produce sound and of electrons
to produce light.
• Unfortunately, we often cannot find solution formulas for more general second order
equations, even for linear equations with variable coefficients:

𝑦′′ + 𝑝(𝑡)𝑦′ + 𝑞(𝑡)𝑦 = 𝑔(𝑡).

• Such equations have important applications to physics. For example, Airy's equation,

𝑦′′ − 𝑡𝑦 = 0,

arises in diffraction problems in optics, and Bessel's equation,

24
1
𝑦′′ + 𝑡 𝑦′ + 𝑦 = 0,

• Occurs in the study of vibrations of a circular membrane and of water waves with circular
symmetry.

Second Order Equations with Maple

Example 9.1 Consider the differential equation

𝑦 ′′ + 𝑦 ′ − 6𝑦 = 20𝑒 𝑡 . (9.3)

We can get a solution by typing:

>

>

As expected, the general solution depends on two arbitrary constants. To solve the
differential equation with initial conditions 𝑦(0) = 0 and 𝑦’(0) = 1, we would type:

>

Maple can also solve some boundary value problems. Let's continue using the same
differential equation, and consider the boundary conditions 𝑦(0) = 0 and 𝑦(𝑙𝑛(2)) = 10.
We get the solution of the boundary value problem by typing:

>

Example 9.2 Now consider the linear second order differential equation

𝑦′′ + 𝑡 2 𝑦′ + 𝑦 = 0. (9.4)

Maple is unable to find an explicit formula for the general solution. Instead, we can use
dsolve(..., numeric) to find a numerical solution. The numerical solution with initial
conditions 𝑦(0) = 1, 𝑦′(0) = −1 can be found by typing

>

and it can be plotted using the techniques developed in previous Chapter.

25
• A good way to understand the behavior of a general solution of a second order equation is to
plot numerical solutions corresponding to a wide range of initial values and initial slopes.
• For this example, to plot solutions satisfying the twenty five initial conditions 𝑦(0) =
−2, −1, 0, 1,2 and 𝑦′(0) = −1, −0.5, 0,0.5, 1 we use the Maple command DEplot (which is
found in the DEtools package). Here are the commands to do this.
>

>

>
>

• The result is shown in Figure 9.1. We see that the solutions seem to level off for positivet and
seem to blow up for negative t.

Figure 9.1: Numerical Solutions of (9.4)

• Finally, let's look at the boundary value problem

𝑦′′ + 𝑡 2 𝑦′ + 𝑦 = 0, 𝑦(0) = 0, 𝑦(1) = 1. (9.5)

• Here we have the same differential equation, but we have specified values of the solution at
two different points; y(0) = 0 and y(1) = 1 are called boundary conditions. This time dsolve
cannot find a solution, so we discuss two alternate approaches. The first is called the
shooting method. Consider the initial value problem

𝑦′′ + 𝑡 2 𝑦′ + 𝑦 = 0, 𝑦(0) = 0, 𝑦′(0) = 𝑠. (9.6)

26
where the first initial condition is the first boundary condition, and in the second initial
condition, the slope at t = 0 is specified by the parameter s. Since for any value of s, the solution
of this initial value problem satisfies the first boundary condition in (9.5), if we find the value s =
8for which the solution satisfies the second boundary condition in (9.5). then the solution of (9.6)
with s = 5 will be the solution of our boundary value problem. 8 is usually found by selecting
various numerical values for s, and solving the initial value problem (9.5) numerically with
dsolve, with an eye to finding a value for s for which the Second boundary condition in (9.5) is
satisfied.
• The following commands can be used to

>

>

• The command trial(s) evaluates the numerical solution of the initial value problem with
𝑦(0) = 0 and 𝑦′ (0) = 𝑠 at 𝑡 = 1. After some trial and error, one finds in this case
that
>

• So the solution to the boundary value problem is (approximately) the numerical


solution of the initial value problem with initial conditions y(0) = 0 and𝑦′(0) = 1.278.
• We note that certain initial value problems, with a differential equation similar to that
of (9.6), can be solved symbolically with dsolve for general s. If the resulting solution is
denoted by 𝑦(𝑡, 𝑠), then 𝑠̅ can be found by solving 𝑦(1, 𝑠) = 1 with solve or fsolve.
• A second approach is to use dsolve(..., numeric) with boundary values specified. The
commands that follow show how to find and plot the (numerical) solution, which is
shown in Figure 9.3.

>

>

>

27
Figure 9.3: Solution of a Boundary Value Problem with dsolve(..., numeric)

Numerical Solutions of Higher Order Differential Equations

• In Chapter 7, we showed how to produce numerical solutions of first order an be


problems using dsolve(... , numeric).
• Higher order initial value problen solved using essentially the same procedure. Here is
an example using dsolve(…,numeric) to solve a third order initial value problem.

>
>

>

>

>

>
>

28
• We could produce the same figure using DEplot, which also allows us to specify initial
condition for the derivatives in a higher order differential equation.
• The corresponding command is

>
>

Numerical Solutions of First Order Systems


• The symbolic solver dsolve should be able to solve any homogeneous 2x 2 linear system
with constant coefficients. For inhomogeneous linear systems, linear systems with
variable coefficients, and nonlinear systems, dsolve will generally not do the job.
• In these situations, we turn to the numerical solver dsolve(... , numeric) or to DEplot.
Suppose we wish to solve the initial value problem

29
for a first order system of differential equations. This initial value problem can be written
in vector form as follows:

Stability of linear systems(for reference click here)

• We can use dsolve(... , numeric) on this system much as we used it on a single first
order equation. We illustrate with the initial value problem

>

>

>

30
You can also extract functions that approximate 𝑥(𝑡) and 𝑦(𝑡), as in Chapter 7. For example,
after running dsolve(... , numeric) as above, the following commands extract and plot the
approximate solution.

>
>
>

• Note that we did not type 𝑥𝑎(𝑡) and 𝑦𝑎(𝑡) in the plot command; this is because the
functions 𝑥𝑎 and 𝑦𝑎 allow only numerical input.
• Though it is possible to produce phase portraits with dsolve(. .* , numeric) and plot,
the procedure is cumbersome.

31
• It is simpler to use DEplot (from the DEtools package), which we introduced in Chapter
8. For example, you can type

>
>

>

>

• The procedure for plotting a phase portrait also works if you wish to vary only one parameter
in the initial data. For example, consider the initial value problem

𝑥 ′ = 𝑥 + 2𝑦, 𝑦′ = −𝑥; 𝑥(0) = 𝑎, 𝑦(0) = 0


• for various values of a. The commands

>

>

32
>

>
>

• Finally, we note that DEplot also works for systems of more than two equations, and for
time-dependent (nonautonomous) systems. An important option in these cases is scene,
which is used to specify a pair of variables to plot. For example, you can get a plot Of
versus t for a trajectory of the above system by typing:

>

33
Qualitative Theory for Systems of Differential Equations

Vector fields can be drawn by hand for simple systems, but the command fieldplot can
draw vector fields of any first order system of two equations. We illustrate the drawing of
vector fields by examining two specific systems, namely

• System (13.3) is a predator-prey model with logistic growth (for the prey).
• The command fieldplot is contained in the plots package. The following sequence of
commands draws a vector field for system (13.2):
• >
• >

Figure 13.1: Vector Field for System (13.2).

• A Simple way to see the directions of vectors near the critical points is to replace
fieldplot with dfieldplot. This command is contained in the DEtools package; we
used it previously to plot the direction field of a single first order differential
equation.
• It produces plots in which every vector has the same length. The drawback, of
course, 1s that it may be harder to locate the critical points (since there are no short
arrows); the Compensating benefit is that we can see the directions more clearly.
• Here is the command we use to plot the "equal length" vector field.

34
>

• The third argument t = 0..1 is irelevant to the vector field plotted in this example, but
the syntax of dfieldplot requires that some range be specified for the independent
variable t. The result is shown in Figure 13.2.

Figure 13.2: Improved Vector Field for System (15.2)

Exercises

1. In this problem, we'll investigate the effect of damping on the pendulum, using the
model
𝜃′′ + 𝑏𝜃′ + 𝑠𝑖𝑛 𝜃 = 0.

a) Define a Maple function of b that will find a numerical solution of this differ equation
with the initial conditions 𝜃(0) = 0, 𝜃′ (0) = 4.
b) For 𝑏 = 0.5, 1, 𝑎𝑛𝑑 2, plot these solutions from 𝑡 = 0 𝑡𝑜 𝑡 = 20.
c) Do the same for the linear approximation

𝜃′′ + 𝑏𝜃′ + 𝜃 = 0.

d) Compare the linear and nonlinear behavior for these values of b. Interpret what is
happening physically in each case; i.e., describe explicitly what the graph says the
pendulum is doing.

35
Solution:
Part (a)
>

>

Part (b)

>

>

>

>

>
>

>
Part (c)

>

36
>

>

>

>

>

>

>

37
>

>

>

>

38
2. Consider the predator-prey model

in which 𝑥 ≥ 0 represents the population of the prey and 𝑦 ≥ 0 represents the population
of the predators.
a) Find all critical points of the system. At each critical point, calculate the
corresponding linear system and find the eigenvalues of the coefficient matrix; then
identify the type and stability of the critical point.
b) Plot the vector field on a region small enough to distinguish the critical points but
large enough to judge the possible solution behaviors away from the critical points.
c) Use several initial data points (zo, yo) in the first quadrant to draw a phase portrait
for the system. Identify the direction of increasing t on the trajectories you obtain.
Use the information from parts (a) and (b) to choose a representative sample of
initial conditions. Then combine the vector field and phase portrait on a single
graph.
d) Explain from your phase portrait how the populations vary over time for initial data
close to the unique critical point inside the first quadrant. What happens for initial
data far from this critical point?
e) Suppose the initial state of the population is given by
𝑥(0) = 1, 𝑦(0) = 1.
Find the state of the population at t = 1,2,3, 4,5.
f) Estimate to two decimal places the period of the solution curve that starts at (1,1).

Solution:

a) Use solve to find the critical points

>
>

>

Part (a): stability


First, we compute the Jacobian matrix "A" of partial derivatives of the system. This could be
done entry by entry, but there is a command called Jacobian, located in the
VectorCalculus package, which will calculate the matrix. Then we find the eigenvalues of
the Jacobian at each of the critical points. We do not report all the zero decimal values nor
the zero coefficients of I that Maple returns. Finally, we classify the critical points

39
>

>

Thus, (0,0) is an unstable saddle point.


>

Thus, (2,4/3) the system oscillate around the steady state

Part (b): vector field


Figure shows a plot of the vector field of the system. The critical points at (0,0) and at
(2,4/3) are easy to recognize and the direction of the vector field is rapidly changing in this
area.

>

>

>

40
Part (c): first attempt
To plot the phase portrait of the system, we are going to use the command DEplot, which is
in the DEtools package. We first use a rectangular grid to generate different initial
conditions. The vector field above makes it clear which direction the solutions are going in
the portrait below as t increases. Many of the solutions rapidly approach infinity as t
decreases through negative values. Without the option stepsize = 0.01 in the command
below. Maple would give multiple warnings before drawing the portrait. We first calculate the
initial values and then plot the phase portrait.

>

>

>

Figure Sols.17: Phase Portrait, First Attempt

Part (c): improved portrait


The rectangular grid of initial conditions yields unevenly spaced solution curves. Since the
solutions rapidly approach a curve connecting the fixed points (1.5, 0) and (0,4/3) and then
move along a path close to this curve as t increases, we can get a cleaner phase portrait by
choosing initial conditions along two parallel lines above and below this curve. Let's use the
lines from (1,0) to (0, 2.5) and from (2,0) to (0,5). We define two sets of initial values, one
for each line, take their union, and then plot the phase portrait.

>

41
>

>
>

Figure Sols.19: Vector Field and Phase Portrait for Problem 6

42
Part (d): table of population values
Here is a table of the population from times 0 to 20. The population change rapidly
between t = 0 and t = 1.

>

>

>
>

3. Consider the competing species model (Boyce and DiPrima, Prob. 4, Sect. 9.4)

For 𝑥, 𝑦 ≥ 2 0.

a) Find all critical points of the system. At each critical point, calculate the
corresponding linear system and find the eigenvalues of the coefficient matrix; then
identify the type and stability of the critical point.
b) Plot the vector field on a region small enough to distinguish the critical points but
large enough to judge the possible solution behaviors away from the critical points.
c) Use several initial data points (to, yo) in the first quadrant to draw a phase portrait
for the system. Identify the direction of increasing t on the trajectories you obtain.
Use the information from parts (a) and (b) to choose a representative sample of
initial conditions. Then combine the vector field and phase portrait on a single
graph.
d) Suppose the initial state of the population is given by

𝑥(0) = 0.1, 𝑦(0) = 0.1.

Find the state of the population att = 1,2,3,4,5,...,20.

43
Solution:

a) Use solve to find the critical points

>
>

>

Part (a): stability


First, we compute the Jacobian matrix "A" of partial derivatives of the system. This could be
done entry by entry, but there is a command called Jacobian, located in the
VectorCalculus package, which will calculate the matrix. Then we find the eigenvalues of
the Jacobian at each of the critical points. We do not report all the zero decimal values nor
the zero coefficients of I that Maple returns. Finally, we classify the critical points

>

>

Thus, (0,0) is an unstable node.


>

Thus, (0,0.75) is an unstable node.


>

Thus, (3,0) is an unstable node.

>

Thus, (2,0.5) is an stable node.

44
Part (b): vector field
Figure Sols.16 shows a plot of the vector field of the system. The critical points at (0,0)
and at (0,4) are easy to recognize, but the other two critical points are less clear. The latter
two points, at (1.5,0) and at (1, 1), are relatively close to each other, and the direction of
the vector field is rapidly changing in this area.

>

>

>

Figure Sols. 16: Vector Field for Problem 6

45

You might also like