Jacobi iterative method in 1 for loop
1 view (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!