How do I define the following function in Sage and compute some values?

The function is $$P(n) = \sqrt{\frac{e^{-h}h^n}{n!}},$$

where $h$ is a real variable and $n$ is a nonnegative integer. I want to see the values of $P(n)$ for $h = 20$ from $n = 0$ to $n = 50$.

After this, I would like to use the function in other formulas such as $$A(n,t) = P(n)\cos(t\sqrt(n+1))\cos(\theta) - iP(n+1)$$

So, if you help me out with computing $P(n),$ I think I will be able to do the rest. Thank you!

  • $\begingroup$ I think I just did it. All I needed to do was print in the command box the following code: "P(n) = sqrt(((exp(-h))*h^n)/(factorial(n)))" $\endgroup$ Jul 24, 2013 at 19:13
  • $\begingroup$ For questions about Sage syntax, the Q&A site ask.sagemath.org is usually a better choice. $\endgroup$
    – 40 votes
    Jul 24, 2013 at 22:25

1 Answer 1

sage: var('h')
sage: P(n) = sqrt(e^-h * h^n/factorial(n))
sage: points((n,P(n).subs(h=20)) for n in [0..50])

enter image description here


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .