RosettaCodeData/Task/Identity-matrix/NetRexx/identity-matrix-2.netrexx
Ingy döt Net 776bba907c Sync
2013-10-27 22:24:23 +00:00

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