I am working on the following code:
f[1] = Cos[t];
f[2] = Sin[t];
f[3] = 1.2 Cos[1.2 Pi t];
f[4] = 1.2 Sin[1.2 Pi t];
f[5] = 1.7 Cos[1.7 Pi t];
f[6] = 1.7 Sin[1.7 Pi t];
u = 0;
s = 0.1;
o[n_] := (o[n] = Table[{f[2 n - 1], f[2 n]}, {t, 0, 2 Pi, s }]; u++)
o[1];
o[2];
o[3];
u
If I run it, it outputs $u=3$ correctly. But if I run it again, it outputs $u=0$. What is going on here? I understand that $u$ is defined as $0$ in the beginning of the code, but shouldn't re-running it increment $u$ three times again and $u$ should be $3$?
How can I force $u$ to be incremented when calling o[1] after o[1] has been defined? I know I could use $\text{Clear["Global`*"]}$ in the beginning of the code, but it would be nice to use the memoization in there too.
o[1],o[2],o[3]is different after memoization. You can check with? oorDownvalues[o]. – Michael E2 Dec 05 '21 at 20:44o[i]it to increment everytime, even when it is declared? I am tryingo[n_] := (o[n] = (u++; Table[{f[2 n - 1], f[2 n]}, {t, 0, 2 Pi, s }]))but this is also not working. – Red Banana Dec 05 '21 at 20:53o[i]and at the same time forceuto be incremented whenevero[i]is called?" (Unless I've misunderstood what your question is.) – Michael E2 Dec 05 '21 at 21:02