# 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;NiMiIiM=# hey, we can compute 1+1, great. %+1;NiMiIiQ=# the % stands for the latest result, so you don't have to type it again, that's nice%+1;NiMiIiU=# note that = is test for equality, not assignmentx = 3;NiMvSSJ4RzYiIiIk# the := is used to assign something to something # in this case, we assign the value 3 to x.x := 3;NiM+SSJ4RzYiIiIk# now x has the value 3;x;NiMiIiQ=# test for equality:x = 3;NiMvIiIkRiQ=# how can we get rid of the assignment? # well we need to unassign it, here is how this is done:x := 'x';NiM+SSJ4RzYiRiQ=x;NiNJInhHNiI=# that's right, now x is a symbol without a value.x := 4;NiM+SSJ4RzYiIiIl# there's another way to get rid of all assigned variables, # it is a complete memory clear:restart;x;NiNJInhHNiI=# OK, now everything is fresh again. # let's move on.#guess what, we are going to do some fractions, yeah!1/3;NiMjIiIiIiIk0.333333;NiMkIidMTEwhIic=# 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);NiMkIitMTExMTCEjNQ==# you can have more digits if you like:evalf(1/3,100);NiMkIl9xTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTEwhJCsi# 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!;NiMiJD8i# Let's do 6!= 6*5*4*3*2*1 = 6 * 5! = 6 * 120 = 7206!;NiMiJD8o# now let's do double factorials6!!;NiMiXmhxKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKyt3NCZSTG9saUVOT3o5YyR6bi85ISk+PG0hUWJmUEI8RygqWzJRRDlUWUl1SG9oOkorXSplJWV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NGSyFcPyteemxOJSo9N2cj# 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(%);NiMkIitXKj03ZyMiJVA8# 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 timeevalf(a);NiMkIitXKj03ZyMiJVA8evalf(a,100);NiMkIl9xZC84ZXpkeTFDI1FacDpKYyQzJnkkPWFGZHlYcCx2PV8iPjZPLyIzRkshXD8rXnpsTiUqPTdnIyIlWjs=# this was a floating point number with 100 decimal digits precision.# Do you know what Pi is?Pi;NiNJI1BpR0kqcHJvdGVjdGVkR0Yk# hmmm, maybe you were expecting 3.14... # here we go:evalf(Pi);NiMkIithRWZUSiEiKg==#want more digits? Here we go:evalf(Pi,100);NiMkIl9xb3E2VWAjWy5HJykqKjNpRzFrInlJI2ZXXCg0I2U1diQqUnByPiUpR116S1FWRVlRS3oqZWBFZlRKISMqKg==# 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.#uhh adding fractions, let Maple do it:1/3+1/5;NiMjIiIpIiM6# that was correct! 1/3 + 1/5 = 5/15 + 3/15 = 8/15.1/%;NiMjIiM6IiIp# now we want powers, this is how we do it:2^2;NiMiIiU=#more powers:2^3;NiMiIik=2^4;NiMiIzs=# 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;NiMiIiM=NiMiIiU=NiMiIik=NiMiIzs=NiMiI0s=NiMiI2s=NiMiJEciNiMiJGMjNiMiJDcmNiMiJUM1# you can do whatever you want inside the loop.# lets say you want to compute 2^i - 1for i to 10 do 2^i - 1; end;NiMiIiI=NiMiIiQ=NiMiIig=NiMiIzo=NiMiI0o=NiMiI2o=NiMiJEYiNiMiJGIjNiMiJDYmNiMiJUI1# 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;NiMiIiU=NiMiIik=NiMiIzs=NiMiI0s=NiMiI2s=NiMiJEciNiMiJGMjNiMiJDcmNiMiJUM1# 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;NiM+SSVzZXExRzYiNiUiIiIiIiMiIiQ=#another one:seq2 := 4,5,6;NiM+SSVzZXEyRzYiNiUiIiUiIiYiIic=#let's concatenate the sequences:seq3 := seq1,seq2;NiM+SSVzZXEzRzYiNigiIiIiIiMiIiQiIiUiIiYiIic=#let's access elements of the sequence, for example the third:seq3[3];NiMiIiQ=# 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;NiM+SSVzZXEzRzYiNisiIiIiIiMiIiQiIiUiIiYiIiciIigiIikiIio=#how long is it?length(seq3);NiMiIz4=# well, that can't be right. In fact you must use nops and square brackets, don't ask why at this pointnops([seq3]);NiMiIio=# OK let's add more stuff:seq3 := seq3,a,b,c;NiM+SSVzZXEzRzYiNi4iIiIiIiMiIiQiIiUiIiYiIiciIigiIikiIipJImFHRiVJImJHRiVJImNHRiU=nops([seq3]);NiMiIzc=# 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;NjEiIiIiIiMiIiQiIiUiIiYiIiciIigiIikiIipJImFHNiJJImJHRi1JImNHRi1JImRHRi1JImVHRi1JImZHRi0=# lets make a sequence of the first few powers of 2:S := seq( 2^i, i=1..10);NiM+SSJTRzYiNiwiIiMiIiUiIikiIzsiI0siI2siJEciIiRjIyIkNyYiJUM1# we could also do it this way:S := seq( 2^i, i={1,2,3,4,5,6,7,8,9,10});NiM+SSJTRzYiNiwiIiMiIiUiIikiIzsiI0siI2siJEciIiRjIyIkNyYiJUM1# let's do something crazyS := seq(i^2, i={x,y,z});NiM+SSJTRzYiNiUqJEkieEdGJSIiIyokSSJ5R0YlRikqJEkiekdGJUYp# these are just symbolic terms, we cannot do much with them now.# notice that we have overwritten S each time # in the last few examples. That is OK, as long as we don't need the old content any more.%[2];NiMqJEkieUc2IiIiIw==# BTW, that was the second element of S.# now we want to have a set:{1,2,3,4,5};NiM8JyIiIiIiIyIiJCIiJSIiJg==#let's give it a name:S := %;NiM+SSJTRzYiPCciIiIiIiMiIiQiIiUiIiY=# another set:T := {2,4,6,8};NiM+SSJURzYiPCYiIiMiIiUiIiciIik=#union, minus, intersect:S union T;NiM8KSIiIiIiIyIiJCIiJSIiJiIiJyIiKQ==S minus T;NiM8JSIiIiIiJCIiJg==S intersect T;NiM8JCIiIyIiJQ==#is 2 a member of S?member(2, S);NiNJJXRydWVHSSpwcm90ZWN0ZWRHRiQ=# OK, and at which position?member(2, S, 'position');NiNJJXRydWVHSSpwcm90ZWN0ZWRHRiQ=position;NiMiIiM=#OK, second position of S.S[2];NiMiIiM=for i to 10 do 2^i; end;NiMiIiM=NiMiIiU=NiMiIik=NiMiIzs=NiMiI0s=NiMiI2s=NiMiJEciNiMiJGMjNiMiJDcmNiMiJUM1for i from 0 to 10 do 2^i; end;NiMiIiI=NiMiIiM=NiMiIiU=NiMiIik=NiMiIzs=NiMiI0s=NiMiI2s=NiMiJEciNiMiJGMjNiMiJDcmNiMiJUM1for i from 0 to 10 do printf("%d ", 2^i); end;1 2 4 8 16 32 64 128 256 512 1024 A := Matrix(7,7);NiM+SSJBRzYiLUknUlRBQkxFR0YlNiUiKl9DTU4iLUknTUFUUklYR0YlNiM3KTcpIiIhRi9GL0YvRi9GL0YvRi5GLkYuRi5GLkYuSSdNYXRyaXhHNiRJKnByb3RlY3RlZEdGMkkoX3N5c2xpYkdGJQ==A[1,1];NiMiIiE=A[7,7];NiMiIiE=A[8,8];Error, Matrix index out of rangefor i from 1 to 7 do for j from 1 to 7 do A[i,j] := 1/(i+j); end; end;A;NiMtSSdSVEFCTEVHNiI2JSIqLz4kXDgtSSdNQVRSSVhHRiU2IzcpNykjIiIiIiIjI0YuIiIkI0YuIiIlI0YuIiImI0YuIiInI0YuIiIoI0YuIiIpNylGMEYyRjRGNkY4RjojRi4iIio3KUYyRjRGNkY4RjpGPSNGLiIjNTcpRjRGNkY4RjpGPUZAI0YuIiM2NylGNkY4RjpGPUZARkMjRi4iIzc3KUY4RjpGPUZARkNGRiNGLiIjODcpRjpGPUZARkNGRkZJI0YuIiM5SSdNYXRyaXhHNiRJKnByb3RlY3RlZEdGUEkoX3N5c2xpYkdGJQ==A[7,7];NiMjIiIiIiM5# let's learn how to use lists!# a list is just a sequence put into square brackets L := [1,2,3,4,5];NiM+SSJMRzYiNyciIiIiIiMiIiQiIiUiIiY=# access goes from 1 to 5:L[1];NiMiIiI=L[2];NiMiIiM=L[3];NiMiIiQ=L[4];NiMiIiU=L[5];NiMiIiY=# we can change an entry in the list using the assignment operator :=L[1] := 2;NiM+JkkiTEc2IjYjIiIiIiIjL;NiM3JyIiI0YkIiIkIiIlIiIm# how can we append? # Our first guess is thisL := [L,6];NiM+SSJMRzYiNyQ3JyIiIiIiIyIiJCIiJSIiJiIiJw==# hmm, that was't what we wanted.# here is the solution. Let's first restore L:L := [1,2,3,4,5];NiM+SSJMRzYiNyciIiIiIiMiIiQiIiUiIiY=# 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 asop(L); #the content of the list, as a sequence:NiciIiIiIiMiIiQiIiUiIiY=[op(L),6]; #now we add an element and make another list:NiM3KCIiIiIiIyIiJCIiJSIiJiIiJw==# we can have a loop create a list as long as we wish:L := []; # start with an empty listNiM+SSJMRzYiNyI=for i from 1 to 10 do L := [ op(L), i ]: end;NiM+SSJMRzYiNyMiIiI=NiM+SSJMRzYiNyQiIiIiIiM=NiM+SSJMRzYiNyUiIiIiIiMiIiQ=NiM+SSJMRzYiNyYiIiIiIiMiIiQiIiU=NiM+SSJMRzYiNyciIiIiIiMiIiQiIiUiIiY=NiM+SSJMRzYiNygiIiIiIiMiIiQiIiUiIiYiIic=NiM+SSJMRzYiNykiIiIiIiMiIiQiIiUiIiYiIiciIig=NiM+SSJMRzYiNyoiIiIiIiMiIiQiIiUiIiYiIiciIigiIik=NiM+SSJMRzYiNysiIiIiIiMiIiQiIiUiIiYiIiciIigiIikiIio=NiM+SSJMRzYiNywiIiIiIiMiIiQiIiUiIiYiIiciIigiIikiIioiIzU=# 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;NiM3LCIiIiIiIyIiJCIiJSIiJiIiJyIiKCIiKSIiKiIjNQ==# there is a quick way to generate repeated elements in lists # for example 0$10 would generate 10 entries 0L := [3$7]; # seven 3'sNiM+SSJMRzYiNykiIiRGJ0YnRidGJ0YnRic=HOMEWORK PROBLEMS:# My big advice is that you open up a word file next to the # maple window and that you copy past stuff into a word document # once you are done with it. # Otherwise, you may loose data if the Maple session # happens to crash# hw 1 the Fibonacci sequence 1, 1, 2, 3, 5, 8, 13, 21, ... is defined as follows: f[1] = 1, f[2] = 1, f[i] = f[i-2] + f[i-1] for i >= 3. Create a list with the first 30 Fibonacci numbers. Use a for loop to create the list.# hw 2 # the Chebyshev Polynomial T[i] is defined as # T[0] = 1, T[1] = x and T[i] = 2*x*T[i-1] - T[i-2] for i >= 2 # create a list holding the first 10 Chebychev polynomials. # Attention, you cannot access the zero's element of lists, # hence you need to store T[i] in T[i+1].# hw 3:# Pascal's Triangle is the following array of numbers:# 1 # 1 1 # 1 2 1 # 1 3 3 1 # 1 4 6 4 1 # 1 5 10 10 5 1 # 1 6 15 20 15 6 1 # etc. # Figure out what is going on.# After that, have a little Maple program # compute Pascal's Triangle of 15 rows# use a Matrix to store the numbers.# The unused spots in the matrix shall be zero.# Remark: to copy the matrix into a word document, # you may want to "right click" on the Maple matrix and # export it to a "Tab Delimited" file. # In word you go file .. insert... and insert that same file. # Notice: If you cannot find your file the reason might # be that Word is looking for "doc" files, # whereas your file is only a simple text file. # you may want to change the search option to "all files" # in word. You should then see your exported file. OK?# hw 3# Read Kraft's notes, Worksheet #1