top of page
CPMSE Worked Examples
MATRIX FLOOR
Write a sequence of steps that will create an n by n matrix for an odd number n such that the innermost element is 0 and the elements adjacent to the innermost (not including diagonals) are set to 1 and the elements adjacent to those are set to 2, and so on until all the elements are filled. Do not use any loops or conditional expressions (since we have not covered these yet)
For example
if n=3 we would have the matrix... If n=5 we would have the matrix....
HINTS
To accomplish this you may want to make use of the following functions: floor, abs and
matrix multiplication (*). Assume n is odd.
Also... What happens when you matrix multiply a nx1 matrix of all 1's by a 1xn matrix filled with various values?
bottom of page