# Piecewise Recursive function with 2 arguments

The following code is not working for argument nn>1. Hold statement Hold[0.62+v0[1,0]] come as output for v0[2,0].

v0[0, 0] = 0.12; v0[nn_, ll_] = PiecewiseExpand[ Piecewise[{{v0[nn - 1, 0] + 0.02 ll (3 ll + 5) + 1/2,nn != 0 && ll != 0}, {v0[nn - 1, 0] + 1/2,nn != 0 && ll == 0}, {v0[0, 0] + 0.02 ll (3 ll + 5),nn == 0 && ll != 0}, {0.12, nn == 0 && ll == 0}}]]


I have to use this function as V0[nn,ll] further for example:

vl[x_] := -((4*as)/(3 x)) + (a*x^2) - v0[nn, ll]


• Welcome to Mathematica S.E. To start: 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, since the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) consider accepting the answer, if any, that solves your problem, by clicking checkmark sign, 4) give help too, by answering questions in your areas of expertise.
– bmf
Feb 3 at 11:19

The following

v0[0, 0] = 0.12;
v0[nn_, ll_] :=
PiecewiseExpand[
Piecewise[{{v0[nn - 1, 0] + 0.02 ll (3 ll + 5) + 1/2,
nn != 0 && ll != 0}, {v0[nn - 1, 0] + 1/2,
nn != 0 && ll == 0}, {v0[0, 0] + 0.02 ll (3 ll + 5),
nn == 0 && ll != 0}, {0.12, nn == 0 && ll == 0}}]]


works fine as you can see

Column@Table[v0[ii, ll], {ii, 1, 5}] // TableForm And also,

vl[x_, nn_ : 0, ll_ : 0] := -((4*as)/(3 x)) + (a*x^2) - v0[nn, ll]


runs without issues. Test it

vl[x]


returns Also, you can do

Column@Table[vl[x], {x, 2, 10}] And of course, you can change nn and ll to whatever you want

Column@Table[vl[2, xx, ll], {xx, 2, 10}] • The problem is after running the definition of v0[nn,ll] again, this gives me \$RecursionLimit problem. But, I guess I do not need to run it again. Thanks. Feb 3 at 12:00
• @kdteam1 please copy the code as i wrote it and try with a clean kernel. do a Quit[] and then run the code
– bmf
Feb 3 at 12:03