-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparcial2.py
More file actions
35 lines (31 loc) · 809 Bytes
/
Copy pathparcial2.py
File metadata and controls
35 lines (31 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from random import random
from math import e, factorial, sqrt, pi, exp, log
def exponencial(lamb, U=None):
U = random() if U is None else U
return -log(U)/lamb
def noHomo(T, lambf, lambc, lenlimit=None):
t = 0
S = []
while True:
t += exponencial(lambc)
if t > T:
break
V = random()
if V < lambf(t)/lambc:
S.append(t)
if lenlimit and len(S) == lenlimit:
break
return S
def ej4(U=None):
"""
X=F^-1(U) tiene distribucion f(x) para U~U[0,1]
F(x) = int from -inf to x f(x)
"""
U = random() if U is None else U
if U < 1/2:
return sqrt(2)*sqrt(U)
else:
return -sqrt(2-2*U)+2
def ej2():
"""retorno lista de tiempos de llegada"""
return noHomo(8, lambda x: x, 8)