# Maple Loop troubles in Maple

#### elarson89

I am trying to write a Gauss Seidel iteration for maple, but my troubles are because of a nested for loop.

What i want to do is like this,
function := proc(....)
for ....... do
for ....... do
(computations)
end do;
(if something > something, then return solution);
end do;

return solution;
end proc;

the statment if something > something is giving me troubles. Even if i don't include a return statement i get the error. It seems like I'm not allowed to put anything in between the end do's.
What am i doing wrong and how can i fix this?

My exact code is this:

with (linalg);

gauss_seidel := proc (A, B, x_0, eps, N) local i, j, k, m, n, x, sol;

n := coldim(A);
for i from 1 to n do
x[i,1] := x_0
od;

for m from 1 to N do
for j from 1 to n do

x[j,m+1] := 1/A[j,j] * ( B[j] - sum(A[j,k]*x[k,m+1] , k=1..(j-1)) - sum( A[j,k]*x[k,m], k=(j+1)..n))

end do;
if abs( max( [seq(x[i,m+1], i=1..n)] - [seq(x[i,m], i=1..n)])) < eps then return (<seq(x[i,m+1], i=1..n)>);

end do;

return <seq(x[i,N+1], i=1..n)>;
end proc;

Last edited:
Related Math Software Workshop News on Phys.org

### Want to reply to this thread?

"Loop troubles in Maple"

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving