Effacer les filtres
Effacer les filtres

error in while loop

1 vue (au cours des 30 derniers jours)
Piyanut Nanta
Piyanut Nanta le 17 Juin 2015
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

Réponses (1)

Nicholas Sullivan
Nicholas Sullivan le 17 Juin 2015
Modifié(e) : Nicholas Sullivan le 19 Juin 2015
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 commentaires
Walter Roberson
Walter Roberson le 18 Juin 2015
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 le 19 Juin 2015
Thanks for the correction. I wasn't paying attention.

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB 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