SlideShare a Scribd company logo
3
Most read
4
Most read
6
Most read
PRACTICAL
Name- Saloni Singhal
M.Sc. (Statistics) II-Sem.
Roll No: 2046398
Course- MATH-409 L
Numerical Analysis Lab
Submitted To: Dr. S.C. Pandey
OBJECTIVE
1. Create an M-file to implement Gauss Jacobi
method.
2. Write both the script file and function for the
program created.
Theory
Diagonal Dominance:
• Iterative Method can be applied when diagonal
dominance exist that is when absolute value of its
leading diagonal elements is greater than or equal to
the sum of absolute value of the remaining element.
• It is a method of solving a matrix equation that has no
zeros along its main diagonal. Each diagonal element is
solved for, and an approximate value plugged in. The
process is then iterated until it converges.
• Applied to non square matrix also as opposed to the direct
methods.
• The method is easily derived by examining each of
the Xn equations
Script File
% defines matrix A
A = [2 1 1; 3 5 2;2 1 4];
% defines vector b
b = [5;15;8]
% solves linear system (i.e. solves Ax=b
for x)
[m n]=size(A);
x=zeros(n,1);
if m~=n
fprintf("incorrect size")
exit
end
aug=[A b];
%diagonal dominance
for i=1:n-1
for j=i:n
[a b]=max(aug(j,1:n));
if b==i
temp=aug(i,:);
aug(i,:)=aug(j,:);
aug(j,:)=temp;
break
end
end
end
Script File Contd.
%check diag dominance
for i=1:n
[a b]=max(aug(i,1:n));
if a~=aug(i,i)
fprintf("divergent")
exit
end
end
%assign tolerance
error=1;
p=0;
while error>=0.01
xold=x;
p=p+1;
fprintf("x%d:",p);
xold
%approximations
for i=1:n
augx=[aug(i,1:i-1) aug(i,i+1:n)];
xx=[xold(1:i-1) xold(i+1:n)];
x(i)=(aug(i,n+1)-dot(augx,xx))/aug(i,i);
end
xold=abs(x-xold);
error=max(xold);
end
x
error
Function
File
function [x,convergence] = seidelA,b)
[m n]=size(A);
x=zeros(n,1);
if m~=n
fprintf("incorrect size")
exit
end
aug=[A b];
%converting into strictly or partially
diagonal dominant
for i=1:n-1
for j=i:n
[a b]=max(aug(j,1:n));
if b==i
temp=aug(i,:);
aug(i,:)=aug(j,:);
aug(j,:)=temp;
break
end
end
end
Program Contd.
%check diag dom
for i=1:n
[a b]=max(aug(i,1:n));
if a~=aug(i,i)
fprintf("divergent")
exit
end
end
%setting tolerance limit for terminating iterations
error=1;
p=0;
while error>=0.01
xold=x;
p=p+1;
fprintf("x%d:",p);
xold
%approximations
for i=1:n
augx=[aug(i,1:i-1) aug(i,i+1:n)];
%xold takes initial values calculated in successive
iterations
xx=[xold(1:i-1) xold(i+1:n)];
x(i)=(aug(i,n+1)-dot(augx,xx))/aug(i,i);
end
xold=abs(x-xold);
error=max(xold);
end
x
error
end
Cases: (Convergent and Divergent
Matrix)
Caveats
• Iterative Method can only be used to
give solutions when the system of
linear equation is convergent or
diagonally dominant.
• The Jacobi iterative method works
fine with well-conditioned linear
systems. If the linear system is ill-
conditioned, it is most probably that
the Jacobi method will fail to
converge.
References
• https://mathworld.wolfram.com/JacobiMethod
.html#:~:text=The%20Jacobi%20method%20i
s%20a,then%20iterated%20until%20it%20co
nverges.
• Lecture notes of Prof. S.C. Pandey Sir
• MATLAB Documentation

More Related Content

PPTX
MARLAB codes for Gauss Seidel
PDF
Gauss Elimination Method With Partial Pivoting
PPTX
Gauss Elimination (without pivot).pptx
PPTX
Gauss Elimination (With Partial Pivot)
PPTX
Error analysis
PPT
Data Structures- Part2 analysis tools
PDF
Final Design Project - Memo (with GUI)
PPTX
Project management
MARLAB codes for Gauss Seidel
Gauss Elimination Method With Partial Pivoting
Gauss Elimination (without pivot).pptx
Gauss Elimination (With Partial Pivot)
Error analysis
Data Structures- Part2 analysis tools
Final Design Project - Memo (with GUI)
Project management

Similar to MATLAB Codes for Jacobi method (20)

PPTX
Analysis Framework, Asymptotic Notations
PDF
Numerical differentation with c
PPT
Matrix Multiplication(An example of concurrent programming)
PPT
matlab_tutorial.ppt
PPT
matlab_tutorial.ppt
PPT
matlab_tutorial.ppt
PDF
Efficient Solution of Two-Stage Stochastic Linear Programs Using Interior Poi...
PPT
Matlab1
PPTX
Unit ii algorithm
PDF
Quantum algorithm for solving linear systems of equations
PPT
matlab tutorial with separate function description and handson learning
PDF
Signal _system _EXP_.eriment _E_0.7.0.pdf
DOCX
Numerical Methods Lab - Shakil Anower Samrat
PDF
2-Algorithms and Complexit data structurey.pdf
PPTX
2-Algorithms and Complexity analysis.pptx
PDF
A review of automatic differentiationand its efficient implementation
PDF
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
PDF
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
PDF
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpall...
PDF
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Analysis Framework, Asymptotic Notations
Numerical differentation with c
Matrix Multiplication(An example of concurrent programming)
matlab_tutorial.ppt
matlab_tutorial.ppt
matlab_tutorial.ppt
Efficient Solution of Two-Stage Stochastic Linear Programs Using Interior Poi...
Matlab1
Unit ii algorithm
Quantum algorithm for solving linear systems of equations
matlab tutorial with separate function description and handson learning
Signal _system _EXP_.eriment _E_0.7.0.pdf
Numerical Methods Lab - Shakil Anower Samrat
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexity analysis.pptx
A review of automatic differentiationand its efficient implementation
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpall...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Ad

More from Saloni Singhal (20)

PPTX
Finite Difference Method
PPTX
Runge Kutta Method
PPTX
Euler Method
PPTX
Simpson's Three-Eighth Method
PPTX
Trapezoidal Rule
PPTX
Simpson One-Third
PPTX
Newton Forward Interpolation
PPTX
Newton Backward Interpolation
PPTX
Lagrange Interpolation
PPTX
Forward & Backward Differenece Table
PPTX
Bisection Method
PPTX
Newton's Raphson method
PPTX
Fixed Point Interation
PPTX
Power Method
PPTX
Eigen Show
PPTX
Inverse Power Method
PPTX
Convergence Analysis
PPTX
L-U Decomposition
PPTX
Flow of control
PPTX
Matlab Files
Finite Difference Method
Runge Kutta Method
Euler Method
Simpson's Three-Eighth Method
Trapezoidal Rule
Simpson One-Third
Newton Forward Interpolation
Newton Backward Interpolation
Lagrange Interpolation
Forward & Backward Differenece Table
Bisection Method
Newton's Raphson method
Fixed Point Interation
Power Method
Eigen Show
Inverse Power Method
Convergence Analysis
L-U Decomposition
Flow of control
Matlab Files
Ad

Recently uploaded (20)

PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
PDF
annual-report-2024-2025 original latest.
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PDF
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
PPTX
1_Introduction to advance data techniques.pptx
PPTX
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
PPTX
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
PPTX
Qualitative Qantitative and Mixed Methods.pptx
PPTX
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
PPTX
Business Ppt On Nestle.pptx huunnnhhgfvu
PDF
Business Analytics and business intelligence.pdf
PDF
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
PPTX
Data_Analytics_and_PowerBI_Presentation.pptx
PPTX
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
PPTX
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
PDF
Clinical guidelines as a resource for EBP(1).pdf
PDF
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
PDF
Lecture1 pattern recognition............
IBA_Chapter_11_Slides_Final_Accessible.pptx
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
annual-report-2024-2025 original latest.
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
oil_refinery_comprehensive_20250804084928 (1).pptx
1_Introduction to advance data techniques.pptx
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
Qualitative Qantitative and Mixed Methods.pptx
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
Business Ppt On Nestle.pptx huunnnhhgfvu
Business Analytics and business intelligence.pdf
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
Data_Analytics_and_PowerBI_Presentation.pptx
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
Clinical guidelines as a resource for EBP(1).pdf
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
Lecture1 pattern recognition............

MATLAB Codes for Jacobi method

  • 1. PRACTICAL Name- Saloni Singhal M.Sc. (Statistics) II-Sem. Roll No: 2046398 Course- MATH-409 L Numerical Analysis Lab Submitted To: Dr. S.C. Pandey
  • 2. OBJECTIVE 1. Create an M-file to implement Gauss Jacobi method. 2. Write both the script file and function for the program created.
  • 3. Theory Diagonal Dominance: • Iterative Method can be applied when diagonal dominance exist that is when absolute value of its leading diagonal elements is greater than or equal to the sum of absolute value of the remaining element. • It is a method of solving a matrix equation that has no zeros along its main diagonal. Each diagonal element is solved for, and an approximate value plugged in. The process is then iterated until it converges. • Applied to non square matrix also as opposed to the direct methods. • The method is easily derived by examining each of the Xn equations
  • 4. Script File % defines matrix A A = [2 1 1; 3 5 2;2 1 4]; % defines vector b b = [5;15;8] % solves linear system (i.e. solves Ax=b for x) [m n]=size(A); x=zeros(n,1); if m~=n fprintf("incorrect size") exit end aug=[A b]; %diagonal dominance for i=1:n-1 for j=i:n [a b]=max(aug(j,1:n)); if b==i temp=aug(i,:); aug(i,:)=aug(j,:); aug(j,:)=temp; break end end end
  • 5. Script File Contd. %check diag dominance for i=1:n [a b]=max(aug(i,1:n)); if a~=aug(i,i) fprintf("divergent") exit end end %assign tolerance error=1; p=0; while error>=0.01 xold=x; p=p+1; fprintf("x%d:",p); xold %approximations for i=1:n augx=[aug(i,1:i-1) aug(i,i+1:n)]; xx=[xold(1:i-1) xold(i+1:n)]; x(i)=(aug(i,n+1)-dot(augx,xx))/aug(i,i); end xold=abs(x-xold); error=max(xold); end x error
  • 6. Function File function [x,convergence] = seidelA,b) [m n]=size(A); x=zeros(n,1); if m~=n fprintf("incorrect size") exit end aug=[A b]; %converting into strictly or partially diagonal dominant for i=1:n-1 for j=i:n [a b]=max(aug(j,1:n)); if b==i temp=aug(i,:); aug(i,:)=aug(j,:); aug(j,:)=temp; break end end end
  • 7. Program Contd. %check diag dom for i=1:n [a b]=max(aug(i,1:n)); if a~=aug(i,i) fprintf("divergent") exit end end %setting tolerance limit for terminating iterations error=1; p=0; while error>=0.01 xold=x; p=p+1; fprintf("x%d:",p); xold %approximations for i=1:n augx=[aug(i,1:i-1) aug(i,i+1:n)]; %xold takes initial values calculated in successive iterations xx=[xold(1:i-1) xold(i+1:n)]; x(i)=(aug(i,n+1)-dot(augx,xx))/aug(i,i); end xold=abs(x-xold); error=max(xold); end x error end
  • 8. Cases: (Convergent and Divergent Matrix)
  • 9. Caveats • Iterative Method can only be used to give solutions when the system of linear equation is convergent or diagonally dominant. • The Jacobi iterative method works fine with well-conditioned linear systems. If the linear system is ill- conditioned, it is most probably that the Jacobi method will fail to converge.