You are on page 1of 1

% Gauss Elimination Method in MATLAB

clear all;
clc;

A = [0 1 1; 2 0 3; 1 1 1]
B = [2; 5; 3]
Na = length(A)
[Naa Nb] = size(B)
Aug = [A B]

if Na~= Naa
disp('A and B must have compatible dimensions')
end
if det(A) == 0
disp('singular matrix and no unique solution')
end
for i = 1:Na-1
m = Aug(i+1:Na,i)/Aug(i,i);
Aug(i+1 : Na, :) = Aug(i+1 : Na, :)-m*Aug(i, :)
end
A\B

You might also like