Question: How do I access the output of the for loop?

I use a for loop to step through the operands of an expression and do a calculation on each operand. I am then unable to add up or otherwise access for manipulation the result of the for loop and wondered how this could be done. What I mean is as follows. I have the expression w

w := 2*(1/2/Pi+Q*cos(k*phi))*Q*cos(k*phi)*(exp(-1/2*sigma^2*k^2)-1)*t*(1/2/Pi+Q*cos(k*psi))/(beta^2*(1+beta^2*(1/2/Pi+Q*cos(k*phi))^2))+(1/2/Pi+Q*cos(k*phi))^2*Q*cos(k*psi)*(exp(-1/2*sigma^2*k^2)-1)*t/(beta^2*(1+beta^2*(1/2/Pi+Q*cos(k*phi))^2))-2*(1/2/Pi+Q*cos(k*phi))^3*Q*cos(k*phi)*(exp(-1/2*sigma^2*k^2)-1)*t*(1/2/Pi+Q*cos(k*psi))/(1+beta^2*(1/2/Pi+Q*cos(k*phi))^2)^2;

 

 

from which I extract terms in phi and do a simple calculation (for example sake) on each term as follows

for z in w do

tot :=select(has,z,phi);r:=2*tot;

end do;

I now have three different values of r and now I wanted to add up the three different values of r. How do I do this? The number of operands in w will change and consequently so too the number of different values of r.

 

How do I access the output of the for-loop ?

Please Wait...