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 - The Fusion of Science and Community**

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

# Loop troubles in Maple

Can you offer guidance or do you also need help?

Draft saved
Draft deleted

Loading...

Similar Threads - Loop troubles Maple | Date |
---|---|

Mathematica While Loop in Mathematica | Feb 25, 2018 |

Mathematica For looping problem not getting answer | May 24, 2017 |

Mathematica If statement inside a Do loop | Apr 9, 2017 |

Matlab Arduino-MATLAB communication using SerialEvent() for PID Loop | Oct 28, 2016 |

Matlab, for loop troubles. | Feb 21, 2008 |

**Physics Forums - The Fusion of Science and Community**