I am trying to write a Gauss Seidel iteration for maple, but my troubles are because of a nested for loop.(adsbygoogle = window.adsbygoogle || []).push({});

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;

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Maple Loop troubles in Maple

Can you offer guidance or do you also need help?

Draft saved
Draft deleted

**Physics Forums | Science Articles, Homework Help, Discussion**