What is Jacobi method

11 visualizzazioni (ultimi 30 giorni)
Math app
Math app il 16 Set 2019
Risposto: Radu Trimbitas il 20 Gen 2022
How Can i write a program for Jacobi method un MATLAB

Risposte (1)

Radu Trimbitas
Radu Trimbitas il 20 Gen 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')

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by