GaussJordonMethod
GaussJordonMethod
The Gauss-Jordan method is an algorithm for solving systems of linear equations by converting
the matrix to its reduced row echelon form (RREF). Here’s the MATLAB implementation with
detailed explanations:
Code:
% Gauss-Jordan Method in MATLAB
% Define the augmented matrix [A|b]
augmented_matrix = [2, 1, -1, 8;
-3, -1, 2, -11;
-2, 1, 2, -3]; % Example system of equations
% Get the number of rows
[n, ~] = size(augmented_matrix);
% Perform Gauss-Jordan elimination
for i = 1:n
% Make the diagonal element 1
augmented_matrix(i, :) = augmented_matrix(i, :) / augmented_matrix(i, i);
% Make the other elements in the column 0
for j = 1:n
if i ~= j
factor = augmented_matrix(j, i);
augmented_matrix(j, :) = augmented_matrix(j, :) - factor * augmented_matrix(i, :);
end
end
end
% Extract the solution
solution = augmented_matrix(:, end);
% Display the results
disp('The solution of the system is:');
disp(solution);
Wokplace of the Code: Output of the Code:
The augmented matrix [A|b] includes the coefficient matrix A and the right-hand side vector 𝑏
Size of the Matrix:
[n, ~] = size(augmented_matrix);
n is the number of rows (equations) in the system.
Gauss-Jordan Elimination:
for i = 1:n
augmented_matrix(i, :) = augmented_matrix(i, :) / augmented_matrix(i, i);
Divides each row by its diagonal element to make the diagonal element equal to 1.
for j = 1:n
if i ~= j
factor = augmented_matrix(j, i);
augmented_matrix(j, :) = augmented_matrix(j, :) - factor * augmented_matrix(i, :);
end
end
Eliminates all other elements in the column to make them 0.
Extract the Solution:
solution = augmented_matrix(:, end);
The last column of the reduced matrix contains the solution to the system.
Display the Results:
disp('The solution of the system is:');
disp(solution);
Outputs the solution vector.
Example Input
Equations:
2x + y - z = 8
-3x - y + 2z = -11
-2x + y + 2z = -3
Augmented Matrix:
[2, 1, -1, 8;
-3, -1, 2, -11;
-2, 1, 2, -3];
Output:
Final Matrix:
[1 0 0 2]
[0 1 0 3]
[0 0 1 -1]
Solution:
The solution of the system is:
2
3
-1