'linear system of n equations
data 3 ' number of equations i.e. number of unknowns
' Matrix A
data 2,1,-2
data 3,-1,1
'data 4,2,-4
data 7,5,-3
' Right side
data 1,0,0
' Read data
read n
dim A(n,n),X(n),B(n)
for i = 1 to n
for j = 1 to n
read num:A(i,j) = num
next j
next i
for i = 1 to n
read num:B(i) = num
next i
print " ---> Linear System to be solved is :":print
for i = 1 to n
for j = 1 to n
if A(i,j)>0 then
print " ";"+";A(i,j);"*X(";j;")";
else
print " ";A(i,j);"*X(";j;")";
end if
next j
print " = ";B(i)
next i
' 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
end