54 lines
1.2 KiB
Plaintext
54 lines
1.2 KiB
Plaintext
get "libhdr"
|
|
manifest $( size = 5 $)
|
|
|
|
// Matrix index
|
|
let ix(mat, n, x, y) = mat+y*n+x
|
|
|
|
let lower(m, n) be
|
|
for y=0 to n-1
|
|
for x=0 to n-1 do
|
|
!ix(m,n,x,y) :=
|
|
x>y -> 0,
|
|
x=y | x=0 -> 1,
|
|
!ix(m,n,x-1,y-1) + !ix(m,n,x,y-1)
|
|
|
|
|
|
let upper(m, n) be
|
|
for y=0 to n-1
|
|
for x=0 to n-1 do
|
|
!ix(m,n,x,y) :=
|
|
x<y -> 0,
|
|
x=y | y=0 -> 1,
|
|
!ix(m,n,x-1,y-1) + !ix(m,n,x-1,y)
|
|
|
|
let symmetric(m, n) be
|
|
for y=0 to n-1
|
|
for x=0 to n-1 do
|
|
!ix(m,n,x,y) :=
|
|
x=0 | y=0 -> 1,
|
|
!ix(m,n,x-1,y) + !ix(m,n,x,y-1)
|
|
|
|
// Print matrix
|
|
let writemat(m, n, d) be
|
|
for y=0 to n-1
|
|
$( for x=0 to n-1
|
|
$( writed(!ix(m,n,x,y), d)
|
|
wrch(' ')
|
|
$)
|
|
wrch('*N')
|
|
$)
|
|
|
|
// Generate and print 5-by-5 matrices
|
|
let start() be
|
|
$( let mat = vec size * size
|
|
|
|
writes("Upper-triangular matrix:*N")
|
|
upper(mat, size) ; writemat(mat, size, 2)
|
|
|
|
writes("*NLower-triangular matrix:*N")
|
|
lower(mat, size) ; writemat(mat, size, 2)
|
|
|
|
writes("*NSymmetric matrix:*N")
|
|
symmetric(mat, size) ; writemat(mat, size, 2)
|
|
$)
|