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

LAB-7

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)
1 views

LAB-7

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/ 5

EXPERIMENT NUMBER: 7

Department of Electrical and Computer Engineering

LAB REPORT: 7

Name Farid Uddin

Registration Number FA21-BEE-016/ATK

Class BEE-07

Subject Numerical Computation (NC)

Submitted To Dr. Babar Sattar

LAB TITLE
Gauss Jordan method and Cramer’s Rule for linear systems of equations, and
Code compilation in MATLAB.

1|Page
EXPERIMENT NUMBER: 7
Introduction
Root Finding Technique (Gauss Jordan method)

The Gauss-Jordan method is similar to the Gaussian elimination process, except that the entries both above and below
each pivot are zeroed out. After performing Gaussian elimination on a matrix, the result is in row echelon form, while
the result after the Gauss Jordan method is in reduced row echelon form.

 Interchanging two rows


 Multiplying a row by a constant (any constant which is not zero)
 Adding a row to another row
 Make each pivot entry 1.
 Make all the entries of pivot column zero except pivot entry

LAB-TASK

Task: Solve the following system of linear equations:

A)

3x1+6x2-9x3 = 15

2x1+4x2-6x3 = 10

-2x1-3x2+4x3 = -6

B)

2x1+1x2-1x3 = 7

3x1-1x2+2x3 = 7

4x1-3x2+1x3 = 1

 Compute the solution of above tasks in MATLAB by using:


1. Gauss Jordan Method
2. Cramer’s Rule

Gauss Jordan Method

MATLAB CODE

2|Page
EXPERIMENT NUMBER: 7
% Gauss-Jordan Method (Reduced Echelon Form)

clc; clear all; close all;

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

B = input('Enter the Constant Matrix / Source vector: ');

N = length(B);

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

% Augmented Matrix

Aug = [A B];

for j = 1:N % To move columns wise

Aug(j, :) = Aug(j, :) / Aug(j, j); % To make each pivot entry 1

for i = 1:N % To move row wise

if i ~= j % Skip pivot element position

m = Aug(i, j); % To find the multiplier

Aug(i, :) = Aug(i, :) - m * Aug(j, :);

end

end

end

Aug

X = Aug(:, N + 1) % Extract solution from the last column of the augmented matrix

Consol Window

3|Page
EXPERIMENT NUMBER: 7

Cramer’s Rule

MATLAB CODE

% Cramer's Rule to solve a linear system of equations

clc; clear all; close all;

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

B = input('Enter the Constant Matrix / Source vector: ');

[N, M] = size(A); % Get the size of the coefficient matrix

if N ~= length(B)

error('The number of rows in A must match the length of B');

end
4|Page
X = zeros(N, 1); % Variable matrix initialized with zero value at start

d = det(A); % Determinant of matrix A


Aold = A;

EXPERIMENT NUMBER: 7

Console Window

5|Page

You might also like