Effacer les filtres
Effacer les filtres

Jacobi iterative method in 1 for loop

1 vue (au cours des 30 derniers jours)
Isaac Al-rai
Isaac Al-rai le 25 Fév 2018
Modifié(e) : Geoff Hayes le 26 Fév 2018
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?

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by