4
$\begingroup$

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]

I don't know if this requires some loop. Please help. This is my first question here.

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – bmf
    Feb 3 at 11:19

1 Answer 1

3
$\begingroup$

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

col

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

res2

Also, you can do

Column@Table[vl[x], {x, 2, 10}]

c2

And of course, you can change nn and ll to whatever you want

Column@Table[vl[2, xx, ll], {xx, 2, 10}]

cf

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$
    – kdteam1
    Feb 3 at 12:00
  • 1
    $\begingroup$ @kdteam1 please copy the code as i wrote it and try with a clean kernel. do a Quit[] and then run the code $\endgroup$
    – bmf
    Feb 3 at 12:03

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.