Skip to content

6. Identity Matrix

In this problem, you’re asked to enter an APL expression (some APL code), including arguments (data given to APL symbols). Your code will be tested by the APL Challenge system to check whether it gives the correct answer and uses the methods described below.

You can use round brackets ( () ) to change the order in which things are calculated. In problem 4 you learnt that an APL function takes the result of all code to its right as its right argument. This was a simplification; the right argument only goes as far as the nearest closing bracket () or ])on its right:

  1. 2×3+4 gives 14 because × takes the result of all code to its right, 3+4, as its right argument.
  2. 2×(3+4) gives 14 because × takes the result of all code to its right, (3+4), as its right argument.
  3. (2×3)+4 gives 10 because the right argument of × only goes as far as the nearest closing bracket.

When you used Equal To (=) in problem 3, you were using it to compare letters in a text. However, it also works on numbers. For example:

      1 = 3 1 4 1 5 9
0 1 0 1 0 0

Using round brackets, (from problem 1), =, and ∘. (from problem 5), create a 5-by-5 table that has 1s on the diagonal from the top left to the bottom right, with all other numbers being 0s. This is known as an identity matrix of size 5 and looks like this:

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