Code covered by the BSD License

### Highlights from Matlab Code Gaussian Elimination Method

2.5

2.5 | 2 ratings Rate this file 65 Downloads (last 30 days) File Size: 1.32 KB File ID: #39850

# Matlab Code Gaussian Elimination Method

14 Jan 2013 (Updated 17 Jun 2013)

Source = http://crunchmodo.com/matlab-code-gaussian-elimination-method/

File Information
Description
MATLAB release MATLAB 7.5 (R2007b)
30 Sep 2013

How can you change this code to solve for 4 equations with 4 variables?
for example

[1 2 3 4;
5 6 7 8;
9 10 11 12;
13 14 15 16]

[1;
2;
3;
3];

Thanks!

18 Jun 2013

Here is the content of this submission. \ does the same thing faster and better, but a one character operator is not as impressive I guess.

function gauss_elimnation
a = [6 2 8;3 5 2;0 8 2];
b = [26;8;-7];
a(:,length(a)+1)=b
[rows cols]=size(a);
for i=1:cols
for j=i+1:rows
tmp=a(i,:).*(-a(j,i)/a(i,i));
a(j,:)=tmp+(a(j,:));
end
end
for i=length(1:rows)-(1:rows)+1
if(i<cols-1)
a(i,cols)=a(i,cols)-(sum(a(i,i+1:cols-1)));
end
end
disp('Solution = ');