loop troubles in Maple

by elarson89
Tags: loop, maple, troubles
elarson89 is offline
Apr18-09, 11:13 PM
P: 20
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
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[i]

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;
Phys.Org News Partner Science news on Phys.org
Simplicity is key to co-operative robots
Chemical vapor deposition used to grow atomic layer materials on top of each other
Earliest ancestor of land herbivores discovered

Register to reply

Related Discussions
[SOLVED] Riding a Loop the Loop (velocity at the bottom of the loop) Introductory Physics Homework 13
Calculating normal force in a loop-the-loop situation Introductory Physics Homework 2
Matlab, for loop troubles. Math & Science Software 10
Loop Impedance Meaning...Data Logger Troubles Electrical Engineering 7
Maple Download and Maple-Matlab Math & Science Software 9