필터 지우기
필터 지우기

What is Jacobi method

조회 수: 3 (최근 30일)
Math app
Math app 2019년 9월 16일
답변: Radu Trimbitas 2022년 1월 20일
How Can i write a program for Jacobi method un MATLAB

답변 (1개)

Radu Trimbitas
Radu Trimbitas 2022년 1월 20일
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')

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by