Escolar Documentos
Profissional Documentos
Cultura Documentos
Dierential Equations
0.5
1.5 1 0.5 0 .5 1
0
0.5
1.5
Dierential equations are an important part of many areas of mathematics, from uid
dynamics to celestial mechanics. They are used by applied mathematicians, physicists
and engineers to help in the designing of everything from bridges to ballistic missiles.
Except for a few special cases, dierential equations cannot normally be solved an-
alytically. Instead, there are many numerical methods which have been developed to
provide solutions.
This report will investigate several methods, including Eulers method, Runge-Kutta
and the Trapezium rule. Concentrating on Keplers equations, we will investigate the
accuracy of the methods and nd a way to reduce the error to an acceptable tolerance
level.
Contents
0 Introduction 4
0.1 Dierential Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
0.2 Analytical Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
0.3 Numerical Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2 Numerical Methods 11
2.1 Forward Eulers Method . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2 Backward Eulers Method . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.3 Trapezium Rule Method . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.4 Errors in Numerical Methods . . . . . . . . . . . . . . . . . . . . . . . . 15
2.4.1 Forward Eulers Method . . . . . . . . . . . . . . . . . . . . . . . 16
2.4.2 Backward Eulers Method . . . . . . . . . . . . . . . . . . . . . . 16
2.4.3 Trapezium Rule Method . . . . . . . . . . . . . . . . . . . . . . . 17
2.5 Symmetric Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.6 Extension to Higher Order ODE . . . . . . . . . . . . . . . . . . . . . . 19
3 Periodic Solutions 21
3.1 Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.2 Application of Numerical Methods . . . . . . . . . . . . . . . . . . . . . 22
3.3 Error Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
1
CONTENTS CONTENTS
A Biographies 51
A.1 Sir Isaac Newton (1643-1727) . . . . . . . . . . . . . . . . . . . . . . . . 51
A.2 Leonhard Euler (1707-1767) . . . . . . . . . . . . . . . . . . . . . . . . . 52
A.3 Carle David Tolme Runge (1856-1927) . . . . . . . . . . . . . . . . . . . 54
A.4 Martin Wilhelm Kutta (1867-1944) . . . . . . . . . . . . . . . . . . . . . 55
A.5 Johannes Kepler (1571-1630) . . . . . . . . . . . . . . . . . . . . . . . . 55
B Maple Worksheets 58
B.1 feuler.mws . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
B.1.1 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
B.1.2 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
B.1.3 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
B.1.4 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
B.2 beuler.tex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
B.2.1 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
B.2.2 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
B.2.3 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
B.2.4 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
B.3 trap.mws . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
B.3.1 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
B.3.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
B.4 circle1.mws . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
B.4.1 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
B.4.2 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
2
CONTENTS CONTENTS
3
Chapter 0
Introduction
Calculus is the study of dierential and integral equations and their solutions. It
provides a technique for modelling real-world systems in a mathematical manner, by
using dierential and integral equations that relate the state of a system to states that
neighbour it in space and time. It was the work of Leibniz and Newton in developing
calculus during the 17th century that allowed for these techniques to be invented.
dn y dn1 y dy
an (x) n
+ an1 (x) n1 + . . . + a1 (x) + a0 (x)y = f (x) (0-1)
dx dx dx
Some of the problems and questions that can be answered by modelling real-world
problems as a system of dierential equations include:
Weather Prediction.
What will the population of a certain country be at some arbitrary time in the
future?
4
CHAPTER 0. INTRODUCTION
There are several models that have been used to study population dynamics.
One common model is the exponential model, in which the rate of change of the
population is proportional to the existing population.
These situations and others can be modelled by expressing the physical laws that
apply to the situation as a set of equations relating derivatives and integrals. These
equations commonly contain variables corresponding to time, velocity, acceleration,
mass, density, momentum, energy and the basic laws that apply to many of these
situations include conservation of mass and energy, and the balance of forces. These
equations can then be solved for some of the variables by assuming other variables to
be known. This allows us to extract information about the physical situation being
modelled.
In some cases the solution to a single dierential equation or system of dierential
equation is exact, e.g. the solution could be a power series or trigonometric function.
These solutions, if they exist, are very useful. However the group of dierential equa-
tions having exact known solutions is small and dierent techniques are required to
solve systems of equations for which an exact solution cannot be found. If an exact
solution cannot be found, the alternative is to nd an approximation of the solution.
The range of techniques used to estimate numerical solutions to dierential equations
is the main focus of this project.
A simple example of a dierential equation is
y = y (0-2)
With initial values y(0) = 1, y (0) = 0, the solution is clearly y = cos x. We will be
using this later on to demonstrate the accuracy of some of the numerical methods of
obtaining solutions.
A more complex example we will also be using is Keplers Equations of planetary
motion. These are
y
y = 3 (0-3)
(y 2 + z 2 ) 2
z
z = 3 (0-4)
(y + z 2 ) 2
2
with initial values y(0) = 1 e, z(0) = 0, y (0) = 0, z (0) = 1+e
1e
The solution to this system is an ellipse and e denotes eccentricity.
As well as linear ordinary dierential equations, we can have non-linear dierential
equations where the derivatives may be raised to some power, and partial dierential
5
CHAPTER 0. INTRODUCTION
equations where y may be a function of several variables. We shall look at the non-
linear Keplers Equations later. These more complicated equations can then be used
for providing mathematical models of the behavior of sound or light waves or describing
how the distribution of heat in an object changes over time.
In this study we will restrict ourselves to ordinary dierential equations.
and if the sample values are given for x and y, c can be calculated easily.
More complicated equations can sometimes be rearranged into a form which can be
integrated straightforwardly, or sometimes tricks such as the integrating factor can be
used.
6
Chapter 1
Classication of Dierential
Equations
1.1 Terminology
dy d y 2
If all the dierential coecients in a dierential equation are ordinary (e.g. dx , dx2 ,
etc.) then the dierential equation is an ordinary one. If partial dierential coecients
2u
are involved (such as ux , y 2 , etc.) then it is a partial dierential equation. The
order of a dierential equation is the order of the highest dierential coecient that
it contains. Dierential equations of order greater than one are called higher-order
dierential equations. The degree of a dierential equation is the power to which
the highest order dierential coecient is raised when the equation is rationalized, that
is, converted to a form with no fractional powers. A dierential equation of order n
dy d2 y
is linear if it is linear in the dependent variable y and its derivatives ( dx , dx2 , . . .).
Otherwise the equation is called non-linear.
In general, an ordinary dierential equation is a function of y (the dependent variable),
x (the independent variable) and the derivatives of y:
dy d2 y d3 y
f x, y, , 2 , 3 , . . . . (1-1)
dx dx dx
7
CHAPTER 1. CLASSIFICATION OF DIFFERENTIAL EQUATIONS
linear dierential equations; that is, a set of two or more dierential equations with an
equal number of unknown functions.
As we are often concerned with rates of change w.r.t. time (e.g. speed, velocity,
nuclear disintegrations per second, etc.), we may often refer to x as time, although
in general it does not have to represent this specic physical quantity. Therefore the
graph of y against x is often termed the time series plot (e.g. displacement-time
graphs), whereas the graph of y against y is often termed the phase plane plot (e.g.
velocity-displacement graphs).
dn y
Step 1. Rewrite Equation 1.2 so that dxn appears on the left-hand side by itself.
Hence
dn y dn1 y
= a n1 + . . . + a1 (x)y (x) + a0 (x)y = f (x), (1-5)
dxn dxn1
with ai (x) = bi (x)/bn (x) for 0 i n 1 and f (x) = g(x)/bn (x).
8
CHAPTER 1. CLASSIFICATION OF DIFFERENTIAL EQUATIONS
Step 4. Equations 1.2 and 1.2 are a system of rst-order linear dierential equa-
tions in y1 (x), y2 (x), . . . , yn (x). This system is equivalent to the single matrix equation
y(x)
= A(x)y(x) + f (x) where
y1 (x)
y2 (x)
y(x) = . , (1-15)
..
yn (x)
0
0
f (x) = ... , (1-16)
0
f (x)
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
y(x) = .. .. .. .. .. . (1-17)
. . . . .
0 0 0 0 1
a0 (x) a1 (x) a2 (x) a3 (x) an1 (x)
9
CHAPTER 1. CLASSIFICATION OF DIFFERENTIAL EQUATIONS
Then the initial conditions can be given by the matrix (vector) equation y(x0 ) = c,
and we are done.
It is worth noting that it is trivial to adapt this procedure for reducing systems of
higher-order equations, rather than a single equation.
10
Chapter 2
Numerical Methods
11
CHAPTER 2. NUMERICAL METHODS
12
CHAPTER 2. NUMERICAL METHODS
True solution
y2 (x2, y2)
y0
(x0, y0)
h h
x
x0 x1 x2
y1 = y0 + hf (x1 , y1 ). (2-8)
y2 = y1 + hf (x2 , y2 ). (2-9)
In general,
yn+1 = yn + hf (xn+1 , yn+1 ), (2-10)
13
CHAPTER 2. NUMERICAL METHODS
(x2, y2)
y2
True solution
y0
(x0, y0)
h h
x
x0 x1 x2
Assuming that the value at point x is correct, the Backward Eulers method computes
the value at point x + h with a local truncation error that is proportional to h2 . The
Backward Eulers method always gives undershoots on the original curve.
Normally we do not know the derivative at point x + h, although we need it to
compute the function value at point x + h. In practice this requires a rearrangement
of the equation. We call such a numerical scheme an implicit numerical scheme, as
opposed to explicit numerical schemes, such as the Forward Euler method, where
no such rearrangement is necessary. For most equations implicit schemes are more
stable than explicit schemes because of the undershoots.
14
CHAPTER 2. NUMERICAL METHODS
1. The local error describes the error that occurs after a single time step of the
method.
2. The global error describes the cumulative eect of the local errors after many
time steps.
3. The roundo error arises from the nite precision with which computers store
and process numbers.
We shall now provide a rigorous denition of local and global errors. Let the set
{(xn , yn ) : n = 0, . . . , N } be an approximation to the solution y(x) of the initial value
problem. The global error at time xn is the dierence between the true solution at
xn and the approximation yn :
En = y(xn ) xn . (2-13)
The absolute error in the numerical approximation at x = xn is |En |, that is, the
absolute value of the global error at xn .
The local error, is the dierence between the true solution y(xn+1 ) and the approx-
imation after one time step, assuming that (xn , yn ) is a point on the graph of the true
solution (i.e. assuming that yn is exact).
A numerical method is of order n, where n is a positive integer, if the method is
exact for polynomials of degree n or less. In other words, if the true solution of an
initial-value problem is a polynomial of degree n or less, then the approximate solution
and the true solution will be identical for a method of order n.
In general, the higher the order, the more accurate the method.
We shall now consider each method in turn, deriving the error term and determining
the order of the method.
15
CHAPTER 2. NUMERICAL METHODS
Thus, if the step size is cut in half, then the local error at each step is reduced by a
factor of four.
A rigorous derivation of the global error is beyond the scope of this report. We shall
restrict ourselves to a simple heuristic argument. Suppose that y(0) = y0 and we want
to nd y(X). The number of steps required is approximately X/h. If the local error is
roughly constant for 0 x X, and E(X) is the global error at x = X,
E(X) number of iterations E loc
X
h2 (2-17)
h
h.
The following fact follows:
The global error in Forward Eulers method decreases linearly with the step size.
We say that Eulers method is a rst-order method, because the global error is
proportional to h (i.e. rst-order with respect to h).
16
CHAPTER 2. NUMERICAL METHODS
But y(x1 h) = y(x0 ) = y0 , y(x1 ) = y(x0 + h), and y (1) (x1 ) = f (x1 , y1 ), so we can
rearrange Equation 2-18 to obtain
1
y(x0 + h) = y0 + hf (x1 , y1 ) h2 y (2) (). (2-19)
2
Hence the local error in Backward Eulers method is
1
E loc = h2 y (2) () h2 . (2-20)
2
This error is O(h2 ), similarly to the error for Forward Eulers method.
Hence the following fact:
The local error in Backward Eulers method decreases as the square of the step size.
By following the argument given in Section 2.4, we deduce that the global error is
O(h).
The global error in Backward Eulers method decreases linearly with the step size.
Once again, a rigorous proof of this fact is beyond the scope of this report.
By Taylor expansion,
h2 (2)
f (xi+1 ) = f (xi + h) = f (xi ) + hf (xi ) + f (xi ) + . . . , (2-22)
2!
and hence
xi+1
h h2 (2)
f (x)dx h f (xi ) + f (xi ) + f (xi ) + . . . (2-23)
xi 2 4
(x xi )2 (2)
f (x) = f (xi ) + (x xi )f (xi ) + f (xi ) + . . . (2-24)
2!
17
CHAPTER 2. NUMERICAL METHODS
Comparison of these two forms shows that the local truncation error is
loc 3 1 1 h3
E =h f (2) (xi ) + . . . = f (2) (xi ) + . . . . (2-26)
6 4 12
We can now make the following conclusion:
The local error in Trapezium Rule method decreases as the cube of the step size.
We used a slightly dierent notation in this proof compared to that in Sections 2.4
and 1. In essence, we are trying to nd a numerical approximation to the integral of
f (x, y) with respect to x. The exact integral is the desired solution of the ordinary
dierential equation.
By following the argument given in Section 2.4, we deduce that the global error is
O(h2 ).
The global error in Trapezium Rule method decreases as the square of the step size.
We have thus demonstrated that by taking the average of the Forward and Backward
Eulers methods we obtain a new method Trapezium Rule which is, as far as
accuracy is concerned, better than the original methods. But accuracy is not the
only concern. We shall proceed to demonstrate that there are other criteria for choosing
numerical methods, such as stability and symmetricity.
18
CHAPTER 2. NUMERICAL METHODS
methods. In general, for problems with periodic solutions asymmetric (i.e. non-
symmetric) methods fail because they lead to non-periodic solutions. Heuristically,
symmetric methods are invariant regardless of the direction (the sign of h), and
produce periodic solutions.
Neither Forward, nor Backward Euler scheme is symmetric. Substitution h h in
2-6 (Forward Eulers), for example, gives us the equation
which is, in fact the Backward Eulers method, which is, in a sense, a mirror image
of the Forward Euler.
Note that by averaging the two mirror methods, Forward and Backward Euler, we
obtained a symmetric method, the Trapezium Rule.
y = f (x, y, z, w),
z = g(x, y, z, w), (2-33)
w = r(x, y, z, w),
19
CHAPTER 2. NUMERICAL METHODS
20
Chapter 3
Periodic Solutions
Some initial value problems have periodic solutions. For such prob-
lems many of the standard numerical methods produce highly inaccu-
rate results, failing to capture the periodic behaviour. We investigate
this phenomenon by considering a simple test equation. As a result,
we discover that, in order to produce satisfactory results on periodic
problems, the numerical method must be symmetric.
3.1 Problem
Some initial value problems have periodic solutions. Consider, for instance, the equation
d2 y
= y (3-1)
dx2
with initial conditions1
y(0) = 1, (3-2)
y (0) = 0. (3-3)
It is easy to see that y = cos x is a solution, and cos is a periodic function. The time
series plot (y against x) is a cosinusoid, whereas the phase plane plot (y against y) is
a circle:
We would like to test some of our numerical methods on this equation, but before we
can apply them, we need to re-write this problem as a rst-order system:
y = z, y(0) = 1, (3-4)
z = y, y (0) = 0. (3-5)
1
The initial conditions dont really matter. We have chosen them to make the solution y = cos x.
21
CHAPTER 3. PERIODIC SOLUTIONS
0.5
10 8 6 4 2 0 2 4 6 8 10
0.5
We now wish to integrate the above equation using various methods. We invoke
our implementations of the Forward Euler, Backward Euler, and Trapezium Rule
given in Chapter 1.2, namely GeneralForwardEuler, GeneralBackwardEuler, and
GeneralTrapezium.
In Maple, the problem can be specied as follows:
> u := [x,y,z];
> f := [1,z,-1*y];
> ic := [0,1,0];
22
CHAPTER 3. PERIODIC SOLUTIONS
0.5
1 0.5 0 0.5 1
0.5
values of h. The Trapezium Rule produced periodic graphs for all values of h, whereas
Forward Euler and Backward Euler methods failed to produce a satisfactory solution.
As h gets smaller, the method remains periodic for some time, but eventually spirals
outwards (Forward Euler) or inwards (Backward Euler).
Figure 3.4 shows the time series plot for h = 101 , all methods being shown on a
single set of axes. The plots for the true solution and the values obtained using the
Trapezium Rule are extremely close, as shown by the graph. The graphs for the Forward
and Backward Euler methods deviate further and further from the true solution as the
distance from the initial value point, (0, 1), increases.
2
The error at x is dened as |true solution at x numerical solution at x|.
23
CHAPTER 3. PERIODIC SOLUTIONS
1 1
0.5 0.5
0.5
0.5
0.5 0.5
1
1.5 1
0.8 1 1
0.6
0.2
0.4
0.5 0.5
0.6
0.8
1 1
1 1 1
1 1 1
Figure 3.3: Phase plane plots for Forward and Backward Euler and Trapezium Rule,
for dierent values of h
24
CHAPTER 3. PERIODIC SOLUTIONS
1
y
0.5
x
2 4 6 8 10
0
0.5
1.5
True solution
Forward Eulers Method
Backward Eulers Method
Trapezium Rule Method
0.6
0.5
0.4
Error 0.3
0.2
0.1
0 2 4 6 8 10
x
Figure 3.5: Error plots for all methods on a single set of axes
25
CHAPTER 3. PERIODIC SOLUTIONS
0.35
0.3
0.25
0.2
h
0.15
0.1
0.05
26
Chapter 4
d2 y
= y (4-1)
dx2
with initial conditions
and to get a numerical answer which is periodic. As previously we need to split this
into a set of rst order dierential equations.
y = z, y(0) = 1, (4-3)
z = y, y (0) = 0. (4-4)
27
CHAPTER 4. DEVELOPING HIGHER ORDER METHODS
h2
yn+1 = yn + hyn + [4y + 2yn ] (4-10)
12 n+1/2
h
yn+1 yn =
yn+1 + 4yn+1/2 + yn (4-11)
6
1 h2
yn+1/2 = [yn+1 + yn ] yn+1 + 4yn+1/2 + yn (4-12)
2 48
However, we can increase the accuracy of the half-step.
yn+1/2 = A[yn+1 + yn ] Bh[yn+1 yn ] + Ch2 [yn+1
yn ] (4-13)
1 5h h2
yn+1/2 = [yn+1 + yn ] [yn+1 yn ] + [yn+1 yn ] (4-14)
2 32 64
1 h2
yn+1/2 = yn + hyn +
2yn+1
+ 12yn+1/2 + 14yn (4-15)
2 192
28
CHAPTER 4. DEVELOPING HIGHER ORDER METHODS
Using this more accurate representation, for yn+1/2 , we can create a more accurate
algorithm. For labeling purposes we should call this method B.
Thus our aim now is to compute the numerical solution of periodic problems using
the fourth order accurate methods A (consisting of Equations 4-10, 4-11 and 4-12) and
B (consisting of Equations 4-10, 4-11 and 4-15).
The Maple procedures used are called FourthOrderFirst and FourthOrderFirstAcc for
A and B respectively.
0.5
0 2 4 6 8 10
0.5
Fourth Order A
Fourth Order B
It is instructive to also create an error plot (Figure 4.3) to uncover how precisely the
respective solutions are with respect to the real solution, which is y = cos(x). It clearly
demonstrates the increased accuracy of using Bs better approximation for yn+1/2 .
29
CHAPTER 4. DEVELOPING HIGHER ORDER METHODS
y 0.5
1 0.5 0 0.5 1
y
0.5
Fourth Order A
Fourth Order B
1e06
8e07
6e07
Err
4e07
2e07
0 2 4 6 8 10
x
Fourth Order A
Fourth Order B
Figure 4.3: Error plot, notice how the error increase linearly with x and this is what
we would expect for our numerical methods
30
CHAPTER 4. DEVELOPING HIGHER ORDER METHODS
d2 y y
2
= 2 (4-16)
dx (y + z 2 )3/2
d2 z z
2
= 2 (4-17)
dx (y + z 2 )3/2
with initial conditions (e = 0.6 in our case)
y = a (4-20)
y
a = 2 (4-21)
(y + z 2 )3/2
z = b (4-22)
z
b = 2 (4-23)
(y + z 2 )3/2
with initial conditions (e = 0.6 in our case)
31
CHAPTER 4. DEVELOPING HIGHER ORDER METHODS
z
0.8 0.6 0.4 0.2 0.2 0.4 0.6 0.8
0.5
y
1
1.5
d2 y GM y
2
= 2 (4-26)
dx (y + z 2 )3/2
d2 z GM z
2
= 2 (4-27)
dx (y + z 2 )3/2
with initial conditions
begin where G is the gravitational constant and M is the mass of the sun. It happens
that GM = 4 2 . Before solving using A and B methods, we must create a set of rst
order ODEs (very similar in form to the previous Keplers Equations). We use a
step-size h = 0.01 in (Figure 4.5).
h h2
yn+1/2 = yn + yn + yn+1 + 4yn+1/2 + 3yn (4-30)
2 48
32
CHAPTER 4. DEVELOPING HIGHER ORDER METHODS
0.5
z
1 0.5 0.5 1 1.5
0
0.5
y 1
1.5
Figure 4.5: The earths orbit around the sun, method A is not as accurate again
0.5
z
1 0.5 0.5 1
0.5
y 1
1.5
Figure 4.6: The earths orbit around the sun now with h = 0.01
If we solve Equation 4-1, we can create an error plot (Figure 4.7), to compare it to
B. We see that B provides a better approximation for the half-step.
33
CHAPTER 4. DEVELOPING HIGHER ORDER METHODS
1e06
8e07
6e07
Err
4e07
2e07
0 2 4 6 8 10
x
Legend
Fourth Order B
Fourth Order Lobatto
34
Chapter 5
h
yn+1 yn = [y + yn ] (5-2)
2 n+1
By eliminating yn+1 from Equation 5-1, we have,
h h h
yn+1 yn = yn + (yn+1 + yn ) + yn
(5-3)
2 2 2
Thus we now have Equation 5-4 for calculating yn+1 and Equation 5-5 for calculating
its derivative. These equations form the basis of the Modied Trapezium rule.
h2
yn+1 = yn + hyn + [y + yn ] (5-4)
4 n+1
h
yn+1 = yn + [y + yn ] (5-5)
2 n+1
35
CHAPTER 5. MODIFIED TRAPEIZUM RULE
y 0.5
1 0.5 0.5 1
y
0.5
Fourth Order A
Mod Trap
Figure 5.1: Step size h = 0.1 plot, phase plot of modied trapezium and fourth order
A. We nd that a periodic solution is generated.
36
CHAPTER 5. MODIFIED TRAPEIZUM RULE
0.5
0 2 4 6 8 10
0.5
Fourth Order A
Mod Trap
Figure 5.2: Step size h = 0.1 plotting both solutions generated by both methods
0.006
0.005
0.004
Err
0.003
0.002
0.001
0 2 4 6 8 10
x
Fourth Order A
Modified Trapezium
Figure 5.3: Step size h = 0.1, comparing the errors from both methods
37
CHAPTER 5. MODIFIED TRAPEIZUM RULE
z
0.8 0.6 0.4 0.2 0.2 0.4 0.6 0.8
0
0.5
1 y
1.5
Figure 5.4: Step size h = 0.1, solving Keplers Equations using both the Modied
Trapezium rule and fourth order A and plotting yz plane
38
Chapter 6
6.1 An Example
We shall consider the following sti equation,
d2 y dy
+ ( + 1) + y = 0 (6-1)
dx2 dx
with initial conditions
Introducing an auxillary variable z we can construct a set of rst order ODEs from
the problem.
dy
=z (6-3)
dx
dz
= y ( + 1)z (6-4)
dx
y = ex (6-6)
39
CHAPTER 6. SOLVING STIFF EQUATIONS
However we also have an unwanted solution ex , which also satises Equation 6-1.
This solution changes very rapidly around x = 0. We aim to demonstrate how under
certain circumstances Forward Euler is not stable when solving 6-1. In fact, Forward
Euler is only stable for step sizes that satisfy,
2
h< (6-7)
We solve Equation 6-1 for = 103 using h = 0.1 numerically using both forward and
backward Eulers methods. If we have a limited range for, eg. x = [0, 1.5] it seems as
though, Forward Euler is stable (Figure 6.1). However, increasing the range slightly,
to x = [0, 1.6] and we see Forward Euler becoming unstable. If we increase the range
of x further, we nd that Forward Euler blows up towards innity.
It is only through decreasing step-size to h = 0.001, that Forward Euler appears to
produce a stable solution. This is not surprising given that, the stability condition is
satised. In all cases Backward Euler appears to produce a stable solution. However,
being an implicit method, it is computationally more demanding than Forward Euler,
an explicit method.
2
0.001 = h < = 0.002 (6-8)
0.8
0.6
0.4
0.2
Real sol
Unwanted sol
Backward Euler
Forward Euler
40
CHAPTER 6. SOLVING STIFF EQUATIONS
20
40
60
80
Real sol
Backward Euler
Forward Euler
Figure 6.2: Step size h = 0.1 with extended range plot, solution begins to deviate from
real solution signicantly
Real sol
Backward Euler
Forward Euler
Figure 6.3: Step size h = 0.01, Forward Euler, still exhibits lack of stability plot
41
CHAPTER 6. SOLVING STIFF EQUATIONS
0.8
0.6
0.4
0.2
0 2 4 6 8 10
Real sol
Backward Euler
Forward Euler
Figure 6.4: Step size h = 0.001, both Forward and Backward Euler produce stable plot
42
Chapter 7
7.1 Introduction
The objective for this part of our work was to nd a numerical method of order 6.
This would mean the local error term for such a method has as its lowest degree term
a term in h7 . Such a method then should be more accurate than any of the previous
methods outlined in this document.
The equations below were provided as a starting point. It was the constants A, B,
, C, D, E, F , C, D, E and F that had to be determined.
yn+1 = yn + h(Ayn+1 + Byn+ 1
+
+ Byn+ 1
+ Ayn ) (7-1)
2 2
1
yn+ 1 + = yn + ( + )hyn + h2 (Cyn+1
+ Dyn+ 1
+
+ Eyn+ 1
+ F yn ) (7-2)
2 2 2 2
1
yn+ 1 = yn + ( )hyn + h2 (Cyn+1
+ Dyn+ 1
+
+ Eyn+ 1
+ F yn ) (7-3)
2 2 2 2
From the equations one may note two points. Firstly because of the nature of the three
equations 7-1, 7-2 and 7-3 we see that symmetricity is satised. Secondly, the terms
yn+
and yn+ mean that gradients of the curve from multiple points between
1 1
2
+ 2
x and x + h are considered, as opposed to assuming the gradient staying constant in
the interval (x, x + h) (which is used by some of the earlier methods). This results in
greater accuracy.
43
CHAPTER 7. DERIVING AND USING A SIXTH ORDER NUMERICAL
METHOD
1 ( 1 + )2 h2 ( 12 + )3 h3 (4)
yn+ 1
+
= yn + + hyn + 2 yn + yn
2 2 2 6
( 1 + )4 h4 (5) ( 12 + )5 h5 (6)
+ 2 yn + yn + O(h6 )
24 120
and yn+ :
1
2
1 ( 1 )h2 ( 12 )h3 (4)
yn+ 1
= yn + hyn + 2 yn + yn
2 2 2 6
( 1 )h4 (5) ( 12 )h5 (6)
+ 2 yn + yn + O(h6 )
24 120
When we use our method, it will have a local error of order 7, hence all terms in
hn up to n = 6 should should vanish. so we need to equate the coecients on the
expansion of the left hand side of 7-1 with those on the right hand side for the terms
up to h6 . This equating means we have to solve for the equations below:
44
CHAPTER 7. DERIVING AND USING A SIXTH ORDER NUMERICAL
METHOD
1 = 2A + 2B (7-5)
1
= A + B 12 + + B 12 (7-6)
2
1 B( 1 +)2 B( 1 )2
= A2 + 2 2 + 22 (7-7)
6
1 B( 1 +)3 B( 1 )3
= A6 + 2 6 + 26 (7-8)
24
1 A B( 1 +)4 B( 1 )4
= 24 + 224 + 224 (7-9)
120
1 A B( 1 +)5 B( 1 )5
= 120 + 2120 + 2120 (7-10)
720
Although there are 6 equations in 3 unknowns, the system is not over-constrained
and we can nd values for A, B and that satisfy these equations.
45
CHAPTER 7. DERIVING AND USING A SIXTH ORDER NUMERICAL
METHOD
( 12 + )2
=C +D+E+F (7-11)
2
( 12 + )3
= C + D( 12 + ) + E( 12 ) (7-12)
6
1
( 2 + )4
= 12 (C + D( 12 + )2 + E( 12 )2 ) (7-13)
24
1
( 2 + )5
= 16 (C + D( 12 + )3 + E( 12 )4 ) (7-14)
120
Using the value of obtained previously, we have 4 equations in 4 unknowns which
again produce a solution.
2
1 h2 1
yn+ 1 = yn + h yn + yn
2 2 2 2
3 4 5
h3 1 h4 1 (4) h5 1
+ yn + yn + yn(5)
6 2 24 2 120 2
and then the right hand side (again terms in the brackets of 7-3 only need to be
expanded up to h3 ):
1 2 h2 (4) h3 (5)
yn+ 1 = yn + h yn + h C yn + hyn + yn + y
2 2 2 6
2 3
1 h2 1 (4) h3 1 (5)
+D yn + h + yn + + yn + + yn
2 2 2 6 2
2 3
1 h2 1 (4) h3 1 (5)
+E yn + h yn + yn + yn
2 2 2 6 2
+F yn + O(h4 ) )
Equating both sides produces the set of equations below, for which we already have
a value for . But from these we can calculate C, D, E and F .
46
CHAPTER 7. DERIVING AND USING A SIXTH ORDER NUMERICAL
METHOD
( 12 )2
=C +D+E+F (7-15)
2
( 12 )3
= C + D( 12 + ) + E( 12 ) (7-16)
6
( 12 )4
= 12 C + D( 12 + )2 + E( 12 )2 (7-17)
24
( 12 )5
= 12 C + D( 12 + )3 + E( 12 )3 (7-18)
120
Now we can get the values for all the constants we require, by solving the equations
produced. We used the maple function solve to get the values:
A = .08333333333
B = .4166666667
= .2236067977
C = .001490711985
D = .02000000000
E = .1815028324
F = .06179127846
C = .001490711985
D = .00483616570
E = .02000000000
F = .02154205488
So we may proceed with the usage of the method.
47
CHAPTER 7. DERIVING AND USING A SIXTH ORDER NUMERICAL
METHOD
y 0.5
1 0.5 0 0.5 1
0.5
4e07
3e07
Err 2e07
1e07
0 2 4 6 8 10
x
6th Order
Fourth Order B
Notice that for a value of h = 0.1 we have a very smooth curve. The main question
to be answered is whether the sixth order method produces more accurate results than
the previous methods investigated (and so is worth the extra computation time). From
the graphical comparison (7.2) it is clear that the sixth order method is signicantly
more accurate than the best of the rest investigated (i.e. the most accurate fourth order
48
CHAPTER 7. DERIVING AND USING A SIXTH ORDER NUMERICAL
METHOD
numerical method). The gure 7.2 shows the errors for both the sixth order method
and the most accurate fourth order method:
d2 y GM y
= 2 (7-19)
dx2 (y + z 2 )3/2
d2 z GM z
2
= 2 (7-20)
dx (y + z 2 )3/2
For Keplers equations, the equations were once again manipulated as for the fourth
order methods and the sixth order method (implemented in Maple code) was applied
to them. The results were similar to those obtained before (see gure 7.3).
0.5
Z
1 0.5 0.5 1
0
0.5
Y 1
1.5
Note for a step size of h = 0.01 we have a graph that is very smooth, smoother than
the results from the fourth order methods.
49
CHAPTER 7. DERIVING AND USING A SIXTH ORDER NUMERICAL
METHOD
d2 y y
2
= 2 (7-23)
dx (y + z 2 )3/2
d2 z z
= 2 (7-24)
dx2 (y + z 2 )3/2
Manipulation was performed as before to bring them into the correct form. Then a
graph was plotted with the results of the sixth order method (gure 7.4).
Z
0.8 0.6 0.4 0.2 0.2 0.4 0.6 0.8
0.5
1.5
50
Appendix A
Biographies
Isaac Newton was born on December 25, 1642 in Woolsthorpe, near Grantham in
Lincolnshire, England. He was born the same year Galileo died. Newton is arguably
the most inuential scientist who ever lived. His accomplishments in mathematics,
optics, and physics laid the foundations for modern science and revolutionized the
world.
Newton was educated at Trinity College, Cambridge where he lived from 1661 to
1696. During this period he produced the bulk of his work on mathematics. In 1696
he was appointed Master of the Royal Mint, and moved to London, where he resided
until his death.
As mathematician, Newton invented integral calculus, and jointly with Leibnitz, dif-
ferential calculus. He also calculated a formula for nding the velocity of sound in a
gas which was later corrected by Laplace.
Newton made a huge impact on theoretical astronomy. He dened the laws of motion
and universal gravitation which he used to predict precisely the motions of stars, and
the planets around the sun. Using his discoveries in optics Newton constructed the rst
reecting telescope.
Newton found science a hodgepodge of isolated facts and laws, capable of describing
some phenomena, and predicting only a few. He left it with a unied system of laws,
51
APPENDIX A. BIOGRAPHIES
that could be applied to an enormous range of physical phenomena, and used to make
exact predications. Newton published his works in two books, namely Opticks and
Principia.
Newton died in London on March 20, 1727 and was buried in Westminster Abbey,
the rst scientist to be accorded this honor. A review of an encyclopedia of science will
reveal at least two to three times more references to Newton than any other individual
scientist.
Euler was one the leading mathematicians of the 18th century. Although the majority
of his work was in pure mathematics, he contributed to other disciplines, such as
astronomy and physics, as well. In his lifetime he published more than 500 books and
papers, and another 400 were published posthumously.
Euler was born in Basel, Switzerland on April 15, 1707. Although his father, a pastor,
was a gifted amateur mathematician he wanted his son to succeed him in the village
52
APPENDIX A. BIOGRAPHIES
church. Despite his love for mathematics, Euler entered the University of Basel to
study theology. As a student, he attracted the attention of the Swiss mathematician,
Johann Bernoulli. Bernoulli was able to convince the elder Euler to allow his son to
drop his theological training and instead study mathematics. Soon after receiving his
degree he was invited by the Empress of Russia in 1727 to be a professor of physics, and
later mathematics, at the Academy of Sciences in St. Petersburg. He left for Berlin
in 1741 and became professor of mathematics at the Berlin Academy of Sciences. He
later returned to St. Petersburg at the urging of Catherine the Great in 1766. He lived
there until he suered a stroke and died in 1767. In his early 20s Euler lost his vision
in one eye due to an illness. Later in life he lost the other eye, but despite this he was
quite productive in his eld until his death.
Eulers contributions to mathematics cover a wide range, including analysis and the
theory of numbers. He also investigated many topics in geometry. For example, he
worked on the mathematics behind the Greek concept of Perfect Bodies. The Greeks
dened the perfect body as the form built from identical regular polyhedra. There
are only ve such polyhedra, the tetrahedron, cube, octahedron, dodecahedron and
icosahedron. These concepts were forgotten until the Renaissance, when Pacioli and
Leonardo da Vinci studied them. Kepler even tried to relate the perfect bodies to the
orbits of the planets. Euler was able to relate the number of faces (F ), vertices (V )
53
APPENDIX A. BIOGRAPHIES
F +V =E+2 (A-1)
from which one can derive that there are only ve regular polyhedra.
Carle Runge was born in Bremen, Germany, on 30 August 1856. At the age of 19,
after leaving school, Carle Runge spent 6 months with his mother visiting the cultural
centres of Italy. On his return to Germany he enrolled at the University of Munich to
study literature. However after 6 weeks of the course he changed to mathematics and
physics.
Runge attended courses with Max Planck and they became close friends. In 1877 both
went to Berlin but Runge turned to pure mathematics after attending Weierstrasss
lectures. His doctoral dissertation (1880) dealt with dierential geometry.
After taking his secondary school teachers examinations he returned to Berlin where
he was inuenced by Kronecker. Runge then worked on a procedure for the numerical
solution of algebraic equations in which the roots were expressed as innite series of
rational functions of the coecients.
Runge published little at that stage but after visiting Mittag-Leer in Stockholm in
September 1884 he produced a large number of papers in Mittag-Leers journal Acta
54
APPENDIX A. BIOGRAPHIES
mathematica (1885).
Runge obtained a chair at Hanover in 1886 and remained there for 18 years. Within
a year Runge had moved away from pure mathematics to study the wavelengths of the
spectral lines of elements other than hydrogen (J. J. Balmer had constructed a formula
for the spectral lines of helium.)
Runge did a great deal of experimental work and published a great quantity of results.
He succeeded in arranging the spectral lines of helium in two spectral series and, until
1897, this was thought to be evidence that hydrogen was a mixture of two elements.
In 1904 Klein persuaded G ottingen to oer Runge a chair of Applied Mathematics,
a post which Runge held until he retired in 1925.
Runge was always a t and active man and on his 70th birthday he entertained his
grandchildren by doing handstands. However a few months later he had a heart attack
and died on 3 January 1927 in G ottingen, Germany.
Martin Kutta was born on 3 November 1867 in Pitschen, Upper Silesia (now Byczyna,
Poland). He studied at Breslau from 1885 to 1890. Then he went to Munich where he
studied from 1891 to 1894, later becoming an assistant to von Dyck at Munich. During
this period he spent the year 1898-99 in England at the University of Cambridge.
Kutta held posts at Munich, Jena and Aachen. He became professor at Stuttgart in
1911 and remained there until he retired in 1935.
He is best known for the Runge-Kutta method (1901) for solving ordinary dierential
equations and for the Zhukovsky-Kutta aerofoil. Runge presented Kuttas methods.
Martin Kutta died on 25 December 1944 in F urstenfeldbruck, Germany.
55
APPENDIX A. BIOGRAPHIES
new shape turned out to be an ellipse, which t well into Keplers Pythagorean views
on nature.
Kepler tried all sorts of mystical notions to describe planetary orbits, using the Pla-
tonic solids and musical analogies. Spread out through his voluminous calculations in
Astronomia Nova, however, were three gems: Keplers laws of planetary motion. For
the formulation of these laws, Kepler is considered the founder of physical astronomy.
The rst law states that the planets move in elliptical orbits with the Sun at one focus.
The second law states that the planets sweep out equal areas in equal times (which is
equivalent to the statement of conservation of angular momentum. ) The third law
states that the period squared in proportional to the semimajor axis cubed. Kepler
believed that the planets were kept in their orbits by a anima motrix (motive soul),
1
Kepler did not develop numerical methods for solving dierential equations. However, his work
has led to some of the most famous dierential equations of all times. Therefore we think the inclusion
of this biographical note is more than justied.
56
APPENDIX A. BIOGRAPHIES
but later modied it to vis motrix (life force). He also studied optics as an aspect of
astronomy in Astronomiae Pars Optica (1604), and developed the concept of a ray.
57
Appendix B
Maple Worksheets
58
APPENDIX B. MAPLE WORKSHEETS
B.1 feuler.mws
B.1.1 Initialization
The following commands initialize Maple. The warnings that appear have no
adverse eects on the execution, so can be safely ignored.
> restart;
> with(DEtools):
> with(plots):
> with(linalg):
Warning, the protected names norm and trace have been redefined and
unprotected
B.1.2 Introduction
This worksheet provides several implementations of Forward Eulers Method and
demonstrates how they can be used to solve simple IV (initial value) problems.
circle.mws uses these results to analyze the circle problem and determine which of
the methods (Forward Eulers, Backward Eulers and Trapezium Rule) produces the
most satisfactory results.
B.1.3 Implementation
We provide multiple implementations of Forward Eulers Method, which dier in their
applicability to problems of dierent orders, the form of the parameters, etc. In each
specic case, the user should choose the most appropriate implementation. Here is a
brief overview:
ForwardEuler is similar to the above, but takes the parameters in a more natural
form, then converts them for its purposes and proceeds as SimpleForwardEuler.
59
APPENDIX B. MAPLE WORKSHEETS
60
APPENDIX B. MAPLE WORKSHEETS
61
APPENDIX B. MAPLE WORKSHEETS
62
APPENDIX B. MAPLE WORKSHEETS
Supplementary procedures
The following procedure converts the x list returned by Maples dsolve to a list of
points, which can be plotted using plot.
63
APPENDIX B. MAPLE WORKSHEETS
B.1.4 Examples
Example 1: First order IV problem
Suppose we are trying to solve the ODE
d
dx y(x) = 3 y(x) + 5
with the initial condition given by y(0) = 7. We specify the problem as follows:
> F := (x, y) -> 3 * y + 5;
> x0 := 0;
> y0 := 7;
> h := 0.1;
> N := 10;
F := (x, y) 3 y + 5
x0 := 0
y0 := 7
h := 0.1
N := 10
64
APPENDIX B. MAPLE WORKSHEETS
0. 7.
0.1 9.6
0.2 12.98
0.3 17.374
0.4 23.0862
sol1 := 0.5 30.51206
0.6 40.165678
0.7 52.7153814
0.8 69.02999582
0.9 90.23899457
1.0 117.8106929
Here is how we could use ForwardEuler to achieve the same result. Notice how the
parameters are passed in this case:
> ode := diff(y(x), x) = 3 * y(x) + 5;
> ic := y(0) = 7;
> interval := x=0..1;
> N := 10;
d
ode := dx y(x) = 3 y(x) + 5
ic := y(0) = 7
interval := x = 0..1
N := 10
65
APPENDIX B. MAPLE WORKSHEETS
We can use Maple to obtain an analytical solution for our ODE. This is achieved by
using dsolve with dierent parameters:
> sol_true := dsolve({ode, ic});
5 26 (3 x)
sol true := y(x) = + e
3 3
Many dierential equations do not have analytical solutions, or they are too dicult
to calculate. In this case we are lucky, as our equation is very simple.
To plot a solution that was obtained from a symbolic computation, we use plot.
However, we must extract the function rst and specify whichever parameters it
takes. In our case, x is the only parameter.
> sol_true_f := unapply(op(2,sol_true),x);
5 26 (3 x)
sol true f := x + e
3 3
> plot(sol_true_f, 0..1);
66
APPENDIX B. MAPLE WORKSHEETS
160
140
120
100
80
60
40
20
How dierent is this solution from those obtained by Eulers Forward Method? To
answer this question, we may wish to plot the two solutions on a single graph.
odeplot provides a way of plotting the numerical solutions returned by dsolve, for
example:
> odeplot(sol_maple, [x, y(x)], 0..1);
67
APPENDIX B. MAPLE WORKSHEETS
120
100
80
y 60
40
20
However, odeplot is a lot less exible and powerful than plot, and it is dicult to
combine dierent kinds of graphs with this method. On the other hand, we need to
convert the results of our numerical solution to a set of points before they can be
plotted with plot. This is done using XListToPoints procedure:
> sol_maple_pts := XListToPoints(sol_maple);
1 1
, 9.59999999999999964], [ , 12.9800000000000004],
sol maple pts := [[0, 7.], [
10 5
3 2
[ , 17.3739999999999988], [ , 23.0861999999999981],
10 5
1 3
[ , 30.5120599999999982], [ , 40.1656779999999998],
2 5
7 4
[ , 52.7153813999999984], [ , 69.0299958200000248],
10 5
9
[ , 90.2389945660000308], [1, 117.810692935800034]]
10
We can now plot the symbolic solution and the numerical solution on the same set of
axes:
> plot([sol_true_f, sol_maple_pts], 0..1, labels=["x", "y"],
> legend=["true", "Eulers Forward Method"]);
68
APPENDIX B. MAPLE WORKSHEETS
160
140
120
100
y
80
60
40
20
0 0.2 0.4 0.6 0.8 1
x
true
Eulers Forward Method
As you can see, the further from the initial point, the more the numerical solution
deviates from the true one. Note that the value of y returned by Eulers Forward
Method is always less than the true value.
d
with the initial conditions given by y(0) = 7 and dx y(0) = 5. We specify the problem
as follows:
> ode := diff(diff(y(x), x), x) = 2 * y(x);
d2
ode := dx2
y(x) = 2 y(x)
Here is how we could express it in terms of the functions F and G, so that we can
apply SimpleForwardEuler2 to obtain a solution:
69
APPENDIX B. MAPLE WORKSHEETS
> t := x;
> solve(ode, diff(diff(y(t), t), t));
> F := (x, _y, _z) -> _z;
> G := unapply(subs(y(t) = _y, diff(y(t), t) = _z, solve(ode,
> diff(diff(y(t), t), t))), (t, _y, _z));
> x0 := 0;
> y0 := 7;
> z0 := 5;
> h := 0.1;
> N := 10;
t := x
2 y(x)
F := (x, y, z ) z
G := (x, y, z ) 2 y
x0 := 0
y0 := 7
z0 := 5
h := 0.1
N := 10
Here is how we could use ForwardEuler2 to achieve the same result. Notice how the
parameters are passed in this case:
> ode := diff(diff(y(x), x), x) = 2 * y(x);
> ic1 := y(0) = 7;
> ic2 := D(y)(0) = 5;
> interval := x=0..1;
> N := 10;
d2
ode := dx2
y(x) = 2 y(x)
70
APPENDIX B. MAPLE WORKSHEETS
ic1 := y(0) = 7
ic2 := D(y)(0) = 5
interval := x = 0..1
N := 10
We can use Maple to obtain an analytical solution for our ODE. This is achieved by
using dsolve with dierent parameters:
> ic1 := y(0) = 7;
> ic2 := D(y)(0) = 5;
> sol_true := dsolve({ode, ic1, ic2});
ic1 := y(0) = 7
ic2 := D(y)(0) = 5
7 5 2 (2 x) 7 5 2 (2 x)
sol true := y(x) = ( + )e +( )e
2 4 2 4
How dierent is this solution from those obtained by Eulers Forward Method? To
answer this question, we may wish to plot the two solutions on a single graph, just as
we did in the previous example.
> sol_true_f := unapply(op(2,sol_true),x);
> sol1_pts := MatrixToPoints(delcols(sol1, 3..3));
> plot([sol_true_f, sol1_pts], 0..1, labels=["x", "y"],
legend=["true",
> "Eulers Forward Method"]);
7 5 2 (2 x) 7 5 2 (2 x)
sol true f := x ( + )e +( )e
2 4 2 4
71
APPENDIX B. MAPLE WORKSHEETS
sol1 pts := [[0., 7.], [0.1, 7.5], [0.2, 8.14], [0.3, 8.930], [0.4, 9.8828], [0.5, 11.01420],
[0.6, 12.343256], [0.7, 13.8925960], [0.8, 15.68880112], [0.9, 17.76285816],
[1.0, 20.15069122]]
22
20
18
16
y 14
12
10
8
0 0.2 0.4 0.6 0.8 1
x
true
Eulers Forward Method
Just as before, the further from the initial point, the more the numerical solution
deviates from the true one. Also, the value of y is always greater for the true solution.
72
APPENDIX B. MAPLE WORKSHEETS
B.2 beuler.tex
B.2.1 Initialization
The following commands initialize Maple. The warnings that appear have no
adverse eects on the execution, so can be safely ignored.
> restart;
> with(DEtools):
> with(plots):
> with(linalg):
Warning, the protected names norm and trace have been redefined and
unprotected
B.2.2 Introduction
This worksheet provides several implementations of Backward Eulers Method and
demonstrates how they can be used to solve simple IV (initial value) problems.
circle.mws uses these results to analyze the circle problem and determine which of
the methods (Forward Eulers, Backward Eulers and Trapezium Rule) produces the
most satisfactory results.
B.2.3 Implementation
We provide multiple implementations of Backward Eulers Method, which dier in
their applicability to problems of dierent orders, the form of the parameters, etc. In
each specic case, the user should choose the most appropriate implementation. Here
is a brief overview:
BackwardEuler is similar to the above, but takes the parameters in a more natural
form, then converts them for its purposes and proceeds as SimpleEuler.
73
APPENDIX B. MAPLE WORKSHEETS
74
APPENDIX B. MAPLE WORKSHEETS
75
APPENDIX B. MAPLE WORKSHEETS
76
APPENDIX B. MAPLE WORKSHEETS
Supplementary procedures
The following procedure converts the x list returned by Maples dsolve to a list of
points, which can be plotted using plot.
> XListToPoints := proc(x_list)
> local points_array;
> points_array := x_list[2, 1];
> return convert(points_array, listlist);
> end proc:
B.2.4 Examples
Example 1: First order IV problem
Suppose we are trying to solve the ODE
77
APPENDIX B. MAPLE WORKSHEETS
d
dx y(x) = 3 y(x) + 5
with the initial condition given by y(0) = 7. We specify the problem as follows:
> F := (x, y) -> 3 * y + 5;
> x0 := 0;
> y0 := 7;
> h := 0.1;
> N := 10;
F := (x, y) 3 y + 5
x0 := 0
y0 := 7
h := 0.1
N := 10
Here is how we could use BackwardEuler to achieve the same result. Notice how the
parameters are passed in this case:
> ode := diff(y(x), x) = 3 * y(x) + 5;
> ic := y(0) = 7;
> interval := x=0..1;
> N := 10;
d
ode := dx y(x) = 3 y(x) + 5
ic := y(0) = 7
interval := x = 0..1
N := 10
78
APPENDIX B. MAPLE WORKSHEETS
We can use Maple to obtain an analytical solution for our ODE. This is achieved by
using dsolve with dierent parameters:
> sol_true := dsolve({ode, ic});
5 26 (3 x)
sol true := y(x) = + e
3 3
Many dierential equations do not have analytical solutions, or they are too dicult
to calculate. In this case we are lucky, as our equation is very simple.
To plot a solution that was obtained from a symbolic computation, we use plot.
However, we must extract the function rst and specify whichever parameters it
takes. In our case, x is the only parameter.
> sol_true_f := unapply(op(2,sol_true),x);
5 26 (3 x)
sol true f := x + e
3 3
> plot(sol_true_f, 0..1);
79
APPENDIX B. MAPLE WORKSHEETS
160
140
120
100
80
60
40
20
How dierent is this solution from those obtained by Eulers Forward Method? To
answer this question, we may wish to plot the two solutions on a single graph, just as
we did in the previous example.
> sol_true_f := unapply(op(2,sol_true),x);
> sol1_pts := MatrixToPoints(sol1);
> plot([sol_true_f, sol1_pts], 0..1, labels=["x", "y"],
legend=["true",
> "Eulers Forward Method"]);
5 26 (3 x)
sol true f := x + e
3 3
sol1 pts := [[0, 7], [0.1, 10.71428571], [0.2, 16.02040816], [0.3, 23.60058309],
[0.4, 34.42940441], [0.5, 49.89914916], [0.6, 71.99878451], [0.7, 103.5696922],
[0.8, 148.6709889], [0.9, 213.1014127], [1.0, 305.1448753]]
80
APPENDIX B. MAPLE WORKSHEETS
300
250
200
y 150
100
50
As you can see, the further from the initial point, the more the numerical solution
deviates from the true one. Note that the value of y returned by Eulers Backward
Method is always greater than the true value.
d
with the initial conditions given by y(0) = 7 and dx y(0) = 5. We specify the problem
as follows:
> ode := diff(diff(y(x), x), x) = 2 * y(x);
d2
ode := dx2
y(x) = 2 y(x)
Here is how we could express it in terms of the functions F and G, so that we can
apply SimpleBackwardEuler2 to obtain a solution:
81
APPENDIX B. MAPLE WORKSHEETS
> t := x;
> solve(ode, diff(diff(y(t), t), t));
> F := (x, _y, _z) -> _z;
> G := unapply(subs(y(t) = _y, diff(y(t), t) = _z, solve(ode,
> diff(diff(y(t), t), t))), (t, _y, _z));
> x0 := 0;
> y0 := 7;
> z0 := 5;
> h := 0.1;
> N := 10;
t := x
2 y(x)
F := (x, y, z ) z
G := (x, y, z ) 2 y
x0 := 0
y0 := 7
z0 := 5
h := 0.1
N := 10
Here is how we could use BackwardEuler2 to achieve the same result. Notice how the
parameters are passed in this case:
> ode := diff(diff(y(x), x), x) = 2 * y(x);
> ic1 := y(0) = 7;
> ic2 := D(y)(0) = 5;
> interval := x=0..1;
> N := 10;
d2
ode := dx2
y(x) = 2 y(x)
82
APPENDIX B. MAPLE WORKSHEETS
ic1 := y(0) = 7
ic2 := D(y)(0) = 5
interval := x = 0..1
N := 10
We can use Maple to obtain an analytical solution for our ODE. This is achieved by
using dsolve with dierent parameters:
> ic1 := y(0) = 7;
> ic2 := D(y)(0) = 5;
> sol_true := dsolve({ode, ic1, ic2});
ic1 := y(0) = 7
ic2 := D(y)(0) = 5
7 5 2 (2 x) 7 5 2 (2 x)
sol true := y(x) = ( + )e +( )e
2 4 2 4
How dierent is this solution from those obtained by Eulers Backward Method? To
answer this question, we may wish to plot the two solutions on a single graph, just as
we did in the previous example.
> sol_true_f := unapply(op(2,sol_true),x);
> sol1_pts := MatrixToPoints(delcols(sol1, 3..3));
> plot([sol_true_f, sol1_pts], 0..1, labels=["x", "y"],
legend=["true",
> "Eulers Backward Method"]);
7 5 2 (2 x) 7 5 2 (2 x)
sol true f := x ( + )e +( )e
2 4 2 4
83
APPENDIX B. MAPLE WORKSHEETS
sol1 pts := [[0., 7.], [0.1, 7.653061224], [0.2, 8.475635152], [0.3, 9.487968448],
[0.4, 10.71459362], [0.5, 12.18491713], [0.6, 13.93391902], [0.7, 16.00298052],
[0.8, 18.44085921], [0.9, 21.30483459], [1.0, 24.66205099]]
24
22
20
18
y 16
14
12
10
8
0 0.2 0.4 0.6 0.8 1
x
true
Eulers Backward Method
Just as before, the further from the initial point, the more the numerical solution
deviates from the true one. Also, the value of y is always smaller for the true solution.
84
APPENDIX B. MAPLE WORKSHEETS
B.3 trap.mws
Trapezium Rule
S. Amen, P.A. Bilokon, A.J. Brinley Codd, M. Fofaria, T. Shah
B.3.1 Initialization
The following commands initialize Maple. The warnings that appear have no
adverse eects on the execution, so can be ignored.
> restart;
> with(DEtools):
> with(plots):
> with(linalg):
Warning, the protected names norm and trace have been redefined and
unprotected
B.3.2 Implementation
Implementation : Trapezium rule
This implementation of the Trapezium rule technically should work for an ODE of
ANY order. The idea behind the implementation is produce a set of trapezium
equations for each of the variables that represent the dierent order derivatives, then
to simultaneously solve them to get the new set of values for each of the derivatives
and for y; then continue to get a list of y points.
85
APPENDIX B. MAPLE WORKSHEETS
rst to put it into a form admissible into our procedure. The procedure then
produced estimates for y and y.
This was performed three times by setting h = 0.1, 0.01, and 0.001 respectively. The
plot for h = 0.001 was not a complete circle because the number of calculations that
needed to be performed was too great.
> u := [x,y,z];
> f := [1,z,-1*y];
> ic := [0,1,0];
> soln := GeneralTrapezium(u,f,ic,0.1,10);
u := [x, y, z]
86
APPENDIX B. MAPLE WORKSHEETS
f := [1, z, y]
ic := [0, 1, 0]
0 1 0
0.1000000000 0.9950124688 -0.09975062344
0.2000000000 0.9800996262 -0.1985062282
0.3000000000 0.9554102288 -0.2952817209
0.4000000000 0.9211905548 -0.3891117600
0.5000000000 0.8777819475 -0.4790603851
0.6000000000 0.8256174105 -0.5642303530
0.7000000000 0.7652172884 -0.6437720879
0.8000000000 0.6971840762 -0.7168921561
0.9000000000 0.6221964094 -0.7828611804
1. 0.5410022946 -0.8410211156
1.100000000 0.4544116482 -0.8907918127
1.200000000 0.3632882173 -0.9316768060
1.300000000 0.2685409637 -0.9632682651
1.400000000 0.1711149972 -0.9852510632
1.500000000 0.07198214798 -0.9974059205
1.600000000 -0.02786872762 -0.9996115916
1.700000000 -0.1274416109 -0.9918460747
1.800000000 -0.2257432562 -0.9741868314
1.900000000 -0.3217930985 -0.9468100137
2. -0.4146330346 -0.9099887071
2.100000000 -0.5033369803 -0.8640902064
2.200000000 -0.5870201082 -0.8095723520
2.300000000 -0.6648476739 -0.7469789629
2.400000000 -0.7360433426 -0.6769344121
2.500000000 -0.7998969331 -0.6001373983
2.600000000 -0.8557715018 -0.5173539765
2.700000000 -0.9031096964 -0.4294099166
2.800000000 -0.9414393155 -0.3371824660
2.900000000 -0.9703780188 -0.2415915993
3. -0.9896371409 -0.1435908414
3.100000000 -0.9990245708 -0.04415775582
3.200000000 -0.9984466687 0.05571580615
3.300000000 -0.9879091984 0.1550335995
3.400000000 -0.9675172722 0.2528049230
3.500000000 -0.9374743009 0.3480545016
3.600000000 -0.8980799651 0.4398322149
3.700000000 -0.8497272257 0.5272225745
87
APPENDIX B. MAPLE WORKSHEETS
88
APPENDIX B. MAPLE WORKSHEETS
89
APPENDIX B. MAPLE WORKSHEETS
0.5
1 0.5 0 0.5 1
0.5
90
APPENDIX B. MAPLE WORKSHEETS
0.5
1 0.5 0.5 1
0.5
91
APPENDIX B. MAPLE WORKSHEETS
0.2
0.4
0.6
0.8
92
APPENDIX B. MAPLE WORKSHEETS
Now compare the analytical solution of this problem to the solutions obtained using
the trapezium rule.
> ode := diff(diff(y(x),x),x)=-y(x);
> ic1 := y(0) = 1; ic2 := D(y)(0) = 0;
> trueSoln := dsolve({ode, ic1, ic2});
d2
ode := dx2
y(x) = y(x)
ic1 := y(0) = 1
ic2 := D(y)(0) = 0
trueSoln := y(x) = cos(x)
> trueSoln := y(x) = cos(x);
> plot_real := []:
> plot_estimate := []:
> for i from 1 by 1 to 101 do
> plot_real := [op(plot_real),[soln[i,1], cos(soln [i,1])]]:
> plot_estimate := [op(plot_estimate),[soln[i,1], soln[i,2]]]:
> end do:
> plot([plot_real, plot_estimate]);
0.5
0 2 4 6 8 10
0.5
The plots for the real values and the values obtained using the trapezium rule are
incredibly close, as shown by the graph, which contains two lines, although this is not
obvious.
93
APPENDIX B. MAPLE WORKSHEETS
B.4 circle1.mws
B.4.1 Initialization
The following commands initialize Maple. The warnings that appear have no
adverse eects on the execution, so can be ignored.
> restart;
> with(DEtools):
> with(plots):
> with(linalg):
Warning, the protected names norm and trace have been redefined and
unprotected
B.4.2 Introduction
Consider the dierential equation
d2
y(x) = y(x)
dx2
with initial conditions y(0) = 1 and y (0) = 0.
The solution is readily available using analytical methods, pencil and paper. In fact,
it is
y(x) = cos(x),
and hence
y (x) = sin(x).
d2
ode := dx2
y(x) = y(x)
ic1 := y(0) = 1
ic2 := D(y)(0) = 0
94
APPENDIX B. MAPLE WORKSHEETS
Note the use of the dierential operator D(f ) for specifying the initial value
d
dx y(0) = 0.
Maple can calculate the true solution algebraically. By default, dsolve resorts to
algebraic methods.
> desol_true := dsolve({ode, ic1, ic2});
We have thus veried our solution. We shall use plot to plot the true solution.
However, we must extract the function ( f ) rst and specify whichever parameters it
takes. In our case, x is the only parameter.
> f := unapply(op(2,desol_true),x);
f := cos
0.5
10 8 6 4 2 0 2 4 6 8 10
0.5
d
We can also use Maple to produce a plot of dx y(x) against y(x):
> plot([f, D(f), -100..100]);
95
APPENDIX B. MAPLE WORKSHEETS
0.5
1 0.5 0 0.5 1
0.5
As you can see, the graph is a circle. The solution is periodic, the graph repeatedly
retraces the same path over the range of x.
We shall use this example to evaluate the quality of solutions produced by numerical
methods. Can they capture this periodic behaviour? By comparing the plots of
d
dx y(x) against y(x) for the various numerical methods with the true solution (the
circle, as shown above), we can reason about the quality of the models that they
provide.
rkf45 - A Fehlberg fourth-fth order Runge-Kutta method with degree four inter-
polant. This is the default non-sti numeric method.
96
APPENDIX B. MAPLE WORKSHEETS
taylorseries - A Taylor Series method. This method can be used for high accu-
racy solutions. It usually takes more time than other methods for low accuracy
results. Therefore, it is better to use this method only when a very high degree
of accuracy is desired.
heunform is the Heun formula (also known as the trapezoidal rule, or the im-
proved Euler method), as specied by the equation:
Y [n + 1] = Y [n] + (h/2) (f (t[n], Y [n]) + f (t[n + 1], Y [n + 1]))
impoly is the improved polygon method (also known as the modied Euler
method), as specied by the equation:
Y [n + 1] = Y [n] + h (f (t[n] + h/2, Y [n] + (h/2) f (t[n], Y [n])))
97
APPENDIX B. MAPLE WORKSHEETS
k1 = f (t[n], Y [n])
k2 = f (t[n] + h/2, Y [n] + (h/2) k1)
k3 = f (t[n] + h/2, Y [n] + (h/2) k2)
k4 = f (t[n] + h, Y [n] + h k3)
Y [n + 1] = Y [n] + (h/6) (k1 + 2 k2 + 2 k3 + k4)
where f(tn+1 , Yn+1 ) is found by rst applying the Adams-Bashford method (the pre-
dictor), then using the above Adams-Bashford-Moulton method (the corrector).
Stiness is dicult to dene because it involves both the IVP and the method applied
to solve it. A sti IVP has a solution that is very stable (some solutions that start
near it converge to it very quickly) and is slowly varying (other solutions change on
much faster time scales). Special methods allow sti problems to be solved eciently,
but they can be very inecient for problems that are not sti.
98
APPENDIX B. MAPLE WORKSHEETS
We shall now plot our graphs for the short range of x (-10..10), medium range
(-100..100) and long range (-500..500).
99
APPENDIX B. MAPLE WORKSHEETS
Short Range of x
> odeplot(desol_rkf45, [y(x), diff(y(x), x)], x=-10..10);
y 0.5
1 0.5 0.5 1
y
0.5
100
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0.5 1
y
0.5
101
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0.5 1
y
0.5
102
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0 0.5 1
y
0.5
103
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0.5 1
y
0.5
104
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0 0.5 1
y
0.5
105
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0 0.5 1
y
0.5
106
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0 0.5 1
y
0.5
107
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0 0.5 1
y
0.5
108
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0 0.5 1
y
0.5
109
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0.5 1
y
0.5
110
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0.5 1
y
0.5
111
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0.5 1
y
0.5
112
APPENDIX B. MAPLE WORKSHEETS
Medium Range of x
> odeplot(desol_rkf45, [y(x), diff(y(x), x)], x=-100..100);
y 0.5
1 0.5 0.5 1
y
0.5
113
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0 0.5 1
y
0.5
114
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0.5 1
y
0.5
115
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0.5 1
y
0.5
116
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0 0.5 1
y
0.5
117
APPENDIX B. MAPLE WORKSHEETS
y
0.5
1 0.5 0 0.5 1
y
0.5
118
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0 0.5 1
y
0.5
119
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0.5 1
y
0.5
120
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0 0.5 1
y
0.5
121
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0.5 1
y
0.5
122
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0.5 1
y
0.5
123
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0.5 1
y
0.5
124
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0 0.5 1
y
0.5
125
APPENDIX B. MAPLE WORKSHEETS
Long Range of x
> odeplot(desol_rkf45, [y(x), diff(y(x), x)], x=-500..500);
y 0.5
1 0.5 0.5 1
y
0.5
126
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0.5 1
y
0.5
127
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0 0.5 1
y
0.5
128
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0 0.5 1
y
0.5
129
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0 0.5 1
y
0.5
130
APPENDIX B. MAPLE WORKSHEETS
2
y
1
3 2 1 1 2 3
y
1
131
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0 0.5 1
y
0.5
132
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0 0.5 1
y
0.5
133
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0 0.5 1
y
0.5
134
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0.5 1
y
0.5
135
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0.5 1
y
0.5
136
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0.5 1
y
0.5
137
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0.5 1
y
0.5
138
APPENDIX B. MAPLE WORKSHEETS
B.4.4 Conclusion
For a small range of x all methods seem to be appropriate. However, as x gets further
from the initial value, Eulers forward method (classical) spirals out producing
highly inaccurate results. Other methods seem to cope well with this situation.
Please note that we have considered a single aspect of the problem, accuracy, over a
limited range of x. We did not assess any other parameters, including the
performance of the methods, which distinguish them from each other. Further work is
certainly required.
139
APPENDIX B. MAPLE WORKSHEETS
B.5 circle2.mws
B.5.1 Introduction
Consider the dierential equation
d2
y(x) = y(x)
dx2
with initial conditions y(0) = 1 and y (0) = 0.
The solution is readily available using analytical methods, pencil and paper. In fact,
it is
y(x) = cos(x),
and hence
y (x) = sin(x).
We now wish to integrate the above equation using Forward Eulers Method,
Backward Eulers Method and the Trapezium Rule. Our goal is to determine the
most appropriate method from this set. By most appropriate we mean, in this case,
the method that produces the smallest error and is thus closest to the true solution.
140
APPENDIX B. MAPLE WORKSHEETS
B.5.2 Implementation
The following procedures have been copied from feuler.mws, beuler.mws and
trap.mws. They implement the Forward Eulers Method, Backward Eulers Method
and the Trapezium Rule Method, respectively. We shall use the most general
implementations, which can be applied to the circle problem. In this case we are
indierent to their performance.
141
APPENDIX B. MAPLE WORKSHEETS
142
APPENDIX B. MAPLE WORKSHEETS
143
APPENDIX B. MAPLE WORKSHEETS
u := [x, y, z]
f := [1, z, y]
ic := [0, 1, 0]
The procedure then produces estimates for y and y.
This was performed three times by setting h = 0.1, 0.01, and 0.001 respectively. The
plot for h = 0.001 was not a complete circle because the number of calculations that
needed to be performed was too great.
FE, h = 0.1
> fe_sol1 := GeneralForwardEuler(u, f, ic, 0.1, 10):
> plot_yz := []:
> for i from 1 by 1 to 101 do
> plot_yz := [op(plot_yz), [fe_sol1[i,2], fe_sol1[i,3]]]:
> end do:
> plot(plot_yz);
0.5
1.5 1 0.5 0.5 1
0
0.5
1.5
144
APPENDIX B. MAPLE WORKSHEETS
FE, h = 0.01
> fe_sol2 := GeneralForwardEuler(u, f, ic, 0.01, 10):
> plot_yz := []:
> for i from 1 by 1 to 1001 do
> plot_yz := [op(plot_yz), [fe_sol2[i,2], fe_sol2[i,3]]]:
> end do:
> plot(plot_yz);
0.5
1 0.5 0 0.5 1
0.5
145
APPENDIX B. MAPLE WORKSHEETS
FE, h = 0.001
> fe_sol3 := GeneralForwardEuler(u, f, ic, 0.001, 10):
> plot_yz := []:
> for i from 1 by 1 to 1001 do
> plot_yz := [op(plot_yz), [fe_sol3[i,2], fe_sol3[i,3]]]:
> end do:
> plot(plot_yz);
0.2
0.4
0.6
0.8
146
APPENDIX B. MAPLE WORKSHEETS
BE, h = 0.1
> be_sol1 := GeneralBackwardEuler(u, f, ic, 0.1, 10):
> plot_yz := []:
> for i from 1 by 1 to 101 do
> plot_yz := [op(plot_yz), [be_sol1[i,2], be_sol1[i,3]]]:
> end do:
> plot(plot_yz);
0.8
0.6
0.4
0.2
0.8 0.6 0.4 0.2 0.2 0.4 0.6 0.8 1
0
0.2
0.4
0.6
0.8
147
APPENDIX B. MAPLE WORKSHEETS
FE, h = 0.01
> be_sol2 := GeneralBackwardEuler(u, f, ic, 0.01, 10):
> plot_yz := []:
> for i from 1 by 1 to 1001 do
> plot_yz := [op(plot_yz), [be_sol2[i,2], be_sol2[i,3]]]:
> end do:
> plot(plot_yz);
0.5
1 0.5 0.5 1
0.5
148
APPENDIX B. MAPLE WORKSHEETS
BE, h = 0.001
> be_sol3 := GeneralBackwardEuler(u, f, ic, 0.001, 10):
> plot_yz := []:
> for i from 1 by 1 to 1001 do
> plot_yz := [op(plot_yz), [be_sol3[i,2], be_sol3[i,3]]]:
> end do:
> plot(plot_yz);
0.2
0.4
0.6
0.8
149
APPENDIX B. MAPLE WORKSHEETS
TR, h = 0.1
> tr_sol1 := GeneralTrapezium(u, f, ic, 0.1, 10):
> plot_yz := []:
> for i from 1 by 1 to 101 do
> plot_yz := [op(plot_yz), [tr_sol1[i,2], tr_sol1[i,3]]]:
> end do:
> plot(plot_yz);
0.5
1 0.5 0 0.5 1
0.5
150
APPENDIX B. MAPLE WORKSHEETS
TR, h = 0.01
> tr_sol2 := GeneralTrapezium(u, f, ic, 0.01, 10):
> plot_yz := []:
> for i from 1 by 1 to 1001 do
> plot_yz := [op(plot_yz), [tr_sol2[i,2], tr_sol2[i,3]]]:
> end do:
> plot(plot_yz);
0.5
1 0.5 0.5 1
0.5
151
APPENDIX B. MAPLE WORKSHEETS
TR, h = 0.001
> tr_sol3 := GeneralTrapezium(u, f, ic, 0.001, 10):
> plot_yz := []:
> for i from 1 by 1 to 1001 do
> plot_yz := [op(plot_yz), [tr_sol3[i,2], tr_sol3[i,3]]]:
> end do:
> plot(plot_yz);
0.2
0.4
0.6
0.8
152
APPENDIX B. MAPLE WORKSHEETS
d2
ode := dx2
y(x) = y(x)
ic1 := y(0) = 1
ic2 := D(y)(0) = 0
trueSoln := y(x) = cos(x)
> plot_true := []:
> plot_fe := []:
> plot_be := []:
> plot_tr := []:
> for i from 1 by 1 to 101 do
> plot_true := [op(plot_true), [fe_sol1[i,1], cos(fe_sol1[i,1])]]:
> plot_fe := [op(plot_fe), [fe_sol1[i,1], fe_sol1[i,2]]]:
> plot_be := [op(plot_be), [be_sol1[i,1], be_sol1[i,2]]]:
> plot_tr := [op(plot_tr), [tr_sol1[i,1], tr_sol1[i,2]]]:
> end do:
> plot([plot_true, plot_fe, plot_be, plot_tr], labels=["y", "y"],
> legend=["True solution", "Forward Eulers Method", "Backward
Eulers
> Method", "Trapezium Rule Method"]);
1
y
0.5
2 4 y 6 8 10
0
0.5
1
1.5
True solution
Forward Eulers Method
Backward Eulers Method
153
APPENDIX B. MAPLE WORKSHEETS
The plots for the real values and the values obtained using the Trapezium Rule are
extremely close, as shown by the graph, which contains two lines, although this is not
obvious.
> err_plot_fe := []:
> err_plot_be := []:
> err_plot_tr := []:
> for i from 1 by 1 to 101 do
> err_plot_fe := [op(err_plot_fe), [fe_sol1[i,1],
> abs(cos(fe_sol1[i,1]) - fe_sol1[i,2])]]:
> err_plot_be := [op(err_plot_be), [be_sol1[i,1],
> abs(cos(be_sol1[i,1]) - be_sol1[i,2])]]:
> err_plot_tr := [op(err_plot_tr), [tr_sol1[i,1],
> abs(cos(tr_sol1[i,1]) - tr_sol1[i,2])]]:
> end do:
> plot([err_plot_fe, err_plot_be, err_plot_tr], labels=["x",
"Error"],
> legend=["Forward Eulers Method", "Backward Eulers Method",
> "Trapezium Rule Method"]);
0.6
0.5
0.4
Error 0.3
0.2
0.1
0 2 4 6 8 10
x
Forward Eulers Method
Backward Eulers Method
Trapezium Rule Method
For the Forward and Backward Euler Method, the error oscillates with x, producing
increasing maxima as x increases. Notably it decreases to 0 for each of the methods
where the graph of y crosses the x-axis.
154
APPENDIX B. MAPLE WORKSHEETS
We shall now consider the error for each method at x = 2 (or the closest point
returned by the procedure).
> evalf(2 * Pi);
> fe_err1 := [0.1, abs(fe_sol1[64, 2] - cos(fe_sol1[64, 1]))];
> fe_err2 := [0.01, abs(fe_sol2[629, 2] - cos(fe_sol2[629, 1]))];
> fe_err3 := [0.001, abs(fe_sol3[6284, 2] - cos(fe_sol3[6284,
1]))];
> fe_err := [fe_err1, fe_err2, fe_err3];
> be_err1 := [0.1, abs(be_sol1[64, 2] - cos(be_sol1[64, 1]))];
> be_err2 := [0.01, abs(be_sol2[629, 2] - cos(be_sol2[629, 1]))];
> be_err3 := [0.001, abs(be_sol3[6284, 2] - cos(be_sol3[6284,
1]))];
> be_err := [be_err1, be_err2, be_err3];
> tr_err1 := [0.1, abs(tr_sol1[64, 2] - cos(tr_sol1[64, 1]))];
> tr_err2 := [0.01, abs(tr_sol2[629, 2] - cos(tr_sol2[629, 1]))];
> tr_err3 := [0.001, abs(tr_sol3[6284, 2] - cos(tr_sol3[6284,
1]))];
> tr_err := [tr_err1, tr_err2, tr_err3];
6.283185308
fe err1 := [0.1, 0.3682471926]
fe err2 := [0.01, 0.0318956901]
fe err3 := [0.001, 0.0031464292]
fe err := [[0.1, 0.3682471926], [0.01, 0.0318956901], [0.001, 0.0031464292]]
be err1 := [0.1, 0.2689330814]
be err2 := [0.01, 0.0309111282]
be err3 := [0.001, 0.0031365719]
be err := [[0.1, 0.2689330814], [0.01, 0.0309111282], [0.001, 0.0031365719]]
tr err1 := [0.1, 0.0000744028]
tr err2 := [0.01, 0.1665 106 ]
tr err3 := [0.001, 0.5 109 ]
tr err := [[0.1, 0.0000744028], [0.01, 0.1665 106 ], [0.001, 0.5 109 ]]
155
APPENDIX B. MAPLE WORKSHEETS
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0 0.02 0.04 0.06 0.08 0.1
The graph demonstrates that the error is proportional to h, as each plot is a straight
line.
B.5.5 Conclusion
As h gets smaller the Forward Eulers Method remains periodic for some time, but
eventually spirals outwards, whereas the Backward Eulers Method spirals inwards.
Trapezium Rule Method remains periodic for all h. This is due to the symmetricity
property substituting h h into the method leaves it unaltered, so the result for
h is the same as the result for h. This is not the case for the Forward and Backward
Eulers method. Thus the Forward and Backward Eulers methods are not symmetric.
156
APPENDIX B. MAPLE WORKSHEETS
B.6 4thorder.mws
B.6.1 Initialization
The following commands initialize Maple. The warnings that appear have no
adverse eects on the execution, so can be ignored.
> restart;
> with(DEtools):
> with(plots):
> with(linalg):
Warning, the protected names norm and trace have been redefined and
unprotected
B.6.2 Implementation
ans := [];
solveEqns := [];
157
APPENDIX B. MAPLE WORKSHEETS
assignList := [];
# increment first x by h
icx := icx + h;
# generate x coordinate
solveEqns := [op(1,u) = icx];
#print(solveEqns);
assignList := [];
158
APPENDIX B. MAPLE WORKSHEETS
ans := [op(ans),ic];
end do;
# eg. if u = [x,y,z]
# matrix returned giving values at each
return matrix(ans);
end proc:
ans := [];
solveEqns := [];
assignList := [];
159
APPENDIX B. MAPLE WORKSHEETS
# interval points
while icx < interval do
# icxhalf := icx + h/2;
# increment first x by h
icx := icx + h;
# generate x coordinate
solveEqns := [op(1,u) = icx];
assignList := [];
end do;
160
APPENDIX B. MAPLE WORKSHEETS
ans := [op(ans),ic];
end do;
# eg. if u = [x,y,z]
# matrix returned giving values at each
return matrix(ans);
end proc:
ic := init;
ans := [];
solveEqns := [];
assignList := [];
161
APPENDIX B. MAPLE WORKSHEETS
# generate x coordinate
solveEqns := [op(1,u) = icx];
assignList := [];
end do;
162
APPENDIX B. MAPLE WORKSHEETS
ans := [op(ans),ic];
end do;
# eg. if u = [x,y,z]
# matrix returned giving values at each
return matrix(ans);
end proc:
Now we can call the above procedures to solve the circle problem. Use method A.
> u := [x,y,z];
> f := [1,z,-1*y];
> ic := [0,1,0];
> # make a copy of variables that will be used to store ynhalf,
> znhalf...
> # make copy of f for the same purpose
> uh := [xhalf, yhalf, zhalf];
> fh := [1,zhalf,-1*yhalf];
> soln1 := FourthOrderFirst(u,f,uh, fh, ic,0.1,10);
u := [x, y, z]
f := [1, z, y]
ic := [0, 1, 0]
uh := [xhalf , yhalf , zhalf ]
fh := [1, zhalf , yhalf ]
0 1 0
0.1000000000 0.9950041666 -0.09983340284
0.2000000000 0.9800665833 -0.1986693036
0.3000000000 0.9553365013 -0.2955201669
0.4000000000 0.9210610155 -0.3894182912
0.5000000000 0.8775825950 -0.4794254777
0.6000000000 0.8253356617 -0.5646424047
0.7000000000 0.7648422496 -0.6442176130
0.8000000000 0.6967067887 -0.7173560136
163
APPENDIX B. MAPLE WORKSHEETS
164
APPENDIX B. MAPLE WORKSHEETS
5. 0.2836615207 0.9589244722
5.100000000 0.3779770881 0.9258149505
5.200000000 0.4685160345 0.8834549944
5.300000000 0.5543737247 0.8322678505
5.400000000 0.6346922976 0.7727649636
5.500000000 0.7086692366 0.7055408668
5.600000000 0.7755653888 0.6312672409
5.700000000 0.8347123501 0.5506862031
5.800000000 0.8855191439 0.4646028923
5.900000000 0.9274781256 0.3738774243
6. 0.9601700549 0.2794162976
6.100000000 0.9832682852 0.1821633365
6.200000000 0.9965420266 0.08309026006
6.300000000 0.9998586529 -0.01681302666
6.400000000 0.9931850240 -0.1165483233
6.500000000 0.9765878214 -0.2151191079
6.600000000 0.9502328788 -0.3115404941
6.700000000 0.9143835260 -0.4048490715
6.800000000 0.8693979578 -0.4941125319
6.900000000 0.8157256550 -0.5784389846
7. 0.7539028933 -0.6569858678
7.100000000 0.6845473853 -0.7289683671
7.200000000 0.6083521080 -0.7936672575
7.300000000 0.5260783792 -0.8504360892
7.400000000 0.4385482506 -0.8987076470
7.500000000 0.3466362940 -0.9379996175
7.600000000 0.2512608631 -0.9679194085
7.700000000 0.1533749174 -0.9881680715
7.800000000 0.05395650073 -0.9985432884
7.900000000 -0.04600103131 -0.9989413936
8. -0.1454989364 -0.9893584093
8.100000000 -0.2435430646 -0.9698900856
8.200000000 -0.3391537917 -0.9407309435
8.300000000 -0.4313758071 -0.9021723314
8.400000000 -0.5192876592 -0.8545995140
8.500000000 -0.6020109622 -0.7984878232
8.600000000 -0.6787191723 -0.7343979082
8.700000000 -0.7486458466 -0.6629701341
8.800000000 -0.8110923012 -0.5849181834
8.900000000 -0.8654345918 -0.5010219252
9. -0.9111297485 -0.4121196229
165
APPENDIX B. MAPLE WORKSHEETS
Use method B.
> u := [x,y,z];
> f := [1,z,-1*y];
> ic := [0,1,0];
> # make a copy of variables that will be used to store ynhalf,
> znhalf...
> # make copy of f for the same purpose
> uh := [xhalf, yhalf, zhalf];
> fh := [1,zhalf,-1*yhalf];
> solnA1 := FourthOrderFirstAcc(u,f,uh, fh, ic,0.1,10);
u := [x, y, z]
f := [1, z, y]
ic := [0, 1, 0]
uh := [xhalf , yhalf , zhalf ]
fh := [1, zhalf , yhalf ]
0 1 0
0.1000000000 0.9950041658 -0.09983342015
0.2000000000 0.9800665799 -0.1986693379
0.3000000000 0.9553364937 -0.2955202175
0.4000000000 0.9210610021 -0.3894183571
0.5000000000 0.8775825743 -0.4794255576
0.6000000000 0.8253356324 -0.5646424968
0.7000000000 0.7648422106 -0.6442177155
0.8000000000 0.6967067390 -0.7173561244
0.9000000000 0.6216100048 -0.7833269488
1. 0.5403023494 -0.8414710301
1.100000000 0.4535961722 -0.8912074118
1.200000000 0.3623578124 -0.9320391446
1.300000000 0.2674988935 -0.9635582513
1.400000000 0.1699672144 -0.9854498035
166
APPENDIX B. MAPLE WORKSHEETS
167
APPENDIX B. MAPLE WORKSHEETS
168
APPENDIX B. MAPLE WORKSHEETS
u := [x, y, z]
f := [1, z, y]
ic := [0, 1, 0]
uh := [xhalf , yhalf , zhalf ]
fh := [1, zhalf , yhalf ]
0 1 0
0.1000000000 0.9950041666 -0.09983340284
0.2000000000 0.9800665833 -0.1986693036
0.3000000000 0.9553365013 -0.2955201669
0.4000000000 0.9210610155 -0.3894182912
0.5000000000 0.8775825950 -0.4794254777
0.6000000000 0.8253356617 -0.5646424047
0.7000000000 0.7648422496 -0.6442176130
0.8000000000 0.6967067887 -0.7173560136
0.9000000000 0.6216100658 -0.7833268320
1. 0.5403024223 -0.8414709098
1.100000000 0.4535962572 -0.8912072908
1.200000000 0.3623579094 -0.9320390256
1.300000000 0.2674990022 -0.9635581371
1.400000000 0.1699673341 -0.9854496969
1.500000000 0.07073740906 -0.9974949718
1.600000000 -0.02919930059 -0.9995736094
1.700000000 -0.1288442605 -0.9916648407
1.800000000 -0.2272018516 -0.9738476875
1.900000000 -0.3232893175 -0.9463001728
2. -0.4161465844 -0.9092975422
169
APPENDIX B. MAPLE WORKSHEETS
170
APPENDIX B. MAPLE WORKSHEETS
We can make a phase plot, for methods A and B for h = 0.1. We see that we do not
have any spiral shape, like with backward and forward Eulers methods.
171
APPENDIX B. MAPLE WORKSHEETS
0.5
1 0.5 0.5 1
0.5
Fourth Order A
Fourth Order B
Now compare the analytical solution of this problem to the solutions obtained using
the trapezium rule.
> ode := diff(diff(y(x),x),x)=-y(x);
> ic1 := y(0) = 1; ic2 := D(y)(0) = 0;
> trueSoln := dsolve({ode, ic1, ic2});
172
APPENDIX B. MAPLE WORKSHEETS
d2
ode := dx2
y(x) = y(x)
ic1 := y(0) = 1
ic2 := D(y)(0) = 0
trueSoln := y(x) = cos(x)
> ode := diff(y(x),$(x,2)) = -y(x);
2
2 y(x) = y(x)
d
ode := dx
> trueSoln := y(x) = cos(x);
trueSoln := y(x) = cos(x)
> plot_real := []:
> plot_estimate := []:
> plot_accestimate := []:
> for i from 1 by 1 to 101 do
> plot_real := [op(plot_real),[soln1[i,1], cos(soln1 [i,1])]]:
> plot_estimate := [op(plot_estimate),[soln1[i,1], soln1[i,2]]]:
> plot_accestimate := [op(plot_accestimate),[solnA1[i,1],
> solnA1[i,2]]]:
> end do:
> # plotsetup("ps", plotoutput="h:/fourth-plot.eps",
> plotoptions="color");
> plotsetup(default);
> plot([plot_estimate, plot_accestimate], legend=["Fourth Order A",
> "Fourth Order B"] , color=[red,black, green],
style=[line,point]);
The plots for the real values and the values obtained using the fourth order rule A
and fourth order (acc) B are incredibly close, as shown by the graph, which contains
two lines, although this is not obvious.
173
APPENDIX B. MAPLE WORKSHEETS
0.5
0 2 4 6 8 10
0.5
Fourth Order A
Fourth Order B
174
APPENDIX B. MAPLE WORKSHEETS
1e06
8e07
Err 6e07
4e07
2e07
0 2 4 6 8 10
x
Fourth Order A
Fourth Order B
175
APPENDIX B. MAPLE WORKSHEETS
1e06
8e07
Err 6e07
4e07
2e07
0 2 4 6 8 10
x
Fourth Order B
Fourth Order Lobatto
176
APPENDIX B. MAPLE WORKSHEETS
B.7 4thorderKepler.mws
B.7.1 Initialization
The following commands initialize Maple. The warnings that appear have no
adverse eects on the execution, so can be ignored.
> restart;
> with(DEtools):
> with(plots):
> with(linalg):
Warning, the protected names norm and trace have been redefined and
unprotected
B.7.2 Implementation
ic := init;
ans := [];
177
APPENDIX B. MAPLE WORKSHEETS
icx := op(1,ic);
ans := [op(ans),ic];
solveEqns := [];
assignList := [];
# increment first x by h
icx := icx + h;
# generate x coordinate
solveEqns := [op(1,u) = icx];
assignList := [];
178
APPENDIX B. MAPLE WORKSHEETS
end do;
ans := [op(ans),ic];
end do;
# eg. if u = [x,y,z]
# matrix returned giving values at each
return matrix(ans);
end proc:
We can modify the above to get a better estimation for yhalf, by using a fourth
order method, method B.
179
APPENDIX B. MAPLE WORKSHEETS
ans := [];
solveEqns := [];
assignList := [];
# increment first x by h
icx := icx + h;
# generate x coordinate
solveEqns := [op(1,u) = icx];
# print(solveEqns);
assignList := [];
180
APPENDIX B. MAPLE WORKSHEETS
end do;
ans := [op(ans),ic];
end do;
# eg. if u = [x,y,z]
# matrix returned giving values at each
return matrix(ans);
end proc:
d2 z(x)
2
z(x) = 3
dx (y(x)2 + z(x)2 )( 2 )
181
APPENDIX B. MAPLE WORKSHEETS
We can use the same trick that we used earlier to make into a set of four rst order
dierential equations.
d
y(x) = a(x)
dx
d y(x)
a(x) = 3
dx (y(x)2 + z(x)2 )( 2 )
d
z(x) = b(x)
dx
d z(x)
b(x) = 3
dx (y(x) + z(x)2 )( 2 )
2
Try to solve analytically. Maple does not produce a solution! We could solve using
polar coordinates though.
> ode1 := diff(diff(y(x),x),x)=-y(x)/(y(x)^2+z(x)^2)^(3/2):
> ode2 := diff(diff(z(x),x),x)=-z(x)/(y(x)^2+z(x)^2)^(3/2):
> ecc := 0.6:
> ic1 := y(0) = 1-ecc; ic2 := D(y)(0) = 0; ic3 := z(0) = 0; ic4 :=
> D(z)(0) = sqrt((1+ecc)/(1-ecc)):
> trueSoln := dsolve({ode1, ode2, ic1, ic2, ic3, ic4}, {y(x),
> z(x)}):
182
APPENDIX B. MAPLE WORKSHEETS
> u := [x,y,a,z,b]:
> ecc := 0.5:
> GM := 4*Pi^2:
> f := [1,a,-GM*y/((y^2+z^2)^(3/2)),b,-GM*z/((y^2+z^2)^(3/2))]:
> # initial conditions
> ic := [0,0,2*Pi,1,-Pi]:
> # make a copy of variables that will be used to store ynhalf,
> znhalf...
> # make copy of f for the same purpose
> uh := [xhalf, yhalf, ahalf, zhalf, bhalf]:
> sv := [yhalf, zhalf]:
> fh :=
> [1,ahalf,-GM*yhalf/((yhalf^2+zhalf^2)^(3/2)),bhalf,-GM*zhalf/((yhalf^2
> +zhalf^2)^(3/2))]:
> solnKsA1 := FourthOrderFirstKeplerAcc(u,f,uh, fh, sv, ic, 0.1,
10):
> solnKs1 := FourthOrderFirstKepler(u,f,uh, fh, sv, ic, 0.1, 10):
0 0.4 0 0 2.000000000
0.1000000000 0.3698493407 -0.5831814464 0.1950024383 1.855583318
0.2000000000 0.2899170806 -0.9788548839 0.3649299360 1.527357437
0.3000000000 0.1808150702 -1.175527933 0.4998220431 1.175084108
0.4000000000 0.05905311296 -1.244096738 0.6016711559 0.8719912489
0.5000000000 -0.06575964731 -1.244209938 0.6762448393 0.6289302191
0.6000000000 -0.1886747505 -1.210226409 0.7291563387 0.4367902863
0.7000000000 -0.3072750181 -1.159996061 0.7649106767 0.2839804549
0.8000000000 -0.4204410193 -1.102600756 0.7869397947 0.1608952773
0.9000000000 -0.5277136429 -1.042669491 0.7978383971 0.06035133687
1.000000000 -0.6289705762 -0.9825610602 0.7995851098 -0.02288245909
183
APPENDIX B. MAPLE WORKSHEETS
184
APPENDIX B. MAPLE WORKSHEETS
185
APPENDIX B. MAPLE WORKSHEETS
0 0.4 0 0 2.000000000
0.1000000000 0.3698428971 -0.5833124717 0.1950018222 1.855569226
0.2000000000 0.2898942069 -0.9790517251 0.3649265445 1.527311820
0.3000000000 0.1807716631 -1.175738236 0.4998122390 1.175001023
0.4000000000 0.05898930502 -1.244292312 0.6016514225 0.8718778324
0.5000000000 -0.06584176971 -1.244380162 0.6762127663 0.6287990827
0.6000000000 -0.1887725482 -1.210370035 0.7291107362 0.4366524852
0.7000000000 -0.3073859472 -1.160115696 0.7648512954 0.2838437542
0.8000000000 -0.4205628666 -1.102700158 0.7868670136 0.1607646399
0.9000000000 -0.5278445773 -1.042752454 0.7977529863 0.06022976603
1.000000000 -0.6291091298 -0.9826310247 0.7994880708 -0.02299324058
1.100000000 -0.7244051552 -0.9235159195 0.7936030495 -0.09271339254
1.200000000 -0.8138648694 -0.8659641363 0.7813011723 -0.1517307906
1.300000000 -0.8976577725 -0.8101988724 0.7635434060 -0.2021317977
1.400000000 -0.9759657795 -0.7562638640 0.7411089500 -0.2454935350
1.500000000 -1.048969898 -0.7041074699 0.7146386677 -0.2830250892
1.600000000 -1.116843241 -0.6536291927 0.6846666876 -0.3156656971
1.700000000 -1.179747570 -0.6047056398 0.6516437368 -0.3441537921
1.800000000 -1.237831799 -0.5572049956 0.6159546256 -0.3690761988
1.900000000 -1.291231586 -0.5109949723 0.5779315379 -0.3909036538
2.000000000 -1.340069522 -0.4659470141 0.5378642743 -0.4100167920
2.100000000 -1.384455622 -0.4219383366 0.4960082529 -0.4267253897
2.200000000 -1.424487949 -0.3788527143 0.4525908405 -0.4412827760
2.300000000 -1.460253272 -0.3365805516 0.4078164272 -0.4538967325
2.400000000 -1.491827723 -0.2950185508 0.3618705474 -0.4647378066
2.500000000 -1.519277396 -0.2540691634 0.3149232696 -0.4739456929
2.600000000 -1.542658888 -0.2136399337 0.2671320258 -0.4816341500
2.700000000 -1.562019779 -0.1736427962 0.2186440069 -0.4878947914
2.800000000 -1.577399032 -0.1339933622 0.1695982253 -0.4927999950
2.900000000 -1.588827324 -0.09461021404 0.1201273230 -0.4964051085
3.000000000 -1.596327310 -0.05541421242 0.07035918865 -0.4987500796
3.100000000 -1.599913818 -0.01632782030 0.02041843665 -0.4998606015
3.200000000 -1.599593974 0.02272556072 -0.02957220702 -0.4997488364
186
APPENDIX B. MAPLE WORKSHEETS
187
APPENDIX B. MAPLE WORKSHEETS
188
APPENDIX B. MAPLE WORKSHEETS
189
APPENDIX B. MAPLE WORKSHEETS
0.5
1 0.5 0.5 z 1 1.5
0
0.5
y 1
1.5
2
z
0.8 0.6 0.4 0.2 0.2 0.4 0.6 0.8
0
0.5
y
1
1.5
190
APPENDIX B. MAPLE WORKSHEETS
B.8 modtrap.mws
Version 1.0
Version History
B.8.1 Initialization
The following commands initialize Maple. The warnings that appear have no
adverse eects on the execution, so can be ignored.
> restart;
> with(DEtools):
> with(plots):
> with(linalg):
Warning, the protected names norm and trace have been redefined and
unprotected
B.8.2 Implementation
ic := init;
191
APPENDIX B. MAPLE WORKSHEETS
makeeqn := nops(u);
ans := [];
solveEqns := [];
assignList := [];
# generate x coordinate
solveEqns := [op(1,u) = icx];
assignList := [];
# now solve
192
APPENDIX B. MAPLE WORKSHEETS
solveEqns := [
op(solveEqns),
op(i,u) = op(i,ic) + h*(ynD) +
(h^2/4)*(op(i+1,f) + ynDD),
op(i+1, u) = ynD + (h/2)*(op(i+1,f) + ynDD)];
end do;
ans := [op(ans),ic];
end do;
# eg. if u = [x,y,z]
# matrix returned giving values at each
return matrix(ans);
end proc:
ic := init;
ans := [];
193
APPENDIX B. MAPLE WORKSHEETS
solveEqns := [];
assignList := [];
# increment first x by h
icx := icx + h;
# generate x coordinate
solveEqns := [op(1,u) = icx];
assignList := [];
solveEqns := [
op(solveEqns),
194
APPENDIX B. MAPLE WORKSHEETS
end do;
ans := [op(ans),ic];
end do;
# eg. if u = [x,y,z]
# matrix returned giving values at each
return matrix(ans);
end proc:
ic := init;
ans := [];
solveEqns := [];
195
APPENDIX B. MAPLE WORKSHEETS
assignList := [];
# increment first x by h
icx := icx + h;
# generate x coordinate
solveEqns := [op(1,u) = icx];
assignList := [];
196
APPENDIX B. MAPLE WORKSHEETS
end do;
ans := [op(ans),ic];
end do;
# eg. if u = [x,y,z]
# matrix returned giving values at each
return matrix(ans);
end proc:
ans := [];
solveEqns := [];
197
APPENDIX B. MAPLE WORKSHEETS
assignList := [];
# increment first x by h
icx := icx + h;
# generate x coordinate
solveEqns := [op(1,u) = icx];
#print(solveEqns);
assignList := [];
solveEqns := [
op(solveEqns),
op(i,u) = op(i,ic) + h*(ynD) +
(h^2/12)*(4*op(i+1,fhalves) + 2*ynDD),
op(i, uhalves) = 1/2*(op(i,u) + op(i,ic)) -
(h^2/48)*(op(i+1,f) + 4*op(i+1,fhalves) + ynDD),
op(i+1, u) = ynD + (h/6)*(op(i+1,f) +
198
APPENDIX B. MAPLE WORKSHEETS
4*op(i+1,fhalves) + ynDD)
];
end do;
# print(solveEqns);
# find yn1 and ynhalf, by iterative process
#print(newICSet);
# replace kth "initial condition" with updated value
for k from 1 by 1 to makeeqn do
ic := subsop(k = eval(op(k,u),newICSet),ic);
end do;
ans := [op(ans),ic];
end do;
# eg. if u = [x,y,z]
# matrix returned giving values at each
return matrix(ans);
end proc:
0 1 0
0.1000000000 0.9950041666 -0.09983340284
0.2000000000 0.9800665833 -0.1986693036
0.3000000000 0.9553365013 -0.2955201669
0.4000000000 0.9210610155 -0.3894182912
0.5000000000 0.8775825950 -0.4794254777
0.6000000000 0.8253356617 -0.5646424047
199
APPENDIX B. MAPLE WORKSHEETS
200
APPENDIX B. MAPLE WORKSHEETS
201
APPENDIX B. MAPLE WORKSHEETS
0 1 0
0.1000000000 0.9950124688 -0.09975062344
0.2000000000 0.9800996262 -0.1985062282
0.3000000000 0.9554102287 -0.2952817209
0.4000000000 0.9211905546 -0.3891117600
0.5000000000 0.8777819473 -0.4790603851
0.6000000000 0.8256174104 -0.5642303530
0.7000000000 0.7652172884 -0.6437720879
0.8000000000 0.6971840762 -0.7168921561
0.9000000000 0.6221964094 -0.7828611804
1. 0.5410022947 -0.8410211156
1.100000000 0.4544116483 -0.8907918127
1.200000000 0.3632882174 -0.9316768060
1.300000000 0.2685409639 -0.9632682651
1.400000000 0.1711149975 -0.9852510632
1.500000000 0.07198214832 -0.9974059205
1.600000000 -0.02786872728 -0.9996115916
1.700000000 -0.1274416106 -0.9918460747
1.800000000 -0.2257432560 -0.9741868314
1.900000000 -0.3217930983 -0.9468100137
2. -0.4146330344 -0.9099887071
2.100000000 -0.5033369800 -0.8640902064
2.200000000 -0.5870201079 -0.8095723520
202
APPENDIX B. MAPLE WORKSHEETS
203
APPENDIX B. MAPLE WORKSHEETS
We can make a phase plot, for both methods for h =0.1, alongside phase plot from
the exact solution. We see that we do not have any spiral shape, like with backward
and forward Eulers methods.
204
APPENDIX B. MAPLE WORKSHEETS
0.5
1 0.5 0.5 1
0.5
Fourth Order A
Mod Trap
Now compare the analytical solution of this problem to the solutions obtained using
the trapezium rule.
> ode := diff(diff(y(x),x),x)=-y(x):
> ic1 := y(0) = 1; ic2 := D(y)(0) = 0:
> trueSoln := dsolve({ode, ic1, ic2});
ic1 := y(0) = 1
205
APPENDIX B. MAPLE WORKSHEETS
The plots for the real values and the values obtained using the fourth order rule A
and modied trapezium rule are incredibly close, as shown by the graph, which
contains two lines, although this is not obvious.
0.5
0 2 4 6 8 10
0.5
Real Sol
Fourth Order A
Mod Trap
206
APPENDIX B. MAPLE WORKSHEETS
Comparing errors between modied trapezium and fourth order A. We see fourth
order A produces a far smaller error.
> err_plot_f := []:
> err_plot_f4 := []:
> err_plot_fMT := []:
> for i from 1 by 1 to 101 do
> #err_plot_f := [op(err_plot_f), [soln1[i,1],
abs(cos(soln1[i,1]) -
> soln1[i,2])]]:
> err_plot_f4 := [op(err_plot_f4), [solnF1[i,1],
> abs(cos(solnF1[i,1]) - solnF1[i,2])]]:
> err_plot_fMT := [op(err_plot_fMT), [solnMT1[i,1],
> abs(cos(solnMT1[i,1]) - solnMT1[i,2])]]:
> end do:
> # plotsetup("ps", plotoutput="mt-errorplot.eps",
plotoptions="color");
> # plot([err_plot_f4, err_plot_fMT], labels=["x", "Err"],
color=[green,
> red], style=[line, point], legend=["Fourth Order A", "Modified
> Trapezium"]);
> plotsetup(default);
> plot([err_plot_f4, err_plot_fMT], labels=["x", "Err"],
color=[green,
> red], style=[point, point], legend=["Fourth Order A", "Modified
> Trapezium"]);
0.006
0.005
0.004
Err
0.003
0.002
0.001
0 2 4 6 8 10
x
Fourth Order A
Modified Trapezium
207
APPENDIX B. MAPLE WORKSHEETS
u := [x, y, a, z, b]
ecc := 0.6
y z
f := [1, a, 2 (3/2)
, b, 2 ]
2
(y + z ) (y + z 2 )(3/2)
0 , 0.4 , 0 , 0 , 2.000000000
0.1000000000 , 0.3717461794 , -0.5650764113 , 0.1934289064 , 1.868578127
0.2000000000 , 0.2954734956 , -0.9603772650 , 0.3649025651 , 1.560895046
0.3000000000 , 0.1892688510 , -1.163715628 , 0.5041069212 , 1.223192076
0.4000000000 , 0.06912615463 , -1.239138300 , 0.6118008007 , 0.9306855150
0.5000000000 , -0.05511826243 , -1.245750041 , 0.6931618727 , 0.6965359268
0.6000000000 , -0.1783235145 , -1.218355001 , 0.7536046312 , 0.5123192433
0.7000000000 , -0.2979920172 , -1.175015052 , 0.7975492753 , 0.3665736390
0.8000000000 , -0.4129844678 , -1.124833959 , 0.8283644842 , 0.2497305393
0.9000000000 , -0.5228458659 , -1.072394002 , 0.8485836330 , 0.1546524370
1.000000000 , -0.6274654111 , -1.019996902 , 0.8601246637 , 0.07616817656
1.100000000 , -0.7269040261 , -0.9687753985 , 0.8644597702 , 0.01053395236
1.200000000 , -0.8213054183 , -0.9192524448 , 0.8627370569 , -0.04498821867
1.300000000 , -0.9108494994 , -0.8716291768 , 0.8558661873 , -0.09242917303
1.400000000 , -0.9957277982 , -0.8259367988 , 0.8445788149 , -0.1333182744
1.500000000 , -1.076130555 , -0.7821183497 , 0.8294716716 , -0.1688245928
1.600000000 , -1.152240141 , -0.7400733803 , 0.8110377154 , -0.1998545312
1.700000000 , -1.224227937 , -0.6996825433 , 0.7896889817 , -0.2271201431
1.800000000 , -1.292253118 , -0.6608210863 , 0.7657735946 , -0.2511876002
1.900000000 , -1.356462479 , -0.6233661195 , 0.7395886113 , -0.2725120662
2.000000000 , -1.416990803 , -0.5872003563 , 0.7113898509 , -0.2914631405
2.100000000 , -1.473961513 , -0.5522138484 , 0.6813995102 , -0.3083436711
2.200000000 , -1.527487435 , -0.5183045857 , 0.6498121346 , -0.3234038398
2.300000000 , -1.577671588 , -0.4853784655 , 0.6167993509 , -0.3368518341
2.400000000 , -1.624607957 , -0.4533489245 , 0.5825136582 , -0.3488620218
2.500000000 , -1.668382222 , -0.4221364040 , 0.5470914933 , -0.3595812771
2.600000000 , -1.709072429 , -0.3916677479 , 0.5106557334 , -0.3691339215
2.700000000 , -1.746749596 , -0.3618755896 , 0.4733177564 , -0.3776256179
208
APPENDIX B. MAPLE WORKSHEETS
209
APPENDIX B. MAPLE WORKSHEETS
210
APPENDIX B. MAPLE WORKSHEETS
> u := [x,y,a,z,b];
> ecc := 0.6;
> f := [1,a,-y/((y^2+z^2)^(3/2)),b,-z/((y^2+z^2)^(3/2))];
> ic := [0,1-ecc,0,0,((1+ecc)/(1-ecc))^(1/2)];
> # make a copy of variables that will be used to store ynhalf,
> znhalf...
> # make copy of f for the same purpose
> # sv is the vars we are interested in plotting
> uh := [xhalf, yhalf, ahalf, zhalf, bhalf];
> sv := [yhalf, zhalf];
> fh :=
> [1,ahalf,-yhalf/((yhalf^2+zhalf^2)^(3/2)),bhalf,-zhalf/((yhalf^2+zhalf
> ^2)^(3/2))];
> solnK1 := FourthOrderFirstKepler(u, f, uh, fh, sv, ic, 0.1, 10):
u := [x, y, a, z, b]
ecc := 0.6
y z
f := [1, a, 2 (3/2)
, b, 2 ]
2
(y + z ) (y + z 2 )(3/2)
ic := [0, 0.4, 0, 0, 2.000000000]
uh := [xhalf , yhalf , ahalf , zhalf , bhalf ]
sv := [yhalf , zhalf ]
yhalf zhalf
fh := [1, ahalf , 2 2 (3/2) , bhalf , ]
(yhalf + zhalf ) (yhalf + zhalf 2 )(3/2)
2
Plot Keplers Equation result from modied Trapezium and from fourth order A.
> plot_real := []:
> plot_Kestimate := []:
> plot_Ktrapestimate := []:
> for i from 1 by 1 to 101 do
> # plot_real := [op(plot_real),[soln[i,1], cos(soln [i,1])]]:
> plot_Kestimate := [op(plot_Kestimate),[solnK1[i,4],
solnK1[i,2]]]:
> plot_Ktrapestimate := [op(plot_Ktrapestimate),[solnMTK1[i,4],
> solnMTK1[i,2]]]:
> end do:
> # plot second problem as described in notes
> # plotsetup("ps", plotoutput="h:/fourth-kepler.eps",
> plotoptions="color");
> plotsetup(default);
> plot([plot_Kestimate, plot_Ktrapestimate], labels=["z","y"],
> legend=["Fourth Order A Kepler Problem", "Modified Trapezium
Kepler
> Problem"], style=[line, line]);
211
APPENDIX B. MAPLE WORKSHEETS
z
0.8 0.6 0.4 0.2 0.2 0.4 0.6 0.8
0
0.5
1 y
1.5
212
APPENDIX B. MAPLE WORKSHEETS
B.9 sti.mws
B.9.1 Initialization
The following commands initialize Maple. The warnings that appear have no
adverse eects on the execution, so can be safely ignored.
> restart;
> with(DEtools):
> with(plots):
> with(linalg):
Warning, the protected names norm and trace have been redefined and
unprotected
B.9.2 Background
Introduction
The equation we wish to solve a second order ODE
d2 d
( 2
y(x)) + ( + 1) ( y(x)) + y = 0
dx dx
By introducing auxillary variables we can convert it into a set of rst order ODEs,
where is a constant. We shall investigate how varying aects the numerical
solution.
d
y(x) = z(x)
dx
d
z(x) = y(x) ( + 1) z(x)
dx
213
APPENDIX B. MAPLE WORKSHEETS
The above is an example of a sti equation. Essentially this is where solutions can
change rapidly with the respect to the independent variable (here x), yet the other
solution changes a lot more slowly. Thus a very small. If we solve the above
analytically, we nd that:
y(x) = e(x)
We also have an unwanted solution where
y(x) = e( x)
Issues
We aim to demonstrate that under certain circumstances forward Euler fails to
converge to the real solution, and instead blows up to innity. In fact forward Euler is
only stable for the step sizes that satisfy
2
h<
B.9.3 Implementation
Solving the a sti equation with Forward and Backward Euler
We can use our implementations of forward and backward Euler to model the sti
equation. We can investigate how varying the value of changes the nature of the
numerical solution.
u := [x, y, z]
f := [1, z, 1000 y 1001 z]
ic := [0, 1, 1]
> la103 := 10^3;
la103 := 1000
If we limit the range for x = [0, 1.5], there doesnt seem to be a problem, until x = 1.5
where we have a sudden jump in value.
214
APPENDIX B. MAPLE WORKSHEETS
1
0.8
0.6
0.4
0.2
Real sol
Unwanted sol
Backward Euler
215
APPENDIX B. MAPLE WORKSHEETS
However, when increasing the range to x = 1.6, we nd that forward Euler breaks
down far more signicantly. Increasing x further, and forward Euler becomes very
unstable, blowing up to innity.
> soln1h01x16 := GeneralBackwardEuler(u,f,ic,0.1,1.6):
> soln2h01x16 := GeneralForwardEuler(u,f,ic,0.1,1.6):
> plot_yz := []:
> plot_yzLa := []:
> plot_yz1 := []:
> plot_yz2 := []:
> for i from 1 by 1 to 17 do
> plot_yz := [op(plot_yz),[soln1h01x16[i,1], exp(-soln1h01x16
> [i,1])]]:
> plot_yzLa := [op(plot_yzLa),[soln1h01x16[i,1],
exp(-la*(soln1h01x16
> [i,1]))]]:
> plot_yz1 := [op(plot_yz1),[soln1h01x16[i,1], soln1h01x16[i,2]]]:
> plot_yz2 := [op(plot_yz2),[soln2h01x16[i,1],soln2h01x16[i,2]]]:
> end do:
> plotsetup("ps", plotoutput="h:\stiff-ploth0116.eps",
> plotoptions="color");
> plot([plot_yz, plot_yzLa, plot_yz1, plot_yz2], legend=["Real
sol",
> "Unwanted sol", "Backward Euler","Forward Euler"], colour=[green,
> brown, red, black], style=[line,line,line, point]);
> plotsetup(default);
> plot([plot_yz, plot_yzLa, plot_yz1, plot_yz2], legend=["Real
sol",
> "Unwanted sol", "Backward Euler","Forward Euler"], colour=[green,
> brown, red, black], style=[line,line,line, point]);
216
APPENDIX B. MAPLE WORKSHEETS
40
60
80
Real sol
Backward Euler
Forward Euler
Here we nd that forward Euler breaks down far quicker, inspite of having a step size.
217
APPENDIX B. MAPLE WORKSHEETS
2
0.05 0.1 0.15 0.2
0
2
4
6
8
Real sol
Backward Euler
Forward Euler
218
APPENDIX B. MAPLE WORKSHEETS
Here we nd that forward Euler is stable. This is not surprising as h < 2 where
2
= .2e-2
> soln1h0001x15 := GeneralBackwardEuler(u,f,ic,0.001,10):
> soln2h0001x15 := GeneralForwardEuler(u,f,ic,0.001,10):
> plot_yz := []:
> plot_yzLa := []:
> plot_yz1 := []:
> plot_yz2 := []:
> for i from 1 by 100 to 10001 do
> plot_yz := [op(plot_yz),[soln1h0001x15[i,1], exp(-soln1h0001x15
> [i,1])]]:
> plot_yzLa := [op(plot_yzLa),[soln1h0001x15[i,1],
> exp(-la*(soln1h0001x15 [i,1]))]]:
> plot_yz1 := [op(plot_yz1),[soln1h0001x15[i,1],
> soln1h0001x15[i,2]]]:
> plot_yz2 := [op(plot_yz2),[soln2h0001x15[i,1],soln2h0001x15[i,2]]]:
> end do:
> #print(plot_yz);
> plotsetup("ps", plotoutput="h:\stiff-ploth0001.eps",
> plotoptions="color");
> plot([plot_yz, plot_yzLa, plot_yz1, plot_yz2], legend=["Real
sol",
> "Unwanted sol", "Backward Euler","Forward Euler"], colour=[green,
> brown, red, black], style=[line,line,line, point]);
> plotsetup(default);
> plot([plot_yz, plot_yzLa, plot_yz1, plot_yz2], legend=["Real
sol",
> "Unwanted sol", "Backward Euler","Forward Euler"], colour=[green,
> brown, red, black], style=[line,line,line, point]);
219
APPENDIX B. MAPLE WORKSHEETS
0.8
0.6
0.4
0.2
0 2 4 6 8 10
Real sol
Backward Euler
Forward Euler
u := [x, y, z]
f := [1, z, la106 y (la106 + 1) z]
ic := [0, 1, 1]
> la106 := 10^6;
la106 := 1000000
If we limit the range for x = [0, .8], there are no sudden jumps.
220
APPENDIX B. MAPLE WORKSHEETS
1
0.9
0.8
0.7
0.6
0.5
Real sol
Backward Euler
Forward Euler
However, when increasing the range to x = .9, we encounter the same problem seen
earlier with forward Euler.
221
APPENDIX B. MAPLE WORKSHEETS
1000
800
600
400
200
Real sol
Backward Euler
Forward Euler
222
APPENDIX B. MAPLE WORKSHEETS
0.98
0.96
0.94
Real sol
Backward Euler
Forward Euler
We could try a step size that satises the rule for stability say h = .1e-5
223
APPENDIX B. MAPLE WORKSHEETS
d2 d
( 2
y(x)) + ( + 1) ( y(x)) + y(x) = 0
dx dx
d
with the initial conditions given by y(0) = 1 and dx y(0) = 1. We specify the
problem as follows:
> ode := diff(diff(y(x), x), x) +(lambda + 1)*diff(y(x), x) +
> lambda*y(x) = 0;
d 2 d
ode := ( dx 2 y(x)) + ( + 1) ( dx y(x)) + y(x) = 0
We can use Maple to obtain an analytical solution for our ODE. This is achieved by
using dsolve with dierent parameters:
> ic1 := y(0) = 1;
> ic2 := D(y)(0) = -1;
> sol_true := dsolve({ode, ic1, ic2});
224
APPENDIX B. MAPLE WORKSHEETS
ic1 := y(0) = 1
ic2 := D(y)(0) = 1
sol true := y(x) = e(x)
225
APPENDIX B. MAPLE WORKSHEETS
226
APPENDIX B. MAPLE WORKSHEETS
B.10 6thorder.mws
B.10.1 Initialization
The following commands initialize Maple. The warnings that appear have no
adverse eects on the execution, so can be ignored.
> restart;
> with(DEtools):
> with(plots):
> with(linalg):
Warning, the protected names norm and trace have been redefined and
unprotected
B.10.2 Implementation
#Declaration of variables
eq1 := ((1/2+al)^2)/2 = C + D + E + F;
227
APPENDIX B. MAPLE WORKSHEETS
#some initialization
ic := init;
eq_plus_half := [];
eq_minus_half := [];
solveEqns := [];
variables := [];
ans := [];
n_plus_half := [seq(plhlf[i],i=1..nvars)];
n_minus_half := [seq(minhlf[g],g=1..nvars)];
228
APPENDIX B. MAPLE WORKSHEETS
oldICSet := {};
+ E*subs(convert(eq_minus_half,set),op(3,op(j,f)))
+ F*eval(op(3,op(j,f)),oldICSet)),
229
APPENDIX B. MAPLE WORKSHEETS
end do;
end proc:
> u := [[x,y,y_]];
> f := [[1,y_,-1*y]];
> ic := [[0,1,0]];
> soln := sixthOrder(u,f,ic,0.1,10);
230
APPENDIX B. MAPLE WORKSHEETS
u := [[x, y, y ]]
f := [[1, y , y]]
ic := [[0, 1, 0]]
0 1 0
0.1 0.9950041656 -0.09983341664
0.2 0.9800665784 -0.1986693308
0.3 0.9553364899 -0.2955202067
0.4 0.9210609950 -0.3894183424
0.5 0.8775825632 -0.4794255388
0.6 0.8253356164 -0.5646424737
0.7 0.7648421888 -0.6442176877
0.8 0.6967067110 -0.7173560915
0.9 0.6216099700 -0.7833269104
1.0 0.5403023076 -0.8414709857
1.1 0.4535961231 -0.8912073611
1.2 0.3623577561 -0.9320390872
1.3 0.2674988303 -0.9635581868
1.4 0.1699671445 -0.9854497316
1.5 0.07073720312 -0.9974949884
1.6 -0.02919952105 -0.9995736050
1.7 -0.1288444933 -0.9916648125
1.8 -0.2272020940 -0.9738476330
1.9 -0.3232895665 -0.9463000898
2.0 -0.4161468366 -0.9092974290
2.1 -0.5048461050 -0.8632093688
2.2 -0.5885011181 -0.8084964058
2.3 -0.6662760226 -0.7457052140
2.4 -0.7373937172 -0.6754631822
2.5 -0.8011436175 -0.5984721457
2.6 -0.8568887558 -0.5155013732
2.7 -0.9040721447 -0.4273798814
2.8 -0.9422223436 -0.3349881510
2.9 -0.9709581685 -0.2392493298
3.0 -0.9899925003 -0.1411200083
3.1 -0.9991351535 -0.04158066230
3.2 -0.9982947792 0.05837414390
3.3 -0.9874797734 0.1577456950
3.4 -0.9667981962 0.2555411032
3.5 -0.9364566909 0.3507832292
3.6 -0.8967584200 0.4425204452
231
APPENDIX B. MAPLE WORKSHEETS
232
APPENDIX B. MAPLE WORKSHEETS
233
APPENDIX B. MAPLE WORKSHEETS
y 0.5
1 0.5 0.5 1
y
0.5
1.2e08
1e08
8e09
error 6e09
4e09
2e09
0 2 4 6 8 10
x
234
APPENDIX B. MAPLE WORKSHEETS
> #Now solve Keplers equations for movement of sun around Earth
> #Note we use a stepsize of 0.1 here but we have also calculated
with a
> #stepsize of 0.01 but do not include it here due to space
constraints.
> u := [[x,y,y_],[x,z,z_]];
> f := [[1,y_,-1*4*Pi^2*y/(y^2 + z^2)^(3/2)],[1,z_,-1*4*Pi^2*z/(z^2
+
> y^2)^(3/2)]];
> ic := [[0,0,2*Pi],[0,1,-1*Pi]];
> soln2 := sixthOrder(u,f,ic,0.1,10);
u := [[x, y, y ], [x, z, z ]]
4 2 y 4 2 z
f := [[1, y , ], [1, z , ]]
(y 2 + z 2 )(3/2) (y 2 + z 2 )(3/2)
ic := [[0, 0, 2 ], [0, 1, ]]
235
APPENDIX B. MAPLE WORKSHEETS
236
APPENDIX B. MAPLE WORKSHEETS
[[0, 1, -Pi],
[.1, .4512244308, -Pi-.4959786788*Pi^2],
[.2, -.4437144412, -Pi-.5005407941*Pi^2],
[.3, -.9973464448, -Pi-.422715980e-2*Pi^2],
[.4, -1.153922018, -Pi+.2917477049*Pi^2],
[.5, -1.094154972, -Pi+.4506172138*Pi^2],
[.6, -.9146167716, -Pi+.5417965370*Pi^2],
[.7, -.6652030097, -Pi+.5954112560*Pi^2],
[.8, -.3755066960, -Pi+.6248898790*Pi^2],
237
APPENDIX B. MAPLE WORKSHEETS
238
APPENDIX B. MAPLE WORKSHEETS
239
APPENDIX B. MAPLE WORKSHEETS
0.5
Z
1 0.5 0.5 1
0
0.5
Y 1
1.5
240
APPENDIX B. MAPLE WORKSHEETS
u := [[x, y, y ], [x, z, z ]]
y z
f := [[1, y , 2 (3/2)
], [1, z , 2 ]]
(y + z )2 (y + z 2 )(3/2)
ic := [[0, 0.4, 0], [0, 0, 2.000000000]]
241
APPENDIX B. MAPLE WORKSHEETS
242
APPENDIX B. MAPLE WORKSHEETS
[[0, 0, 2.000000000],
[.1, .1950361828, 1.855667313],
[.2, .3649597191, 1.527446218],
[.3, .4998455628, 1.175137257],
[.4, .6016951835, .8720416440],
[.5, .6762738355, .6289954578],
[.6, .7291929672, .4368728508],
[.7, .7649566910, .2840775736],
[.8, .7869964056, .1610032350],
243
APPENDIX B. MAPLE WORKSHEETS
244
APPENDIX B. MAPLE WORKSHEETS
245
APPENDIX B. MAPLE WORKSHEETS
Z
0.8 0.6 0.4 0.2 0.2 0.4 0.6 0.8
0
0.5
Y
1
1.5
246
Bibliography
247
Index
248
INDEX INDEX
Simpsons Rule, 28
sti equation, 39
symmetric, 28
symmetricity, 43
symmetry, 18
system of dierential equations, 7
249