Professional Documents
Culture Documents
Laboratory Session 1
Learning outcomes for this session
At the end of this session, you will be able to
1. Use Maple for elementary arithmetic.
2. Use Maple to solve algebraic equations.
3. Plot functions in Maple.
4. Meet some limitations of Maple and see how to work around them.
5. Save a worksheet for later use.
Overview
1. Maple is a comprehensive mathematical package which far surpasses graphics
calculators in terms of its capibilities.
2. It can be used to solve many problems, including the provision of the algebraic
results for operations involving the derivatives, integrals and series
approximations of engineering functions.
3. Maple comes with a programming language which can be invoked to solve more
complex problems.
Important Note: To be consistent across the various laboratories, you should be
using the Classic Worksheet version of Maple 15. Even though the standard
version of Maple 15 is available, the discussion below may be misleading or
confusing if it is used instead of the classic worksheet version.
The worksheet
When you open the software, a command window like this will appear:
The prompt is [ > and you can enter any valid mathematical statement next to it. For
example, type in x + y + 2*x and end the line with a semicolon ; to get
[ > x + y + 2*x;
on the screen. As soon as you press the Enter key, Maple will response with 3x + y.
What you will see on the screen is
> x + y + 2*x;
3x+y
This is the execution group delimiter.
Pressing the Enter key means you want Maple to execute the statement and a semicolon
is a signal to Maple that you have completed the statement. The delimiter delimits the
statement and the response from Maple as an execution group. A new delimiter and
prompt will appear as soon as one statement has been executed. If you forget to type the
semicolon, Maple will warn you that something is wrong with your statement, and you
can then go back (scroll back) to the statement and add the semicolon. If you type a colon
: instead of a semicolon, this tell Maple that you do not want to see its response. The
statement will still be executed if the Enter key is pressed although no output will be
shown on the screen. Also note that the multiplication symbol * is required when you
enter the expression, otherwise Maple will complain of an error.
Notice how Maple responds with the expression you have just entered. More than that,
though, it has its own set of rules for simplification when it responds. The 3x+y above is
quite an obvious simplification, but Maple can appear a little fickle at times. For instance,
typing
> 3/sqrt(5);
gives an unnecessarily complicated looking response. This is because Maple does not
like square roots and other surds appearing in the denominator of a fraction. Still, you
should recognize that its response is equivalent to what you had typed in.
Being primarily a symbolic manipulation tool, Maple will endeavour to preserve exact
expression as far as possible. Whereas most calculators will respond with a decimal
number when asked to calculate the square root of 2, Maple does the following
> sqrt(2);
To get a decimal response from Maple, you have to tell it that you want a floating point
number as an answer. This is done as follows:
> evalf(sqrt(2));
Note that any number of decimal places can be displayed. To calculate the cube root of 3
to 15 significant figure, simply type
> evalf[15](3^(1/3));
2
Sometimes, you may want to have a set of statements to be executed one after another as
a group. To add more statements to an execution group, you can press Shift Enter, which
will give you a new line without executing the statement typed. You can also continue
typing statements, separated by semicolons on the same line. When you have finished all
the statements you want in the group, just press Enter. As an exercise, reproduce the
following output on your screen now. Note that the := means were assigning something
to a variable name.
> x:=3; y:=4;
var:=5*x; varb:=x+y;
x := 3
y := 4
var := 15
varb := 7
Note that setting variables like this is essentially a global assignment within the Maple
worksheet. This can interfere with subsequent computations if any of the variable names
are used again. To avoid his problem, use
> restart;
to clear all variable assignments up to that point.
A useful trick within Maple is to use % (or %% or %%% etc.) to assign a previous
Maple output to a new task. Consider the following example:
> eqn:=x^2+4*x-5=0;
> solve(%);
> subs(x=1,%%);
The % referred to the equation just returned by Maple, while the %% also refers to the
equation which, by now, is the second last Maple output. This feature saves you retyping complicated expressions.
One of the most useful things Maple can do is to solve equations.
extracting variables from equations such as in the following example
> eqn:=sqrt(x^2*y+3*z)-4*z^2+z^3=0;
This includes
> solve(eqn,y);
(The answer here is essentially just saying that we are trying to solve the original
equation once more, so it is of little use to us.)
Finding arithmetic solutions of equations also uses the solve command. To find the
square roots of 2, for instance, type
> solve(x^2=2);
or, if you want a decimal answer,
> fsolve(x^2=2);
Maple can find all solutions of polynomial equations up to order 4, but it has trouble
generating all solutions for most other equations. See below for more details. The solve
and fsolve commands are also capable of solving simultaneous equations as in
> eqns:={u+v=3,2*u+5*v=0};
> solve(eqns,{u,v});
(Note the careful use of brackets here. The braces {} are used to describe sets, a set of
two variables to be solved for in this case. Be careful not to use [ ] or { } for entering
arithmetic or algebraic expressions, because Maple will interpret these as lists or sets,
respectively and respond in ways you may not expect.)
Nonlinear simultaneous
equations can also be solved, see the exercises at the end of the sheet.
One of the drawbacks of Maple (as with any computational package) is that it can not
always find a complete set of solutions. For example, there are two solutions to the
equation in the following solve command, but Maple will only pick up one:
> eqn:=x^2-2*sin(x)=0;
> fsolve(eqn);
To see that a second solution exists, we can plot a graph of the function involved and see
where it is equal to zero:
> plot(x^2-2*sin(x),x=-5..5);
(look up the details of the plot command by typing >?plot; and see how you can
adjust the domain and range of the function). Clearly, a second solution of the equation
exists between x=1 and x=2. To find it, we simply provide a range for the possible
solution values in the fsolve command.
> fsolve(eqn,x=1..2);
Finally, note that within a Maple worksheet, each variable name must be a continuous
string of alphanumeric characters, but it must start with an alpha character, and there is no
restriction on the length. The following are all valid variable names: a, avariable,
var1, expre_1, A, Agas and so on. Maple is case sensitive, so that Avar and
avar are two different variable names. If a numerical value is not assigned to a variable,
then the variable is represented as an algebraic quantity. Type the following statement at
the next prompt:
> A*exp(varC); 2*varC;
Here, varC is a variable name. exp is the representation for the exponential function,
so if we want e2x, we should type in exp(2*x). As weve noted before, if you typed 2x
instead of 2*x, you will get an error message from Maple. When Maple shows you its
response on the screen it will not show the * symbol.
5