Professional Documents
Culture Documents
Function Gauss Jordan
Function Gauss Jordan
Function Gauss Jordan
function gauss_jordan_method()
N = 4;
a = input('Enter the elements of the matrix:\n');
identity = eye(N);
aug = [a, identity];
for j = 1:N
for i = 1:N
if (i ~= j)
t = aug(i, j) / aug(j, j);
fprintf('\nRow Operation: R%d = R%d - (%.2f * R%d)\n', i, i, t, j);
for k = 1:(N + 1)
aug(i, k) = aug(i, k) - aug(j, k) * t;
end
fprintf('Updated Augmented Matrix:\n');
disp(aug);
end
end
end
Columns 6 through 9
1.0000 0 0 0
0 1.0000 0 0
0 0 1.0000 0
0 0 0 1.0000
Columns 6 through 9
1.0000 0 0 0
0 1.0000 0 0
0 0 1.0000 0
0 0 0 1.0000
Columns 6 through 9
1.0000 0 0 0
0 1.0000 0 0
0 0 1.0000 0
0 0 0 1.0000
Columns 6 through 9
1.0000 0 0 0
0 1.0000 0 0
0 0 1.0000 0
0 0 0 1.0000
Columns 6 through 9
1.0000 0 0 0
0 1.0000 0 0
0 0 1.0000 0
0 0 0 1.0000
Columns 6 through 9
1.0000 0 0 0
0 1.0000 0 0
0 0 1.0000 0
0 0 0 1.0000
1.0000 0 0 0
0 1.0000 0 0
0 0 1.0000 0
0 0 0 1.0000
Columns 6 through 9
1.0000 0 0 0
0 1.0000 0 0
0 0 1.0000 0
0 0 0 1.0000
Columns 6 through 9
1.0000 0 0 0
0 1.0000 0 0
0 0 1.0000 0
0 0 0 1.0000
Columns 6 through 9
1.0000 0 0 0
0 1.0000 0 0
0 0 1.0000 0
0 0 0 1.0000
Row Operation: R1 = R1 - (0.98 * R4)
Updated Augmented Matrix:
Columns 1 through 5
0.3500 0 0 0 7.0494
0 0.1731 0 0.6666 9.3123
0 0 -0.2006 0.5406 2.7046
0 0 0 -0.0408 1.1961
Columns 6 through 9
1.0000 0 0 0
0 1.0000 0 0
0 0 1.0000 0
0 0 0 1.0000
0.3500 0 0 0 7.0494
0 0.1731 0 0 28.8548
0 0 -0.2006 0.5406 2.7046
0 0 0 -0.0408 1.1961
Columns 6 through 9
1.0000 0 0 0
0 1.0000 0 0
0 0 1.0000 0
0 0 0 1.0000
0.3500 0 0 0 7.0494
0 0.1731 0 0 28.8548
0 0 -0.2006 0 18.5509
0 0 0 -0.0408 1.1961
Columns 6 through 9
1.0000 0 0 0
0 1.0000 0 0
0 0 1.0000 0
0 0 0 1.0000
0.3500 0 0 0 7.0494
0 0.1731 0 0 28.8548
0 0 -0.2006 0 18.5509
0 0 0 -0.0408 1.1961
Columns 6 through 9
1.0000 0 0 0
0 1.0000 0 0
0 0 1.0000 0
0 0 0 1.0000
for j = 1:N-1
fprintf('\nStep %d:\n', j);
for i = j+1:N
t = a(i,j) / a(j,j);
for k = j:N+1
a(i,k) = a(i,k) - a(j,k) * t;
end
disp(a);
end
end
x = zeros(N, 1);
for i = N:-1:1
s = 0;
for j = i+1:N
s = s + a(i,j) * x(j);
end
x(i) = (a(i,N+1) - s) / a(i,i);
end
fprintf('\nSolution:\n');
disp(x);
end
Enter the augmented matrix (4x5):
[0.35 0.16 0.21 0.01 14;0.54 0.42 0.54 0.10 28;0.04 0.24 0.10 0.65 12.5;0.07 0.18
0.15 0.24 10.5]
Initial Augmented Matrix:
0.3500 0.1600 0.2100 0.0100 14.0000
0.5400 0.4200 0.5400 0.1000 28.0000
0.0400 0.2400 0.1000 0.6500 12.5000
0.0700 0.1800 0.1500 0.2400 10.5000
Step 1:
0.3500 0.1600 0.2100 0.0100 14.0000
0 0.1731 0.2160 0.0846 6.4000
0.0400 0.2400 0.1000 0.6500 12.5000
0.0700 0.1800 0.1500 0.2400 10.5000
Step 2:
0.3500 0.1600 0.2100 0.0100 14.0000
0 0.1731 0.2160 0.0846 6.4000
0 0 -0.2006 0.5406 2.7046
0 0.1480 0.1080 0.2380 7.7000
Step 3:
0.3500 0.1600 0.2100 0.0100 14.0000
0 0.1731 0.2160 0.0846 6.4000
0 0 -0.2006 0.5406 2.7046
0 0 0 -0.0408 1.1961
Solution:
20.1411
166.6532
-92.4798
-29.3145