37 lines
1 KiB
Text
37 lines
1 KiB
Text
/* NetRexx */
|
|
options replace format comments java crossref symbols nobinary
|
|
|
|
runSample(arg)
|
|
return
|
|
|
|
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
method createIdMatrix(n) public static
|
|
DIM_ = 'DIMENSION'
|
|
m = 0 -- Indexed string to hold matrix; default value for all elements is zero
|
|
m[DIM_] = n
|
|
loop i = 1 to n -- NetRexx indexed strings don't have to start at zero
|
|
m[i, i] = 1 -- set this diagonal element to 1
|
|
end i
|
|
return m
|
|
|
|
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
method displayIdMatrix(m) public static
|
|
DIM_ = 'DIMENSION'
|
|
if \m.exists(DIM_) then signal RuntimeException('Matrix dimension not set')
|
|
n = m[DIM_]
|
|
loop i = 1 to n
|
|
ol = ''
|
|
loop j = 1 To n
|
|
ol = ol m[i, j]
|
|
end j
|
|
say ol
|
|
end i
|
|
return
|
|
|
|
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
method runSample(arg) public static
|
|
parse arg n .
|
|
if n = '' then n = 5
|
|
say 'Identity Matrix of size' n
|
|
displayIdMatrix(createIdMatrix(n))
|
|
return
|