-
Notifications
You must be signed in to change notification settings - Fork 0
/
pivot.m
32 lines (31 loc) · 879 Bytes
/
pivot.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
% function A = pivot(A,r,s)
%
% ars = A(r,s);
%
% % Row operations
% for ir = 1 : size(A,1)
% if ir ~= r
%
% airs = A(ir,s);
% A(ir,:) = ars*A(ir,:) - airs*A(r,:);
% end
% end
%
% % Making ones be ones
% for is = 1 : size(A,2)
% elements = find(A(:,is) ~= 0);
% if numel(elements) == 1
% A(elements,:) = A(elements,:)/A(elements,is);
% end
% end
function R = pivot(M, r, c)
[d, w] = size(M); % Get matrix dimensions
R = zeros(d, w); % Initialize to appropriate size
R(r,:) = M(r, :) / M(r,c); % Copy row r, normalizing M(r,c) to 1
for k = 1:d % For all matrix rows
if (k ~= r) % Other then r
R(k,:) = M(k,:) ... % Set them equal to the original matrix
- M(k,c) * R(r,:); % Minus a multiple of normalized row r, making R(k,c)=0
end
end
end