aUCBLogo Demos and Tests / det
to det
pr "Determinant
ar = {{1 0 2 -1}{3 -2 6 4}{5 4 3 0}{2 2 -5 6}} ; -> det=-132
m=count ar
pr (se "Ordnung= m)
pr ar
br=(mdArray (se m-1 m-1) 1)
for [i 1 m-1] [for [j 1 m-1] [setB i j 0] ]
q=1
for [n m 2 -1]
[ z=0
ifElse (readA 1 1) == 0 [qq=1][qq=(1/(readA 1 1))^(n-2)]
q=q*qq ;cs
pr (se "from_n= n "to_n= n-1)
pr (se "qq qq "q= q)
for [i 2 n]
[ for [j 2 n]
[ z=z+1
a=(readA 1 1) * (readA i j) - (readA i 1) * (readA 1 j)
(setB i-1 j-1 a)
pr (se "a( i-1 j-1 ")= a )
if n == 2
[ (pr)
pr "Result:
pr (se "a= a "; "q= q "; "Det=a*q= q*(readB i-1 j-1))
stop
]
if z == (n-1)^2 [(pr) pr "(nextpage)]
] ; next j
(pr)
] ; next i
for [i 1 n-1]
[
for [j 1 n-1]
[(setA i j (readB i j))]
] ; next i
] ; next n
to readA ia ib
op ri (se ia ib) ar
end
to readB ia ib
op ri (se ia ib) br
end
to ri iList mat ; read item
op mdItem iList mat
end
to setA ia ib val
si (se ia ib) ar val
end
to setB ia ib val
si (se ia ib) br val
end
to si iList mat val ; set item
mdSetItem iList mat val
end
end