Yiffany
Yiffany

Reputation: 352

Sympy can not plot float probability with factorial

This is the raw code, and I want to plot some probability functions. But it does not work, anyone knows what's going wrong?

Thank you guys!!!

from sympy import *
import numpy as np
from sympy.plotting import plot

init_printing()

def f(x):
    return (factorial(365) / factorial(365 - x )).evalf() / (365**x)

display(f(5))
x = symbols('x')
plot(f(x),(x,0,100),ylim=[0,2])

Result I got

0.972864426300206 
      1 |                                                       
        |                                                       
        |                                                       
        |                                                       
        |                                                       
        |                                                       
        |                                                       
        |                                                       
        |                                                       
        |                                                       
      0 |-------------------------------------------------------
        |                                                       
        |                                                       
        |                                                       
        |                                                       
        |                                                       
        |                                                       
        |                                                       
        |                                                       
        |                                                       
     -1 |_______________________________________________________
         0                          50                         100

Upvotes: 0

Views: 89

Answers (1)

smichr
smichr

Reputation: 19135

With

>>> plot((factorial(365) / factorial(365 - x ))/ (365**x),(x,0,100))

I get enter image description here

Evaluation with the factorial doesn't seem to work, but using rf or ff does:

def f(x):
    return (ff(365, x)/(365**x)).n(3)

plot(f(x), (x, 0, 2))

enter image description here

Upvotes: 2

Related Questions