Why do I get this error for my gauss seidel code?
2 ビュー (過去 30 日間)
古いコメントを表示
a = [3 -.1 -.2; .1 7 -.3; .3 -.2 10];
b = [7.85; -19.3; 71.4];
x = [0;0;0];
imax = 10;
es = 1e-6;
lambda = 0.5;
n = 3;
for i = 1:n
dummy = (a(i,i))
for j = 1:n
a(i,j) = a(i,j)/dummy
end
b(i) = b(i)/dummy
end
for i = 1:n
sum = b(i)
for j = 1:n
if i ~=j
sum = sum - (a(i,j)*x(j))
end
x(i) = sum
end
iter = 1;
while (1)
sentinel = 1;
for i = 1:n
old = x(i)
sum = b(i)
for j = 1:n
if i~= j
sum = sum - a(i,j)*x(j)
end
x(i) = lambda*sum+(1-lambda)*old
if sentinel = 1 && x(i) ~= 0
ea = abs((x(i)-old)/x(i))*100
if ea > es
sentinel = 0;
end
end
iter = iter + 1;
if sentinel = 1 | iter >= imax
break
end
end
end
The error I keep receiving is:
>> gaussseidel
Error: File: gaussseidel.m Line: 35 Column: 25
The expression to the left of the equals sign is not a valid target for an assignment.
Why is this?
0 件のコメント
回答 (1 件)
David Goodmanson
2017 年 11 月 6 日
Hello Peter, try
if sentinel == 1 && x(i) ~= 0
instead of
if sentinel = 1 && x(i) ~= 0
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Debugging and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!