필터 지우기
필터 지우기

Jacobi iterative method in 1 for loop

조회 수: 1 (최근 30일)
Isaac Al-rai
Isaac Al-rai 2018년 2월 25일
편집: Geoff Hayes 2018년 2월 26일
Hey all I am tryig to create a function that will run the jacobi iterative method using only one for loop. This is for a numerical methods assignment. Inspired from my textbook, I have gotten this code to give a single answer after typing it into the command line:
function X=jacob2(A,B,P,delta,max1)
N = length(B);
for k=1:max1
j=eye(100);
X(1:j)=(B(1:j)-A(1:j,[1:j-1,j+1:N])*P([1:j-1,j+1:N]))/A(1:j,1:j);
end
err=abs(norm(X'-P));
relerr=err/(norm(X)+eps);
P=X';
if (err<delta)||(relerr<delta)
RETURN
end
X=X';
end
And when I run this from the command line I am given only one solution.
if true
% code
X1=jacob2(A1,b1,P,0.001,100)
X1 =
0.0037
end
How can I get this to create the array of answers that I am looking for?

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by