You are on page 1of 6

Engineering Mathematics 120

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);

Often, there are multiple solutions to equations:


> solve(eqn,x);

and, in many cases, it is impossible to solve an equation


> solve(eqn,z);

(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

Saving your work


Very often, you will want to save your work so that you can continue later. Maple allows
you to save the worksheet as a Standard Worksheet with extension .mw, or as a Classic
Worksheet, with extension .mws. You should save your work in your own I drive
directory, because, on a shared machine, even if you are allowed to save the work on the
hard disk, it will be deleted or overwritten when space runs out. There is also no privacy
on the hard drive. For assigned tasks which must be handed in at the end of a lab session
beginning in the 3rd or 4th week of semester, you must mail your worksheet to your tutor
at the end of the session via the mail tool in Blackboard.
Help
For a detailed description of any new command you come across, type ?(command
name); at the prompt to pull up the appropriate help menu. There are also a number of
guided tours available via the main help menu at the top of the screen. If you get stuck,
dont hesitate to get your tutors attention.
Exercises
Here are some exercises that you should do on your terminal. You may work in pairs and
learn from one another for these exercises, if you wish. Read the instructions carefully
and try to answer the questions raised. Remember to end each Maple statement with a
semicolon.
1. Use Maple to find the fifth root of 567 correct to 12 decimal places.
2. Plot x^2*exp(-x) over the interval (0, 10).
3. Here is a simple way to define a function. f := x ->sqrt(x) defines f(x) to be the
square root function, so that after this statement is executed, you can type f(2) to
get the value of 2 or f(15) to get the value of 15 . Define the function f in your
worksheet and then type in the commands f(2) and f(15). You will need to use the
evalf command to get decimal answers.
4. Solve the following equations for the variables involved: f_a-f_e=0,
f_a+2f_c+f_e=0, f_b-f_d=0, f_c-98=0, 2f_d+f_e=0. This gives you the stress
forces in the simple truss discussed in the first lecture.
Administrative Note
There is no assigned task to be handed in during this lab session. However, in future lab
sessions, there will be tasks that you have to complete before the end of the session. These
will be submitted through the mail tool on Blackboard, but you should always keep a copy
on your I drive directory as well. Its a good idea to save todays worksheet in your I drive
directory as well so that you can refer to it in future laboratory classes.

You might also like