'linear system of n equations TEST
data 100 ' number of equations i.e. number of unknowns
' generate data input by random numbers
read n
dim A(n,n),X(n),B(n)
for i = 1 to n
for j = 1 to n
A(i,j) = rnd(1) * 1000
next j
next i
for i = 1 to n
B(i) = rnd(1) * 1000
next i
start = time$("ms")
' Transform A into triangular matrix
for k = 1 to n-1
if A(k,k) = 0 then print:print" *** Error *** No unique solution!":wait:stop
for i = k+1 to n
B(i) = B(i) - A(i,k)/A(k,k)*B(k)
for j = k+1 to n
A(i,j) = A(i,j) - A(i,k)/A(k,k)*A(k,j)
next j
next i
next k
' Solve triangular system
X(n) = B(n)/A(n,n)
for i = n-1 to 1 step -1
s = 0
for k = i+1 to n
s = s + A(i,k)*X(k)
next k
if A(i,i) = 0 then print "No Unique Solution !":wait:end
X(i) = (B(i) - s)/(A(i,i))
next i
' Print results
print:print " ---> Solution is :":print
for i = 1 to n
print " X(";i;") = ";X(i)
next i
print "End of calculation. Elapsed time in milliseconds: "; time$("ms") - start
end