The program is:
! Practice Program 8.1
! A matrix is a one-dimensional or two-dimensional array of numbers.
! A square matrix has the same number of rows and columns. The
! principal diagonal of a square matrix goes from the upper left
! corner to the lower right corner. The identity matrix is a square
! matrix with elements along the principle diagonal having a value
! of 1, and the other elements having a value of 0. Here is an
! identity matrix displayed by a True Basic program:
! 1 0 0 0
! 0 1 0 0
! 0 0 1 0
! 0 0 0 1
!
! Using FOR statements, create and display an identity matrix
! with 10 rows and columns (a 10-by-10 matrix).
! Pseudocode:
! 1. Name the matrix Identity (i,j)
! 2. Initiallize with zeros for all i,j; 1 to 10 for each
! 3. Print out the matrix elements
! 4. Now substitute 1's for zeros i=j and for 1-10 using FOR statements
! 5. Print out the new matrix
! 6. Consider using a subroutine to do this for any i=j=n.
! 7. Start with a 3x3 identity matrix in MEX8.1.2
! Review 8.4 Arrays with two dimensions on p 216
! Declare a 2-D 10x10 array with DIM Identity (1 to 10, 1 to 10)
! See EP8-7 p218 for a nested for loop method to initialize Identity (10,10)
DIM Identity (1 to 10, 1 to 10)
FOR row = 1 to 10
FOR column = 1 to 10
IF row = column then
LET Identity (row,column)=1
ELSE
LET Identity (row,column)=0
END IF
NEXT column
NEXT row
FOR row = 1 to 10
FOR column = 1 to 10
SET COLOR "red"
PRINT Identity (row,column);
NEXT column
NEXT row
SET COLOR "blue"
PRINT "This is a 10x10 identity matrix"
PAUSE 6
SOUND 500,0.2
END
The output is:
1 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 1
This is a 10x10 identity matrix