gaussian elimination with pivoting and backsubstitution help



Here's my (incomplete) code for gaussian elimination with pivoting and backsubstitution. I don't know if I implemented it right and my problem now is how can i solve for the x's?

Can you help me? Thank you so much.

n: 4$
m: 4$

array(eqn, n)$
eqn[1]: -4*x1+3*x2+4*x3-1*x4+37$
eqn[2]: -2*x1-5*x2+3*x3+20$
eqn[3]: -x1-x2-3*x3-4*x4+27$
eqn[4]: -3*x1+2*x2+4*x3-x4-7$

A: matrix()$
B: matrix()$

for i:1 while (i<=n) do(
    eqn: eqn[i],                                           
    coeffmatrx: [],                                        
    
        for j:1 while (j<=m) do(
            constantmatrx: coeff(eqn[i], concat('x,j)),     
            listarray[j]: [constantmatrx],                         
            coeffmatrx: append(coeffmatrx, listarray[j]),         
            eqn: coeff(eqn,concat('x,j), 0)                
        ),
    A: addrow(A, coeffmatrx),
    eqn: eqn * -1,                                            
    B: addrow(B, [eqn])
)$

myMatrix:addcol(A,B)$                                                 
display(myMatrix);      

gaussian_elimination (myMatrix) := block( [A, i, j, n, m, maxi, listarith:true],
   A: copymatrix(myMatrix),
   n:length(args(A)), 
   m:length(A[1])-1,
   
   i:1, 
   j:1,
  while (i<=m and j<=n) do (
      maxi:i,
      for k:i+1 thru m do
         if abs(A[k,j]) > abs(A[maxi,j]) then
            maxi:k,
 
      if A[maxi,j]#0 then (
         [A[i],A[maxi]]: [A[maxi],A[i]],
      
         A[i]: float(A[i]/A[i,j]),
      
         for u:i+1 thru m do
            A[u]: A[u] - A[u,j] * A[i],
 
         i: i+1 ),
      j: j+1 ),
   A )$    

display(gaussian_elimination(myMatrix));


_________________________________________________________________
Easily edit your photos like a pro with Photo Gallery.
http://get.live.com/photogallery/overview