Table of Contents

Exercises

Quiz

Back to Maple Tutorial Table of Contents

+, -, *, and /

Like the TI graphing calculators, Maple does it's math in expression form.

> 2+2;

[Maple Math]

> 4-21;

[Maple Math]

In place of the x or dot operator used sometimes on paper to stand for multiplication, Maple uses the asterisk. Maple also uses the / for division.

> 2*4;

[Maple Math]

> 45/5;

[Maple Math]

Using parenthetical notation for multiplication does not work. In this example, Maple thinks that 2 is a function and not a number.

> 2(6);

[Maple Math]

As always, we use the semicolon to terminate our commands.

 

Top

^ - Exponentiation

To compute 2 squared (2*2), we use the syntax shown below:

> 2^2;

[Maple Math]

If you need to use multiple terms in your exponent, you MUST enclose them with parenthesis. The first statement below simplifies to 22. The second equation simplifies to [Maple Math].

> 2^(8/4);

[Maple Math]

> 2^8/4;

[Maple Math]

 

Top

() - Parenthesis

Parenthesis allow you to tell Maple to evaluate parts of an expression before another.

Example:

> 2+4*8;

[Maple Math]

> (2+4)*8;

[Maple Math]

 

Top

! - Factorials

Maple lets you compute factorials (n factorial is 1*2*3*..*n-1*n. 1 factorial is 1, and 0 factorial is also 1). The syntax is:

> 2!;

[Maple Math]

> 4!;

[Maple Math]

 

Top

% - Ditto mark

Scenario: Let's say you need to evaluate [Maple Math] to 15 digits, then divide the result by 5. (You don't want to divide before rounding because of rounding issues.)

You could do this:

> Digits:=15;

[Maple Math]

> evalf(Pi/4);

[Maple Math]

> .785398163397448/5;

[Maple Math]

In this example, I retyped the floating-point number into the next command prompt. If you are a computer whiz, you are probably thinking about copying the result to the clipboard and pasting it into the command prompt. You can do that, but there is a better way:

> Digits:=15;

[Maple Math]

> evalf(Pi/4);

[Maple Math]

> %/5;

[Maple Math]

The percent sign in Maple is called the ditto mark. Like the " you might use on paper, the ditto mark tells Maple to "bring down" the last result. No retyping, no clipboard, and no hassle!

Caveat: % returns the last evaluated answer. This problem is best illustrated with an example.

> 2+2;

[Maple Math]

> 4+2;

[Maple Math]

> %+2;

[Maple Math]

If these lines are executed one after the other, you will receive the output shown above. However, if you execute line 1, skip line 2, and execute line 3, the ditto mark will evaluate to 4, not 6, because 4 was the last processed result.

You can also use %% and %%%. Example:

First, let's generate some output to play with.

> 1;

[Maple Math]

> 2;

[Maple Math]

> 3;

[Maple Math]

> 4;

[Maple Math]

Next, let's see what happens.

> %%;

[Maple Math]

> %%%;

[Maple Math]

The ditto marks can be confusing at first. A good rule of thumb is to count up from your command prompt to the result you want. However many results you count should be the number of percent signs you should use. (The maximum is 3)

Using this rule on the previous example, we see that the first ditto mark returns 3 because it skips 4. The second ditto mark returns 3, also, because it skips 3 and 4.

It's a good idea not to use ditto marks unless the result you want is right above your command prompt, or unless you are not saving your work. Otherwise, you can load a worksheet, accidentally execute statements in the wrong order, and end up with bad results. If you are saving your worksheet, store important data in variables.

 

Top

Line delimiters

So far in Maple, we have put the semicolon after each line. This is to tell Maple the command is finished and ready to be executed.

We do that because Maple can understand commands that are grouped. Later, we will learn how to use commands to change the flow of our worksheet. These commands will take this form:

> 2+2;
  6+2;

[Maple Math]

[Maple Math]

Notice how we have grouped several commands in one command prompt. To insert the "soft break", hold down Shift while you press Enter. These commands execute as a group and the output is clumped together at the end.

Maple has another line-delimiter. It is the colon. Use the colon when you don't want Maple to send you the output of your command. This will be handy when we execute commands that give us output that we don't need to see. Example:

> sin(2):

Notice how Maple did not repeat the output from the computation.

We can take this further by applying it to our previous example.

> 2+2:
  6+2;

[Maple Math]

Note that Maple didn't show us the output of the first expression.

The backslash (\) is another end-of-line symbol. It allows you to continue input to the next line. Example:

> 2+\
  2;

[Maple Math]

Note that if you use this method, the complete expression must be in one command prompt.

 

Top

x..y - Ranges

When you want to tell Maple to use certain numbers, you use a range. The range is mostly used in the plot command. The following command will plot the line f(x) = x from x = -10 to x = 10.

> plot(x,x=-10..10);

[Maple Plot]

Note the x = -10 .. 10. That is the range which tells Maple what values to show on the x-axis.

 

Top

x$y - Sequences

There are times in Maple when we need to input a sequence of the same expression. (x,x,x,x,x,x) Instead of typing x's and commas, we can use the $ operator. It's syntax is x $ y. x is the expression to be repeated and y is the number of times to repeat it. Example:

> x$2;

[Maple Math]

> (x+2)$5;

[Maple Math]

 

Top

# - Comments

Maple allows you to insert comments into your worksheet. Comments allow you to insert "reminders" into your code so that when you look at it later, you will remember what the code does. Comments are preceded by the pound sign (#). The # tells Maple not to evaluate what follows after it. Example:

> #This is very important code that finds 2+2.

> 2+2

[Maple Math]

> #As expected, the result was 4.

> 3+3; #You can also put comments after commands.

[Maple Math]

Use comments often; you'll be glad you did!

 

Top

Maple's Order of Operations

From top to bottom

 

% Ditto mark
! Factorial
^ Exponentiation
*, /, intersect Multiplication, division, and intersections
>+, -, union Addition, subtraction, and unions
mod Modulus of a number
.. Ranges
<, <=, >, >=, =, <> Comparisons
and, or, not Boolean operators
-> User-defined functions
, Sequence
:= Assignment

Top