DiagSize
DiagSize
returns the size of the diagonal. It works for both rectangle and square arrays.
For example,
ans = DiagSize(n=3, diagNo=1)
Returns the size of first super diagonal of a square matrix of shape (3,3).
And,
ans = DiagSize(n=3, diagNo=-1)
Returns the size of first sub diagonal of a square matrix of shape (3,3).
ans = DiagSize(m=4, n=7, diagNo = 1)
Returns the size of first super diagonal of a rectangle matrix of shape (4,7). Here m and n stand for number of rows and cols, respectively.
- ܀ See example
- ↢ Close
In this example we show the usage of DiagSize routine.
Usage
header
program main
use easifemBase
(4,4) main diagonal
call Display( DiagSize(4, 0), "(4,4), main diagonal = " )
(4,4) first super diagonal
call Display( DiagSize(4, 1), "(4,4), first superdiagonal = " )
(4,4) second super diagonal
call Display( DiagSize(4, 2), "(4,4), second superdiagonal = " )
(4,4) out of bound super diagonal
call Display( DiagSize(4, 5), "(4,4), out of bound superdiagonal = " )
results
(4,4), main diagonal = 4
(4,4), first superdiagonal = 3
(4,4), second superdiagonal = 2
(4,4), out of bound superdiagonal = 0
(4,4) first subdiagonal
call Display( DiagSize(4, -1), "(4,4), first subdiagonal = " )
(4,4) second subdiagonal
call Display( DiagSize(4, -2), "(4,4), second subdiagonal = " )
(4,4) out of bound subdiagonal
call Display( DiagSize(4, -5), "(4,4), out of bound subdiagonal = " )
results
(4,4), first subdiagonal = 3
(4,4), second subdiagonal = 2
(4,4), out of bound subdiagonal = 0
Let us now test DiagSize
for rectangle matrix.
(4,7) main diagonal
call Display( DiagSize(4, 7, 0), "(4, 7), main diagonal = " )
(4,7) first super diagonal
call Display( DiagSize(4, 7, 1), "(4, 7), first superdiagonal = " )
(4,7) second super diagonal
call Display( DiagSize(4, 7, 2), "(4, 7), second superdiagonal = " )
(4,7) more superdiagonal
call Display( DiagSize(4, 7, 3), "(4,7), third superdiagonal = " )
call Display( DiagSize(4, 7, 4), "(4,7), fourth superdiagonal = " )
call Display( DiagSize(4, 7, 5), "(4,7), fifth superdiagonal = " )
call Display( DiagSize(4, 7, 6), "(4,7), sixth superdiagonal = " )
(4,7) out of bound superdiagonal
call Display( DiagSize(4, 7, 7), "(4,7), out of bound superdiagonal = " )
results
(4, 7), main diagonal = 4
(4, 7), first superdiagonal = 4
(4, 7), second superdiagonal = 4
(4,7), third superdiagonal = 4
(4,7), fourth superdiagonal = 3
(4,7), fifth superdiagonal = 2
(4,7), sixth superdiagonal = 1
(4,7), out of bound superdiagonal = 0
(4,7) 1:3 subdiagonal
call Display( DiagSize(4, 7, -1), "(4,7), first subdiagonal = " )
call Display( DiagSize(4, 7, -2), "(4,7), second subdiagonal = " )
call Display( DiagSize(4, 7, -3), "(4,7), thrid subdiagonal = " )
(4,7) out of bound subdiagonal
call Display( DiagSize(4, 7, -4), "(4,7), out of bound subdiagonal = " )
results
(4,7), first subdiagonal = 3
(4,7), second subdiagonal = 2
(4,7), thrid subdiagonal = 1
(4,7), out of bound subdiagonal = 0
Now let's test it for rectangle matrix.
cleanup
end program