Using Maple for Bio481

This page is going to contain a general primer on using Maple for our problems. Hopefully I can even get some screen captures up showing actual screens.

 

Setting up variables and functions

To establish variables and functions, you need to use the assignment operator. The assignment operator is ':='. Remember that all statments in Maple must end with a ';'. So to tell Maple that the symbol R is equal to the value 2.5, you would type: 'R := 2.5;'. It is important to note that R is not a true variable now. It has one particular value (2.5). If you want to use a variable that takes on multiple values, do NOT assign this variable. If you have assigned a symbol a meaning and no longer wish for it to be assigned, you can enter 'unassign('R'); to unassign the symbol R.


It works similar with functions. You assign a set of operations to a name. For example if you have the equation N(t) = r^t*N0, you could assign a function, 'f' to calculate this: 'f := r^t*N0;'. This assignment is not the same as the '=' you use when you are solving an equation.

Maps are a special type of function (this is different from the discrete time term map). These functions let you enter in any argument for the function and calculates the result according. Suppose you wanted to calculate x^2 for different values of x. You could have type in f:=x^2, but then you would have to re-enter each value for x and then recalculate f each time. The best approach to this would be to form a general equation or map for this. You can type f:=(x)->x^2;. Now you can use f(x) as you please. For example f(2);and f(5); would calculate the function for the respective values.



Plotting functions

If you have entered in a function, the next thing you want to do is most likely to plot it. To plot a simple function like 'f' in the previous example you would type: 'plot(f, t=1..5);'. You must have R and N0 defined or else this will generate an empty plot (Maple doesn't know what values to give the function) This example will plot 'f' for all values of t from 1 to 5. You can set alternative ranges for t. You can also set the range of the y-axis to display by using a more complicated version of the plot command: 'plot(f, t=1..5, y=1..100, title=`t versus N(t)`);'. I would strongly suggest that you set the option to display plots in a separate window rather than inline.


You can display 3D plots in Maple, although they may be more difficult to interpret. For example, let's suppose that we have the old 'f' function. If we want to know how it performs for values of t as well as r, we might use a 3D plot. Note: t and r must be unassigned, while N0 must be assigned. To display this graph, type: 'plot3d(f, t=1..5, r=2..3)'. With the plots in separate windows, you can do some wild things with the formatting and changing perspectives of the plots.



Multiple functions on a plot

Maple allows you to plot multiple functions on a given plot. To do this you must use Maple's array notation. In this, each function is listed separately in an array: [f, g, h] if f, g, and h were our three functions. Similarly anytime we want to set options for each of the functions we will set the option as an array. So the full syntax to plot our three functions and give them colors and specific style might look like: plot([f, g, h], x=0..2, color=[red, green, blue], style=[line, line, point], title='Three functions');.



Matrices and Vectors

Maple has extensive support for matrices and vectors and will let you do quite a bit with these representations. To use any of the matrix and vector support, you must load the linear algebra package into Maple. You do this by entering: with(linalg);. Once the linear algebra package is loaded, you are ready to go.

Matrices and vectors are all represented as arrays in Maple. The grouping is by row and then by column. So if you were to type in vect:=array([[5, 2, 3]]);, Maple would construct a row vector with these three elements. Typically we want to have column vectors in population biology. To create a column vector, you would have had to type in: vect:=array([[5], [2], [3]]);. Note that each row is enclosed in its own brackets (as is the entire vector). The syntax for matrices is very similar. Here the only real difference is that we will specify the dimensions of the matrix. For example: A:=array(1..3,1..3,[[0,2,3], [0.5,0,0], [0,.2,09]]); gives us a 3x3 matrix.

Matrix multiplication is a little bit different that standard multiplication. Maple uses the symbol &* to represent matrix multiplication. So we can write a function that calculates the population size at time t (assuming that the vector N0 is defined), by writing Nt:=(mat,vect,t)->evalm((mat^t)&*vect);. Now you can type Nt(A, N0, 10) to calculate the population after 10 years if A is your projection matrix and N0 is your initial population vector.



 


Go Back to My Bio481