GM Lab - 7 - NM - SE14AB-BA
GM Lab - 7 - NM - SE14AB-BA
TECHNOLOGY
School of Electrical Engineering and Computer Sciences
COURSE NAME
Numerical Methods
Lab no
7
Introduction
Jacobi iterative method is an algorithm for determining the solutions of a diagonally
dominant system of linear equations.
Objectives
The purpose of this lab is to get familiar with Jacobi Method
Tools/Software Requirement
Matlab R2016a
Description
Skeleton code
k = 1;
while k <= m
err = 0;
end
Lab Task
Implement Jacobi’s method. Hard code the input matrix and take tolerance and no. of
iterations as input and then display solution vector.
Code:
for k = 1:max_iter
err = 0; % Reset error at each iteration
for i = 1:n
% Calculate the summation for j ≠ i
sum = A(i, [1:i-1, i+1:n]) * x([1:i-1, i+1:n]);
% Compute the new value of x
x_new(i) = (b(i) - sum) / A(i, i);
end
if k == max_iter
fprintf('Max iterations reached.\n');
end
% Display solution
fprintf('Solution:\n');
disp(x);
end
Output:
Deliverables
Submit single word file with matlab code and screen shot of Output.