0
$\begingroup$

This is related to the answer (link) of my previous question. The code works great. I just don't know what is the purpose of the additional part 'psi[n]' and 'psi[n]' in the definition. Thanks in advance!

Clear[psi, phi]
psi[0] = Pi;
phi[0] = 0.1;

psi[n_] :=psi[n] = If[L < Mod[psi[n - 1] + 2*phi[n - 1], 2 Pi] < 2 Pi - L,psi[n - 1] + 2*phi[n - 1],psi2[psi[n - 1], phi[n - 1]]]
phi[n_] :=phi[n] = If[L < Mod[psi[n - 1] + 2*phi[n -1], 2 Pi] < 2 Pi - L,phi[n - 1], phi2[psi[n - 1], phi[n- 1]]]
$\endgroup$
3
  • 3
    $\begingroup$ It's called "memoization" and basically memorizes already calculated values, essentially using memory instead of computation. $\endgroup$ – bill s Nov 18 '20 at 1:42
  • 4
    $\begingroup$ See Functions That Remember Values They Have Found $\endgroup$ – Bob Hanlon Nov 18 '20 at 2:32
  • $\begingroup$ Thanks a lot for the explanation and the reference! $\endgroup$ – Pengfei Nov 18 '20 at 2:48