How to resolve the algorithm Identity matrix step by step in the Icon and Unicon programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Identity matrix step by step in the Icon and Unicon programming language

Table of Contents

Problem Statement

Build an   identity matrix   of a size known at run-time.

An identity matrix is a square matrix of size n × n, where the diagonal elements are all 1s (ones), and all the other elements are all 0s (zeroes).

I

n

=

[

1

0

0

0

0

1

0

0

0

0

1

0

0

0

0

1

]

{\displaystyle I_{n}={\begin{bmatrix}1&0&0&\cdots &0\0&1&0&\cdots &0\0&0&1&\cdots &0\\vdots &\vdots &\vdots &\ddots &\vdots \0&0&0&\cdots &1\\end{bmatrix}}}

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Identity matrix step by step in the Icon and Unicon programming language

Source code in the icon programming language

link matrix
procedure main(argv)
    if not (integer(argv[1]) > 0) then stop("Argument must be a positive integer.")
    matrix1 := identity_matrix(argv[1], argv[1])
    write_matrix(&output,matrix1)
end


  

You may also check:How to resolve the algorithm Sum multiples of 3 and 5 step by step in the NetRexx programming language
You may also check:How to resolve the algorithm Minimal steps down to 1 step by step in the Nim programming language
You may also check:How to resolve the algorithm Dining philosophers step by step in the JoCaml programming language
You may also check:How to resolve the algorithm Least common multiple step by step in the Fermat programming language
You may also check:How to resolve the algorithm Order disjoint list items step by step in the Aime programming language