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

2 views (last 30 days)
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?

Answers (1)

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

Categories

Find more on Debugging and Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!