In [4]:
def funcc(x,xo,g):
pr=[]
pi=[]
pr=gen(x)
for i in range(x):
pi.append(xo+g*math.tan(math.pi*(pr[i]-(1/2))))
return pi
fcc=funcc(x,0,1)
for i in range(len(fcc)):
print "{0:.2f}".format(fcc[i])
In [5]:
lambda_=1
def funexp(l,x):
lmda=[]
for i in range(x):
lmda.append(l*math.exp(-l*i))
return lmda
fprobe=funexp(lambda_,x)
def funcexp(x,l):
p=[]
pi=[]
p=gen(x)
for i in range(x):
pi.append(-math.log10(1-p[i])/l)
return pi
fcue=funcuanexp(x,lambda_)
for i in range(len(fcue)):
print "{0:.2f}".format(fcue[i])
In [7]:
%matplotlib inline
import matplotlib.pyplot as plt
from scipy.integrate import quad
import math
import numpy as np
import scipy as sp
x=10
s1=17
s2=27
def gen(x):
x0=x*10
x0=((75*x0))%((2**16)+1)
Ux=float(x0)/((2**16)+1)
return Ux
def gena(N):
Ux=[]
x=0
x0=7
while x<N:
x0=((5*x0)+3)%607
x=x+1
Ux.append(float(x0)/607)
return Ux
p=gen(s1)
#funcion de probabilidad binomial
def funpb(x,p):
y=[]
for i in range(x):
y.append((math.factorial(x)/(math.factorial(i)*math.factorial(x-i)))*(p**i)*(1-p)**(x-i))
return y
fpb=funpb(x,p)
#funcion acumulada binomial
def funab():
y=[]
y.append(fpb[0])
for i in range(x-1):
y.append(fpb[i+1]+y[i])
return y
fab=funab()
plt.plot(fab)
Out[7]:
In [8]:
#funcion inversa binomial
def fib(x):
p=[]
p=gena(x)
pi=[]
for i in range(x):
for j in range(len(fab)):
if p[i]<fab[j]:
pi.append(j)
break
return pi
finb=fib(x)
print finb
In [11]:
p=gen(s2)
def funpg(x,p):
y=[]
for i in range(x+1):
y.append(p*(1-p)**(i))
return y
fpg=funpg(x,p)
def funag():
y=[]
y.append(fpg[0])
for i in range(x-1):
y.append(fpg[i+1]+y[i])
return y
fag=funag()
plt.plot(fag)
Out[11]:
In [12]:
#funcion inversa binomial
def fig(x):
p=[]
p=gena(x)
pi=[]
for i in range(x):
for j in range(len(fag)):
if p[i]<fag[j]:
pi.append(j)
break
return pi
fing=fig(x)
print fing
In [13]:
#Funcion de probabilidad Uniforme Discreta
def funpun(x):
fpu=[]
for i in range(x):
fpu.append(1/float(x))
return fpu
fpu=funpun(x)
def funaun(x):
facu=[]
facu.append(fpu[0])
for i in range(x-1):
facu.append(fpu[i+1]+facu[i])
return facu
facu=funaun(x)
plt.plot(facu)
Out[13]:
In [14]:
#funcion inversa Uniforme
def fiun(x):
p=[]
p=gena(x)
pi=[]
for i in range(x):
for j in range(len(facu)):
if p[i]<facu[j]:
pi.append(j)
break
return pi
fing=fiun(x)
print fing
In [ ]: