Question: function X = myGaussJordan ( A , B ) n = size ( A , 1 ) ; X = [ A , B ]

function X = myGaussJordan(A, B)
n = size(A,1);
X =[A, B];
for i =1:n
[~, max_row]= max(abs(X(i:n, i)));
max_row = max_row + i -1;
X([i, max_row], :) = X([max_row, i], :);
pivot = X(i, i);
if abs(pivot)<1e-10
error('Matrix is singular or poorly conditioned.');
end
X(i, :) = X(i, :) / pivot;
for j =1:n
if i ~= j
X(j, :) = X(j, :) - X(j, i)* X(i, :);
end
end
end
X = X(:, n+1:end);
end
A =[2,1,-1;
1,3,2;
1,0,3];
B =[4;
3;
5];
X = myGaussJordan(A, B);
disp('Solution:');
disp(X);

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 Databases Questions!