fprintf('=====Test 1===================================\n');
A = [4,1;2,3];
b = [-1;3];
gaussianelimination(A,b);
fprintf('\n=====Test 2===================================\n');
A = [0,1;2,3];
b = [1;5];
gaussianelimination(A,b);
fprintf('\n=====Test 3===================================\n');
A = [1,1,0,3;2,1,-1,1;3,-1,-1,2;-1,2,3,-1];
b = [4;1;-3;4];
gaussianelimination(A,b);
fprintf('\n=====Test 4===================================\n');
fprintf('======The method can fail!=====================\n');
format short e
A = [1e-20,1;2,3];
b = [1;5];
gaussianelimination(A,b);
format
=====Test 1===================================
Initial augmented matrix
T =
4 1 -1
2 3 3
After 1 steps of Gaussian elimination:
T =
4.0000 1.0000 -1.0000
0 2.5000 3.5000
The solution is
x =
-0.6000
1.4000
=====Test 2===================================
Initial augmented matrix
T =
0 1 1
2 3 5
After 1 steps of Gaussian elimination:
T =
2 3 5
0 1 1
The solution is
x =
1
1
=====Test 3===================================
Initial augmented matrix
T =
1 1 0 3 4
2 1 -1 1 1
3 -1 -1 2 -3
-1 2 3 -1 4
After 1 steps of Gaussian elimination:
T =
1 1 0 3 4
0 -1 -1 -5 -7
0 -4 -1 -7 -15
0 3 3 2 8
After 2 steps of Gaussian elimination:
T =
1 1 0 3 4
0 -1 -1 -5 -7
0 0 3 13 13
0 0 0 -13 -13
After 3 steps of Gaussian elimination:
T =
1 1 0 3 4
0 -1 -1 -5 -7
0 0 3 13 13
0 0 0 -13 -13
The solution is
x =
-1
2
0
1
=====Test 4===================================
======The method can fail!=====================
Initial augmented matrix
T =
1.0000e-20 1.0000e+00 1.0000e+00
2.0000e+00 3.0000e+00 5.0000e+00
After 1 steps of Gaussian elimination:
T =
1.0000e-20 1.0000e+00 1.0000e+00
0 -2.0000e+20 -2.0000e+20
The solution is
x =
0
1