Why do I get this error for my gauss seidel code?

2 Ansichten (letzte 30 Tage)
Peter Phung
Peter Phung am 6 Nov. 2017
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?

Antworten (1)

David Goodmanson
David Goodmanson am 6 Nov. 2017
Hello Peter, try
if sentinel == 1 && x(i) ~= 0
instead of
if sentinel = 1 && x(i) ~= 0

Kategorien

Mehr zu Debugging and Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by