Does anyone know how to write a program in MATLAB to perform
Does anyone know how to write a program in MATLAB to perform Gauss Elimination (not naïve) for a system of linear equations Ax = b?
Solution
Following is the program in MATLAB to perform Gauss Elimination
function x = gauss(A,b)
 A = cat(2,A,b);
 [m,n]=size(A);
 for j=1:m-1
     for z=2:m
         if A(j,j)==0
             t=A(j,:);A(j,:)=A(z,:);
             A(z,:)=t;
         end
     end
     for i=j+1:m
         A(i,:)=A(i,:)-A(j,:)*(A(i,j)/A(j,j));
     end
 end
 x=zeros(1,m);
 for s=m:-1:1
     c=0;
     for k=2:m
         c=c+A(s,k)*x(k);
     end
     x(s)=(A(s,n)-c)/A(s,s);
 end
 disp(\'Gauss elimination method:\');
 A
 x\'
 end
Sample Input:
A= [0.25 0.35 0.55
 0.35 0.2 0.4
 0.4 0.45 0.05]
b=[0.3
 0.3
 0.4]
gauss(A,b)
Sample Output
Gauss elimination method:
A =
    0.2500    0.3500    0.5500    0.3000
          0 -0.2900   -0.3700   -0.1200
          0           0        -0.6897   -0.0345
 ans =
    0.6000
     0.3500
     0.0500

