0% found this document useful (0 votes)
3 views2 pages

Jacobimethod (Matlab Coding)

The document outlines the implementation of the Gauss-Jacobi method for solving the equation Ax=b. It initializes the matrix A, vector b, and an initial guess for the solution x, while checking for the square and diagonally dominant properties of matrix A. The iterative process continues until the error is within a specified tolerance, and the number of iterations taken for convergence is displayed.

Uploaded by

walirehman1998
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Jacobimethod (Matlab Coding)

The document outlines the implementation of the Gauss-Jacobi method for solving the equation Ax=b. It initializes the matrix A, vector b, and an initial guess for the solution x, while checking for the square and diagonally dominant properties of matrix A. The iterative process continues until the error is within a specified tolerance, and the number of iterations taken for convergence is displayed.

Uploaded by

walirehman1998
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

%% Gauss-Jacobi Method

%% Solution of x in Ax=b using Jacobi Method


% * _*Initailize 'A' 'b' & intial guess 'x'*_
%%
clc;
clear all;
A=@5 -2 3;-3 9 1;2 -1 -7D
b=@-1 2 3D'
@n,mD=sizeHAL
x=@0 0 0D'
itr=0;
tol=1e-4
err=inf
% size gives how many rows and columns in the A matrix
@m,nD=sizeHAL
if m~=n
error=H'A is not a square matrix,but should be'L;
else
dispH'A is square matrix'L
end

count=0;
for i=1:n
sumrow=0;
for j=1:1:n
if i~=j
sumrow=sumrow+absHAHi,jLL;
end
end
if absHAHi,iLL>=sumrow
count=count+1;
end
end
if count==n
dispH'Matrix is diagonally dominant'L
else
dispH'Matrix is not diagonally dominant'L
end
while err>tol
xold=x

for i=1:n
sum=0;

for j=1:n

if j~=i
sum=sum+AHi,jL*xoldHjL
end

end

xHiL=H1•AHi,iLL*HbHiL-sumL
end
itr=itr+1
2 JacobiMethod.m

err=absHxold-xL;
end
fprintfH'Method converge in %d iteration \n',itrL;
dispHxL

You might also like