Laboratory 10

1. Write a Maple function that produces an array containing the following variant of Pascal’s triangle:

\begin{matrix}n = 0 : & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ n = 1 : & 1 & 1 & 1 & 0 & 0 & 0 & 0 \\ n = 2 : & 1 & 2 & 3 & 2 & 1 & 0 & 0 \\ n = 3 : & 1 & 3 & 6 & 7 & 6 & 3 & 1 \\ i = & 0 & 1 & 2 & 3 & 4 & 5 & 6 \end{matrix}

Here the construction rule is

\left⟨{n + 1 \atop i}\right⟩ = \left⟨{n \atop i − 2}\right⟩ + \left⟨{n \atop i − 1}\right⟩ + \left⟨{n \atop i}\right⟩ ,

\left⟨{n \atop 0}\right⟩ = \left⟨{n \atop 2n}\right⟩ = 1,

\left⟨{n \atop j}\right⟩ = 0 for j < 0 or j > 2n.

Your procedure should take one argument, n, and return an (n+1)×(2n+1) array containing the first n rows of the triangle (the case n = 3 is depicted above).

Can you prove that the numbers in each row add up to 3^{n}?

2. In this problem you will gain insight into using Maple to design a special square called the magic square. The purpose is to give you some practice in using Maple as a tool to develop programs. Magic squares have some interesting properties which are listed below:

• The order of a magic square (say n) is the number of rows (or columns)

• The number of rows and columns is the same

• Each number in the magic square is unique

• The numbers in the magic square are in the range {1..n^{2}}

• The sum of all the numbers in each row = the sum of all numbers in each column = the sum of all numbers in both diagonals = N

• There is a specific relationship between the sum N and the order n

In this problem you will write a Maple program to print magic squares of odd order. An example 3 × 3 (order 3) and 5 × 5 (order 5) magic square is shown below.

8 1 6  17 24 1 8 15
3 5 7  23 5 7 14 16
4 9 2  4 6 13 20 22
10 12 19 21 3
11 18 25 2 9

3 × 3 magic square 5 × 5 magic square

It is quite straightforward to see how the numbers are filled. Before you come to the lab, study the magic squares of order 3 and 5 and try to think of a way in which a program could be written for any odd order. In the beginning of the lab the algorithm will be explained to you. Therefore do not panic if you are finding it difficult.

\underline{Deliverables} At the end of the lab you should have accomplished the following:

• Understood how the magic squares of odd order are created

• Implemented and tested your program to print magic squares

• Demo your program to one of the assistants

• Find the relationship between N and n

After you have finished the above program, try to think of a way to construct magic squares of order {4, 8, 16, 32, 64, ...}. Is it possible to construct a magic square of order 6?