Day 4: Normal Distribution #1

  • + 0 comments

    So everyone publishes his code??
    Now here is mine (wasn't aware of , what a pity).

    import math
    # ouch, no scipy 
    
    density = lambda t: math.exp(-t*t/2) / math.sqrt(2*math.pi) 
    # note acuracy of math.pi 8 digits: maybe better define own
    
    def phi(t):
        tabs = abs(t)
        delta, eps = 0.001, 1e-6
        s = 0
        while ...:
            d = delta * density(tabs)
            s += d
            tabs += delta
            if d < eps: break
        return s if t <= 0 else 1-s
    
    normalize = lambda mu, sigma: lambda t: (t-mu) / sigma
    
    # main
    
    n = normalize(30, 4)
    
    print(phi(n(40)))
    print(1-phi(n(21)))
    print(phi(n(35)) - phi(n(30)))