how to enter the number of iteration in Gauss seidel method

3 ビュー (過去 30 日間)
Afua Amoako Dadey
Afua Amoako Dadey 2021 年 5 月 2 日
コメント済み: Afua Amoako Dadey 2021 年 6 月 12 日
Hi everyoone
i have written a code for Guass seidel but instead of counting the number of iteration i want my code to be in such a way that i rather input the iteration number.Please can anyone help to do that .please find code attached
Thanks
%Gauss Seidel method
function [k,x]= GSeidel411_Afua(A, x,b, eps)
n = length(x) ;
r=zeros(n,1);
x1=zeros(n,1);
Max_iter=1000
k=0; %counting iterations
r=b-A*x;
while norm(r,2) >= eps
k=k+1;
if k > Max_iter
disp('Maximum number iterations')
break
end
y=b;
for i = 1 : n
for j = 1 : n
if j<i
y(i) = y(i) - A(i, j)*x1(j) ;
elseif j>i
y(i) = y(i) - A(i, j)*x(j);
end
end
x1(i) = y(i) / A(i, i) ;
end
x=x1;
r=b-A*x;
d=norm(r);
end

回答 (1 件)

Sindhu Karri
Sindhu Karri 2021 年 5 月 5 日
Hii,
You can use input function to manually give number of iterations to be run

カテゴリ

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