I have an implicit function


which I want to call recursively, called initially with g=0. I have this working for a specified number of recursive calls rec.

h[x_, y_, z_, rec_] := Piecewise[{{f[x, y, z, 0], 
 rec == 0}}, f[x, y, z, h[x, y, z, rec-1];

Is there a neat way build a function keeps increasing rec until the change in h falls below a certain threshold?


  • 2
    $\begingroup$ Maybe FixedPoint would help. $\endgroup$
    – bill s
    Apr 23 '18 at 2:59
  • $\begingroup$ Perhaps NestWhile would be relevant $\endgroup$
    – user42582
    Apr 23 '18 at 6:02

Ah, I think I have my own answer, thanks to more reading...

h[x_, y_, z_] := Last[NestWhileList[f[x, y, z, #] &, 0, Abs[#1 - #2]/#2 > 0.01&, 2]] 

finds the answer with enough recursion for 1% accuracy.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.