aUCBLogo Demos and Tests / imm
to imm ;invertMatrixMovie
init
tabl
setcursor se 3 4
type [original]
display :a 3 3
invert :a
display :a 3 12
setcursor se 3 13
type [inverse]
setCursor list 0 23
end
to init
make "a {{1 2 3 4 4 1 3 3}{4 5 6 7 2 3 3 1}{2 2 3 4 1 2 1 2}
{1 2 5 1 3 1 5 2}{3 0 4 4 6 1 4 1}{4 1 6 5 1 3 .7 3}
{3 2 5 1 3 3 9 1}{1 4 3 2 1 3 1 1}}
end
to tabl
ct
setTextFont [Courier New]
insertMode
for [i 1 80][type "-]
(pr)
for [i 1 21][pr "|]
for [i 1 21][setcursor se 79 :i type "|]
setcursor [1 22]
for [i 1 78][type "-]
overwriteMode
end
to display :a :b :c
make "n count :a
for [i 1 :n]
[ for [j 1 :n]
[ make "aa mditem se :i :j :a
setcursor se :b+ :j*8 :i+ :c
type form :aa 7 2
setcursor se 3 5
]
]
end
to invert :a
make "det 1
for [l 1 :n]
[ make "x mditem (se :l :l) :a
make "det :det* :x
ifelse :x==0
[ pr [singular matrix] stop
]
[ mdsetitem (se :l :l) :a 1
for [j 1 :n 1]
[ make "k mditem (se :l :j) :a
make "k :k/ :x
mdsetitem (se :l :j) :a :k
]
for [i 1 :n]
[ ifelse :i==:l
[ type "
]
[ make "x mditem (se :i :l) :a
mdsetitem (se :i :l) :a 0
for [j 1 :n]
[ make "aa mditem (se :i :j) :a
make "bb mditem (se :l :j) :a
make "bb :bb* :x
make "bb :aa- :bb
mdsetitem (se :i :j) :a :bb
setcursor se 3+ :j*8 12+ :i
type form :bb 7 2 setcursor se 2 5
wait 2
]
]
]
]
]
end