Skip to content

7. More Identity Matrices

Note: In this problem, you’re asked to enter your own APL function, without giving it any arguments. Your function will be checked by the APL Challenge system using several tests to see whether it is correct.

You can create your own function by putting an expression in curly brackets ( {} ). For example, the expression 2+3 becomes the function {2+3}. Your function can take a right argument by using (omega, the right-most letter of the Greek alphabet) in the expression; any is replaced by the data to the right of the closing curly bracket ( } ).

For example, a function that multiplies its argument by two could be written {2×⍵}. Then:

  1. {2×⍵} 5 gives 10
  2. {2×⍵} 7 gives 14

Using what you learnt in problem 6, write a function that gives an identity matrix of the given size. For example:

      {answer} 5
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1

      {answer} 2
1 0
0 1

      {answer} 6
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1