Why the code gives an error?

2 ビュー (過去 30 日間)
Caped Crusader
Caped Crusader 2013 年 3 月 7 日
Hi I am getting the following error in the code shown below:
function[X] = gauss_seidel(A,b)
N = length(b);
X = zeros(N,1);
err = 1;
while err>0.001
for i =1:1:N
sum = 0;
for j = 1:1:N
if j~=i
sum = sum+A(i,j)*X(j,1);
end
end
X(i,1) = (b(i,1)-sum)/A(i,i);
end
Z = A*X-b;
d = sum(Z);
err = abs(d);
end
and the error is:
>> gauss_seidel(A,b)
??? Subscript indices must either be real positive integers or logicals.
Error in ==> gauss_seidel at 16
d = sum(Z);
I don't know why this error is happening here.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 7 日
編集済み: Azzi Abdelmalek 2013 年 3 月 7 日
You are using sum as a variable, and as a function in
sum = sum+A(i,j)*X(j,1);
d = sum(Z);
  1 件のコメント
Caped Crusader
Caped Crusader 2013 年 3 月 7 日
Thanks, I failed to notice it.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCustomize Object Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by