-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrow_reduced_echleon_form.m
46 lines (46 loc) · 1.03 KB
/
row_reduced_echleon_form.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function sol = row_reduced_echleon_form(A)
[r,c]=size(A);
j=1;
tol=1e-10;
for i=1:r
while abs(A(i,j))<tol
% is it zero or j < columns
imax=i; %index of the element with maximum value
maxe=A(i,j); %value of that element
for k=i+1:r % finding the max
if abs(A(k,j))>abs(maxe)
maxe=A(k,j);
imax=k;
end
end
if abs(maxe)<tol% is it zero
j=j+1;
else
A([i,imax],:)=A([imax,i],:); %swap the rows
end
if j>c
sol=non_negligible(A,tol);
return;
end
end
A(i,:)=A(i,:)/A(i,j); % do for all remaining elements in current row
for k=1:r
if k~=i
A(k,:)=A(k,:)-A(i,:)*A(k,j);
A(k,j)=0; % make elements other than the pivot element in the current row zero
end
end
j=j+1;
if j>c
break;
end
end
for i=1:r
for j=1:c
if abs(A(i,j))<tol
A(i,j)=0;
end
end
end
sol=A;
end