# Gauss jordan elimination

1. Apr 13, 2010

### hell_demon

can any body please give me matlab version 6 coding of gauss jordan elimination method or how to make following gauss elimination method to gauss jordan elimination method
clc;
n=input('Enter no. of eqaution: ');
A=input('Enter matrix [A]: ');
r=input('Enter matrix [r]: ');
D=A;d=r;
%create upper triangular matrix
s=0;
for j=1:n-1
if A(j,j)==0
k=j;
for k=k+1:n
if A(k,j)==0
continue
end
break
end
B=A(j,:); C=r(j);
A(j,:)=A(k,:); r(i)=r(k);
A(k,:)=B;r(k)=C;
end
for i=1+s:n-1
L=A(i+1,j)/A(j,j);
A(i+1,:)=A(i+1,:)-L*A(j,j);
r(i+1)=r(i+1)-L*r(j);
end
s=s+1;
end
%solution equation
x(n)=r(n)/A(n,n);
for i=n-1:-1:1
sum=0;
for j=i+1:n
sum=sum+A(i,j)*x(j);
end
x(i)=(1/A(i,i)*(r(i)-sum));
end
p=inv(D)*d;
%----------output------------
fprintf('\nThe sol. of system of equations using gauss elimination method is :- \n');
disp('Upper triangular matrix = ');disp(A)
disp('Solution of linear equation: ');disp(x)
disp('Solution with matlab function(for checking): ');disp(p)

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted