:

## Computer Algebra using Maple, as taught by The Open University (UK)

Maple

In this post I will describe a little about the OU course MS325: Computer Algebra, Chaos and Simulations, which I took last year.

MS325 is a level 3 OU applied mathematics course, which means, roughly that it is pitched at the level of a final year mathematics undergraduate. It is split into three components: Computer Algebra, which teaches the use of Maple and Maple programming; Chaos, which teaches dynamical systems, deterministic chaos and fractals, with an emphasis on iterative maps; and Simulations, which teaches the use of Maple to simulate random processes and apply them to problemsf such as traffic flow and Monte Carlo integration. The course is assessed by means of four tutor-marked assignments (TMAs), which are mainly focused on Maple (worksheets must be printed and also emailed to tutors), and an end-of-course written exam which does not require or allow the use of Maple, and is purely a test of the non-Maple parts of the course.

Due to copyright, I cannot post extracts from the course books, nor the question booklets for the TMA. However I can post my own code, and I will post some of my solutions to the more interesting and relevant TMA questions. Hopefully with my descriptions, they will be easy to follow.

Block A, “Computer Algebra”, is essentially a guide to Maple commands and programming, with lots of exercises along the way. It was enjoyable and I found it quite easy because I had gained a head start by purchasing a copy of Maple and Doug Meade’s excellent book, and also working through some of the online Maple guides such those on Peter Stone’s website

The block finishes with some interesting case studies: The spectra of numbers, numerical Integration using the Newton-Cotes method, polynomial least squares fitting, elementary combinatorics, series solutions of differential equations; and the van der Pol Oscillator.

On the whole, students who had previous programming experience, found this block to be very easy though some who came from a structured programming background lamented Maple’s lack of structure and strong typing. There were others who had no programming background who struggled a lot. I managed to get 93% on the TMA for this block.

Block B, “Chaos and Modern Dynamics” starts out with a gentle introduction to modern dynamics and chaotic phenomena in the real world: the orbit of Pluto, the tumbling of Hyperion (one of Saturn’s moons), the distribution of asteroid belts, a double pendulum and the Lorenz system, before ploughing into a discussion of flows in phase space (systems of differential equations) linearization of nonlinear systems, and the classification of a fixed point in two dimensional flows by eigenvalues, as: a centre; saddle point; spiral (stable or unstable); star (stable or unstable); node (stable or unstable); or improper node (stable or unstable), followed by a discussion of how these can apply to linearized systems. Maple is used to illustrate various kinds of orbits. Here is a program showing an orbit of the Duffing double-well oscillator

with(DEtools):
dufforbit:=proc(gamma,omega,c,xmin,xmax,ymin,ymax)
local eqn,x,y,t,ttl;
eqn:= diff(x(t),t)=y(t),diff(y(t),t)=x(t)-c*y(t)-(x(t))^3+gamma*cos(omega*t);
ttl := cat("Duffings double-well oscillator, ","gamma=",convert(gamma,string),",
omega=",convert(omega,string),",c=",convert(c,string));
DEplot([eqn],[x(t),y(t)],t=100..400,[[x(0)=1,y(0)=0.5]],x=xmin..xmax,y=ymin..ymax,stepsize=0.01,method=rkf45,thickness=1,linecolor=black,font=[TIMES,ITALIC,24],axesfont=[TIMES,ROMAN,14],titlefont=[TIMES,ROMAN,14],title=ttl);
end proc:

dufforbit(0.70,1.25,0.30,-2,2,-2,2);

Iterative maps are then introduced, and this remains the focus for the rest of the block. Chaos is introduced naturally, but non-rigorously, by showing how some orbits are extremely sensitive to initial conditions. The tent map and logistic map are studied in detail, and the Lyapunov exponent is introduced in one dimension, leading to a more precise definition of chaos: an orbit is chaotic if it is unbounded, and is not asymptotically period, and it’s Lyapunov exponent is positive.

The following attached worksheet is my answer to part of TMA 2, concerning the Ricker model of population growth, an iterative map on R: xn+1 = f(xn),  f(x)= x.exp (r(1 − x)) . Here we use Maple to locate the period-2 orbits and determine their stability for different values of r, plot a bifurcation diagram, and produce a plot of the Lyapunov exponent vs r

TMA_MS325_02_Q2_d_e_.mw

Two-dimensional maps, beginning with the Henon map and the standard map, then follow, extending the concept of Lyapunov exponents and the definition of chaos to two dimensions, where an orbit is chaotic if the first Lyapunov exponent, h1 is positive, an attractor (non chaotic) if h1+h2<0 and a strange attractor (chaotic) if h1+h2<0 but h1>0.  Maple was used extensively to investigate the self-similarity of certain attractors, by magnifying orbit plots, thereby introducing fractal sets. The next attached worksheet is my answer to another part of TMA 2, showing phase portraits for a strange attractor and a non-chaotic attractor of a two-dimensional map.

TMA_MS325_02_Q3_a_.mw

There is an all too brief excursion into dynamics in the context of Hamiltonian mechanics where Maple is used to plot the contours of Hamiltonians. Although Hamiltonian systems don't have attractors, it would have been nice to have had this section extended, perhaps as non-examinable optional material, which done in other parts of this course.

The last part of this block is devoted to fractals. Maple is used for numerical determination of the fractal box-counting dimension. The box-counting dimension D is defined as follows. Consider a set S which is a subset of a d-dimensional space. We pick a value for a positive number, denoted by e, and divide the d-dimensional space into d-dimensional shapes of side length e. In each of these shapes we determine whether there is an element of S contained within the shape, in which case we say that the shape belongs to the e-covering set of S.Let the number of shapes (‘boxes’) of side e forming the e-covering set of S be N(e). Then the box-counting dimension D of the set S is defined as This is demonstrated in the calculation in the following attached worksheet for the Henon map, where the least squares method is used to fit a straight line, to pairs of points (lnN(e), 1/ ln e) , the slope giving us the value required.

Henon_fractal_dimens.mw

The Lyapunov exponent can also be used to estimate the box-counting dimension, using the Lyapunov dimension (1+h1/|h2| for h1>0 and h1+h2<0) and using the code in the worksheet attached in the previous section, we find a reasonable agreement (1.27 vs 1.22)

Just under half of Block C is taken up with presenting probability theory and elementary statistics in a fairly standard manner found in other undergraduate texts. Maple is then used extensively in Monte Carlo integration, along with methods to decrease the statistical errors. The respective TMA question required the calculation of the mass, centre of mass and moment of inertia of an face-shaped object to within given absolute and relative statistical error levels, using numerical integration.  My solutions are in the following worksheet.

TMA_MS325_03_Q4.mw

Population dynamics are simulated as a stochastic process, and Maple was used for this - it did not come up in the TMAs.

A medieval siege weapon  - the trebuchet – was investigated at length, using Maple, as its motion is a good example of non-linear dynamics, however it was not assessed in the TMAs (which was just as well, as it did get quite boring and tedious)

Traffic flow was investigated using a “cellular automata” model, which was quite easy to implement in Maple. Essentially it involves modeling the speed of each vehicle discretely, with rules for braking (keeping a safe distance) and accelerating (when the road ahead is clear), with a random element which determines whether a vehicle slows down or not (eg a driver who drops his/her speed due to a distraction, or over-reaction). This formed a large part of the final TMA.

The final TMA was about consolidating Maple skills, applying them to quite long questions, which drew on other parts of the course.

TMA 04 Question 1 was about perturbation theory applied to approximating the eigenvalues of complicated matrices where exact solutions can not usually be found.

TMA 04 Question 2 was about modeling gravitational motion – two, and then three (the restricted three-body problem) point-like massive bodies were animated.

TMA 04 Question 3 extended the traffic flow modeling from Block C, by adding a pelican crossing.

My solutions to TMA04 are in the following worksheet. I got 96% overall on this TMA.

Overall, the course seemed a bit piecemeal, throwing seemingly disparate areas of mathematics together, linked only by the use of Maple. However, for me, this was one of the most attactive aspects of the course. I thoroughly enjoyed it and would recommend it to anyone.

Edit: Various Typos ﻿