1
$\begingroup$

With the function

P[n_] :=  Module[{s,t} , 
    s = Sum[z^k/k!, {k, 0,Infinity}];
    t = Series[s^x, {z, 0, n+1}];
    f[x_] = n!^2 Coefficient[t, z, n]
]

I get for

Map[P[3], {0, 1}]

{(6 x^3)[0],(6 x^3)[1]}

What I want is {0, 6}, the x evaluated at {0,1}. How to do it right?

$\endgroup$
2
$\begingroup$

In at least this case, you might consider using SeriesCoefficient[] instead:

P[n_Integer?NonNegative] := Block[{x, z},
  Function[x, n!^2 SeriesCoefficient[Exp[z]^x, {z, 0, n}] // Evaluate]]

P[3] /@ {0, 1}
   {0, 6}
$\endgroup$
3
$\begingroup$

Something like:

P[n_]:=Module[{s,t},
    s=Sum[z^k/k!,{k,0,Infinity}];
    t=Series[s^x,{z,0,n+1}];
    Function@@{x,n!^2 Coefficient[t,z,n]}
]

P[3] /@ {0, 1}

{0, 6}

$\endgroup$
  • $\begingroup$ It's probably worth mentioning that the f=... isn't needed. $\endgroup$ – jjc385 May 29 '17 at 18:15
  • $\begingroup$ Thanks. But how to do it with Map[]? $\endgroup$ – Sophia Antipolis May 29 '17 at 18:17
  • $\begingroup$ P[3] /@ {0, 1} and Map[P[3], {0, 1}] are syntactically equivalent. $\endgroup$ – Carl Woll May 29 '17 at 18:20
1
$\begingroup$

I would probably use Carl Woll's answer. However, the following approach might be more intuitive to a new user.

You could allow P[n] to take an argument x :

ClearAll[P]    
P[n_][x_] := Module[{s, t}, 
  s = Sum[z^k/k!, {k, 0, Infinity}];
  t = Series[s^x, {z, 0, n + 1}];
  n!^2 Coefficient[t, x, n]
   ]

Then:

Map[ P[3], {0,1} ]
{0, 6}

Note that the Module will re-evaluate for each different x call. Avoiding this is possible (as Carl Woll does), but the syntax gets a bit more messy.

$\endgroup$

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.