Question: function x = gaussJordan ( A , B ) % Solve Ax = B by Gauss - Jordan elimination algorithm. [ NA , ~ ]

function x = gaussJordan(A, B)
% Solve Ax = B by Gauss-Jordan elimination algorithm.
[NA, ~]= size(A);
[~, NB]= size(B);
if NB ~= NA
error('A and B must have compatible dimensions');
end
N = NA + NB;
AB =[A, B];
for k =1:NA
% Scaled Partial Pivoting
[akx, kx]= max(abs(AB(k:NA, k))./ max(abs(AB(k:NA, k:NA)),[],2));
if akx < eps
error('Singular matrix and No unique solution');
end
mx = k + kx -1;
if kx >1
tmp_row = AB(k, :);
AB(k, :) = AB(mx, :);
AB(mx, :) = tmp_row;
end
% Gauss forward and backward elimination
pivot = AB(k, k);
AB(k, :) = AB(k, :) / pivot;
for m =1:NA
if m ~= k
AB(m, :) = AB(m, :) - AB(m, k)* AB(k, :);
end
end
end
x = AB(:, NA+1:N);
end
modify the function gaus() into gausj() that implements GausJordan elimination algorithm and show that the function is indeed working.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!