フィルターのクリア

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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by