LAB-6
LAB-6
LAB REPORT: 6
Class BEE-07
LAB TITLE
Compilation of Gaussian elimination method, partial pivoting and scaled
partial pivoting methods to solve linear equations
1|Page
EXPERIMENT NUMBER: 6
Introduction
Root Finding Technique (Gaussian elimination method)
A system of linear equations with various unknown factors is known as a system of linear equations. Unknown factors
can be found in various equations, as we all know. To check all of the equations that make up the system, you must find
the value for the unknown factors. We can state that the given system is a consistent independent system if there is a
single solution that indicates one value for each unknown factor. If there are several solutions, the system has an infinite
number of solutions, then we call it a consistent dependent system.
The method we use to perform the three types of matrix row operations on an augmented matrix obtained from a linear
system of equations to find the solutions for such a system is known as the Gaussian elimination method. The Gaussian
elimination with the back substitution step is carried out if solutions for the variables involved in the linear system can
be found. This final step yields a reduced echelon form of the matrix, which yields the system of linear equations'
general solution.
Gaussian elimination is the name of the method we use to perform the three types of matrix row operations on an
augmented matrix coming from a linear system of equations in order to find the solutions for such system. This
technique is also called row reduction The Gaussian elimination rules are the same as the rules for the three elementary
row operations, in other words, you can algebraically operate on the rows of a matrix in the next three ways (or
combination of):
LAB-TASK
3x1+6x2-9x3 = 15
2x1+4x2-6x3 = 10
-2x1-3x2+4x3 = -6
Compute the solution of above tasks in MATLAB by using:
1. Gauss elimination method (without partial pivoting/scaled pivoting).
2. Partial pivoting method
3. Scaled partial pivoting method
MATLAB CODE
2|Page
EXPERIMENT NUMBER: 6
% Coefficients matrix
% Augmented matrix
AB = [A B];
% Gauss elimination
n = size(A, 1);
for k = 1:n-1
for i = k+1:n
end
end
% Back substitution
X = zeros(n, 1);
for i = n-1:-1:1
end
disp(X);
3|Page
EXPERIMENT NUMBER: 6
Consol Window
Without partial pivoting, Gaussian elimination may encounter a scenario where the pivot element (diagonal
entry) is zero or very close to zero, causing a division by zero or amplifying rounding errors.
In cases where a diagonal element becomes zero during elimination (or is very small compared to other
elements), forward elimination fails.
Without pivoting, rounding errors may accumulate, especially for systems with large differences in magnitude
between elements (ill-conditioned systems).
Ill-conditioned systems are more sensitive to numerical errors, and their solutions may vary significantly due to
minor changes in input data or operations.
Partial Pivoting: Ideal for ensuring stability in most systems, as it avoids issues like division by zero and
minimizes computational instability.
MATLAB CODE
4 B| P= input('Enter
age the Constant Matrix / Source vector: ');
N = length(B);
end
Aug;
% Back Substitution
for k = N-1:-1:1
5|Page
X(k) = (Aug(k, N+1) - Aug(k, k+1:N) * X(k+1:N)) / Aug(k, k);
End
% Solution
EXPERIMENT NUMBER: 6
Console Window
MATLAB CODE
AB = [A B];
for k = 1:n-1
pivot = pivot + k - 1;
% Swap rows
if pivot ~= k
AB(pivot, :) = temp;
tempS = S(k);
S(k) = S(pivot);
S(pivot) = tempS;
6|Page
end
for i = k+1:n
EXPERIMENT NUMBER: 6
% Back substitution
X = zeros(n, 1);
for i = n-1:-1:1
EXPERIMENT NUMBER: 6
Console Window
8|Page