I have the following code.
n = 0;
For[iii = 0, iii < Nn, iii++,
z = -L + iii*h;
While[
n < Nn - 1,
xn = -L + h*n;
result = result + func[z,xn];
n++;
]
(* Store (z, result *)
result = 0;
n = 0;
]
The function func is predefined and the constants Nn, h, L as well. My question is: how do I store the results obtained in the loop in a list? I would like to do this at the point where I commented "(* Store (z, result) )*". Ultimately I would like to use this list to make a listplot.
I have looked at previous questions where the answers almost always say that one should use 'reap' and 'saw', but I don't see how one should use this here, as I explicitly need to put result back to zero after each step
Sow[result];result=0
of course usingTable
instead ofFor
would be far better. $\endgroup$ – george2079 Feb 18 '15 at 13:20Table[result=0;While[];result,{iii,Nn}]
$\endgroup$ – george2079 Feb 18 '15 at 14:54