> # this is a comment line.if you read this, then you have successfully started your session, congratulations!!!

> # I recommend you use ctrl-3 to adjust the font size. Better? yeah!

> 1+1;

2

> # hey, we can compute 1+1, great.

> %+1;

3

> # the % stands for the latest result, so you don't have to type it again, that's nice

> %+1;

5

> # note that = is test for equality, not assignment

> x = 3;

x = 3

> # the := is used to assign something to something
# in this case, we assign the value 3 to x.

> x := 3;

x := 3

> # now x has the value 3;

> x;

3

> # test for equality:

> x = 3;

3 = 3

> # how can we get rid of the assignment?
# well we need to unassign it, here is how this is done:

> x := 'x';

x := x

> x;

x

> # that's right, now x is a symbol without a value.

> x := 4;

x := 4

> # there's another way to get rid of all assigned variables,

> # it is a complete memory clear:

> restart;

> x;

x

> # OK, now everything is fresh again.
# let's move on.

> #guess what, we are going to do some fractions, yeah!

> 1/3;

1/3

> 0.333333;

.333333

> # 1/3 and 0.333333 is not the same thing, so get used to it!

> # however, if you want to treat 1/3 as floating point number,
# you can give evalf on it.

> evalf(1/3);

.3333333333

> # you can have more digits if you like:

> evalf(1/3,100);

.3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333.3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333

> # Maple treats mathematical quantities exact, i.e. the way mathematicians
# would treat them. For applications, you may want to switch to

# floating points. As we have seen, you can do that.

> # another example is that of factorials.
# n! (read n factorial) is defined as the product of all

# numbers from 1 to n. For example 5! = 5 * 4 * 3 * 2 * 1 = 120:

> 5!;

120

> # Let's do 6!= 6*5*4*3*2*1 = 6 * 5! = 6 * 120 = 720

> 6!;

720

> # now let's do double factorials

> 6!!;

26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...26012189435657951002049032270810436111915218750169457857275418378508356311569473822406785779581304570826199205758922472595366415651620520158737919845877408325291052446903888118841237643411919510455053...

> # wow, what was that?
# That was 6!! = 720! = 720 * 719 * 718 * ... * 2 * 1,

# which of course is a very large number. Notice that Maple gives you

# the exact answer, even though you might not have expected such a large output.

# This is typical for Maple.

# Now if you like, you can turn that number into a floating point.

# Here, the % notation comes in handy.

> evalf(%);

0.2601218944e1747

> # Let's give it a name using the assignment operator.
# Notice that it is now already the next to last result, so we

# use the double percent notation:

> a := %%:  # no output this time

> evalf(a);

0.2601218944e1747

> evalf(a,100);

0.2601218943565795100204903227081043611191521875016945785727541837850835631156947382240678577958130457e17470.2601218943565795100204903227081043611191521875016945785727541837850835631156947382240678577958130457e1747

> # this was a floating point number with 100 decimal digits precision.

> # Do you know what Pi is?

> Pi;

Pi

> # hmmm, maybe you were expecting 3.14...
# here we go:

> evalf(Pi);

3.141592654

> #want more digits? Here we go:

> evalf(Pi,100);

3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170683.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068

> # OK, I hope you see the difference between a symbolic system and a numeric system.
# Maple is symbolic, Matlab is numeric, for example.

> # let's move on.

> restart;

>

>

>

> #uhh adding fractions, let Maple do it:

> 1/3+1/5;

8/15

> # that was correct! 1/3 + 1/5 = 5/15 + 3/15 = 8/15.

> 1/%;

15/8

> # now we want powers, this is how we do it:

> 2^2;

4

> #more powers:

> 2^3;

8

> 2^4;

16

> # want more? why not have a little loop? guess what, Maple starts counting from 1 (I repeat: one)

> for i to 10 do 2^i; end;

2

4

8

16

32

64

128

256

512

1024

> # you can do whatever you want inside the loop.

> # lets say you want to compute 2^i - 1

> for i to 10 do 2^i - 1; end;

1

3

7

15

31

63

127

255

511

1023

> # now we want to start the loop from i=2.
# this is how we do it.

> for i from 2 to 10 do 2^i; end;

4

8

16

32

64

128

256

512

1024

> # notice that the output starts with 2^2 = 4 rather that 2^1 = 2.

> # I want a sequence. Notice the assign operator :=

> seq1 := 1,2,3;

seq1 := 1, 2, 3

> #another one:

> seq2 := 4,5,6;

seq2 := 4, 5, 6

> #let's concatenate the sequences:

> seq3 := seq1,seq2;

seq3 := 1, 2, 3, 4, 5, 6

> #let's access elements of the sequence, for example the third:

> seq3[3];

3

> # uhh, don't access the zeroth element, this is Maple and not C, OK!?

> seq3[0];

Error, invalid subscript selector

> #let's make the sequence longer:

> seq3 := seq3,7,8,9;

seq3 := 1, 2, 3, 4, 5, 6, 7, 8, 9

> #how long is it?

> length(seq3);

19

> # well, that can't be right. In fact you must use nops and square brackets, don't ask why at this point

> nops([seq3]);

9

> # OK let's add more stuff:

> seq3 := seq3,a,b,c;

seq3 := 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c

> nops([seq3]);

12

> # you have noticed that we always have a semicolon at the end of a command.

> # we can also have a colon. That would then suppress output, as follows:

> seq3:=seq3,d,e,f:

> # want to see seq3 ?, here you go:

> seq3;

1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, d, e, f

> # lets make a sequence of the first few powers of 2:

> S := seq( 2^i, i=1..10);

S := 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024

> # we could also do it this way:

> S := seq( 2^i, i={1,2,3,4,5,6,7,8,9,10});

S := 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024

> # let's learn how to use lists!

> # a list is just a sequence put into square brackets

> L := [1,2,3,4,5];

L := [1, 2, 3, 4, 5]

> # access goes from 1 to 5:

> L[1];

1

> L[2];

2

> L[3];

3

> L[4];

4

> L[5];

5

> # we can change an entry in the list using the assignment operator :=

> L[1] := 2;

L[1] := 2

> L;

[2, 2, 3, 4, 5]

> # how can we append?
# Our first guess is this

> L := [L,6];

L := [[2, 2, 3, 4, 5], 6]

> # hmm, that was't what we wanted.

> # here is the solution. Let's first restore L:

> L := [1,2,3,4,5];

L := [1, 2, 3, 4, 5]

> # its a bit tricky, we need to get the contents
# of the list first, and then add one more entry and

# make it a list, such as

> op(L); #the content of the list, as a sequence:

1, 2, 3, 4, 5

> [op(L),6]; #now we add an element and make another list:

[1, 2, 3, 4, 5, 6]

> # we can have a loop create a list as long as we wish:

> L := [];  # start with an empty list

L := []

> for i from 1 to 10 do
 L := [ op(L), i ]:

end;

L := [1]

L := [1, 2]

L := [1, 2, 3]

L := [1, 2, 3, 4]

L := [1, 2, 3, 4, 5]

L := [1, 2, 3, 4, 5, 6]

L := [1, 2, 3, 4, 5, 6, 7]

L := [1, 2, 3, 4, 5, 6, 7, 8]

L := [1, 2, 3, 4, 5, 6, 7, 8, 9]

L := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

> # uhh, what was that.
# That was one line of output for each execution of the

# loop body.

> # Maybe that is too much output for you.
# turning the ";" to a ":" after the end prohibits output:

> L := []: for i from 1 to 10 do
 L := [ op(L), i ]:

end:

> L;

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

> # there is a quick way to generate repeated elements in lists
# for example 0$10 would generate 10 entries 0

> L := [3$7]; # seven 3's

L := [3, 3, 3, 3, 3, 3, 3]

>

>

>