What is Jacobi method

4 views (last 30 days)
Math app
Math app on 16 Sep 2019
Answered: Radu Trimbitas on 20 Jan 2022
How Can i write a program for Jacobi method un MATLAB

Answers (1)

Radu Trimbitas
Radu Trimbitas on 20 Jan 2022
See the following source:
function [x,ni]=Jacobi(A,b,x0,err,nitmax)
%JACOBI Jacobi method
%call [x,ni]=Jacobi(A,b,x0,err,nitmax)
%parameters
%A - system matrix
%b - right hand side vector
%x0 - starting vector
%err - tolerance (default 1e-3)
%nitmax - maximum number of iterations (default 50)
%x - solution
%ni -number of actual iterations
%parameter check
if nargin < 5, nitmax=50; end
if nargin < 4, err=1e-3; end
if nargin <3, x0=zeros(size(b)); end
[m,n]=size(A);
if (m~=n) | (n~=length(b))
error('ilegal size')
end
%compute T and c (prepare iterations)
M=diag(diag(A));
N=M-A;
x=x0(:);
for i=1:nitmax
x0=x;
x=M\(N*x0+b); %x=T*x0+c;
if norm(x-x0,inf)<err*norm(x,inf)
ni=i;
return
end
end
error('iteration number exceeded')

Categories

Find more on Software Development Tools in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!