0% found this document useful (0 votes)
4 views

LAB-6

Uploaded by

fa21-bee-030
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

LAB-6

Uploaded by

fa21-bee-030
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

EXPERIMENT NUMBER: 6

Department of Electrical and Computer Engineering

LAB REPORT: 6

Name Farid Uddin

Registration Number FA21-BEE-016/ATK

Class BEE-07

Subject Numerical Computation (NC)

Submitted To Dr. Babar Sattar

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):

 Interchanging two rows


 Multiplying a row by a constant (any constant which is not zero)
 Adding a row to another row

LAB-TASK

Task: Solve the following system of linear equations:

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

Gauss elimination method (without partial pivoting/scaled pivoting):

MATLAB CODE
2|Page
EXPERIMENT NUMBER: 6
% Coefficients matrix

A = [3, 6, -9; 2, 4, -6; -2, -3, 4];

% Right-hand side vector

B = [15; 10; -6];

% Augmented matrix

AB = [A B];

% Gauss elimination

n = size(A, 1);

for k = 1:n-1

for i = k+1:n

factor = AB(i, k) / AB(k, k);

AB(i, k:end) = AB(i, k:end) - factor * AB(k, k:end);

end

end

% Back substitution

X = zeros(n, 1);

X(n) = AB(n, end) / AB(n, n);

for i = n-1:-1:1

X(i) = (AB(i, end) - AB(i, i+1:n) * X(i+1:n)) / AB(i, i);

end

disp('Solution using Gauss Elimination (Without Pivoting):');

disp(X);

3|Page
EXPERIMENT NUMBER: 6

Consol Window

Reason of getting NaN:

 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.

Partial Pivoting Method

MATLAB CODE

% Gauss Elimination method using PARTIAL PIVOTING METHOD

clc; clear all; close all;

A = input('Enter the coefficient Matrix: ');

4 B| P= input('Enter
age the Constant Matrix / Source vector: ');

N = length(B);

X = zeros(N, 1); % Variable matrix initialize with zero value at start


EXPERIMENT NUMBER: 6

end

Aug;

% Back Substitution

Aug X(N) = Aug(N, N+1) / Aug(N, N);

% Last variable calculation

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

Scaled Partial Pivoting Method

MATLAB CODE

% Scaled partial pivoting

AB = [A B];

S = max(abs(A), [], 2); % Scale factors

for k = 1:n-1

% Find the pivot row

[~, pivot] = max(abs(AB(k:n, k)) ./ S(k:n));

pivot = pivot + k - 1;

% Swap rows

if pivot ~= k

temp = AB(k, :);

AB(k, :) = AB(pivot, :);

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);

X(n) = AB(n, end) / AB(n, n);

for i = n-1:-1:1

X(i) = (AB(i, end) - AB(i, i+1:n) * X(i+1:n)) / AB(i, i);


7|Page
end
disp('Solution using Scaled Partial Pivoting:');

EXPERIMENT NUMBER: 6

Console Window

8|Page

You might also like