フィルターのクリア

error in while loop

1 回表示 (過去 30 日間)
Piyanut Nanta
Piyanut Nanta 2015 年 6 月 17 日
編集済み: Nicholas Sullivan 2015 年 6 月 19 日
Hi, I want to loop of Jacobi method but error in while loop. help me please
clear all
clc
n=input('Number of equations (n): ');
A=input('Enter the matrix A,2D Matrix: ');
b=input('Enter the matrix b,Column vector: ');
E=input('Permissible error: ');
x0=zeros(1,n);
x=x0;
k=0;
while
k=k+1;
fprintf('%d',k);
for i=1:n
j=1:n
if i~=j
sum=sum+A(i,j)*x(j);
end
x(i)=(b(i)-sum)/A(i,i);
fprintf('%10.5f',x(i));
end
end

回答 (1 件)

Nicholas Sullivan
Nicholas Sullivan 2015 年 6 月 17 日
編集済み: Nicholas Sullivan 2015 年 6 月 19 日
I think you might be missing a nested 'for' statement. Instead of
for i=1:n
j=1:n
Write
for i=1:n
for j=1:n
and then add an extra 'end' statement where appropriate.
  2 件のコメント
Walter Roberson
Walter Roberson 2015 年 6 月 18 日
k will never test equal to k+1 unless k is infinity.
The code was not "while k=k+1", it just looked like that because it was not formatted. Instead it had a 'while" with nothing else on the same line. That needs to be changed to something like
while true
That would create an infinite loop. Possibly along the way some test involving E (permissible error) is intended. The way to calculate the current error is not documented here, though, so no suggestions on that.
Nicholas Sullivan
Nicholas Sullivan 2015 年 6 月 19 日
Thanks for the correction. I wasn't paying attention.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by