Jacobi iterative method in 1 for loop

1 visualización (últimos 30 días)
Isaac Al-rai
Isaac Al-rai el 25 de Feb. de 2018
Editada: Geoff Hayes el 26 de Feb. de 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?

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by