Sort by

recency

|

136 Discussions

|

  • + 0 comments

    python sol

    import statistics
    
    mean = 20
    sd = 2
    
    x1 = 19.5
    x2_a = 20
    x2_b = 22
    
    nd = statistics.NormalDist(mean, sd)
    
    print(round(nd.cdf(x1), 3))
    print(round(nd.cdf(x2_b)-nd.cdf(x2_a), 3))
    
  • + 0 comments
    import math as m
    
    def ND(x,mean,sd):
    z = (x-mean)/(2*m.sqrt(2))
    cdf = 0.5*(1 + m.erf(z))
    return cdf 
    
    print(f"{ND(19.5,20,2):.4f}")
    p1 = ND(20,20,2)
    p2 = ND(22,20,2)
    print(f"{p2-p1:.4f}")
    
  • + 0 comments
    import math
    
    mu = 20
    sigma = 2
    
    x_1 = 19.5 
    
    x_2_a = 20
    x_2_b = 22
    
    # P(X <= x) = 0.5 * (1+math.erf((x - mu)/(sigma * 2**0.5)))
    p_less_than_19_5 = 0.5 * (1+math.erf((x_1 - mu)/(sigma * 2**0.5)))
    
    print(round(p_less_than_19_5,3))
    
    # (a <= X <= b) = F(b) - F(a)
    p_between_20_and_22 = 0.5 * (1+math.erf((x_2_b - mu)/(sigma * 2**0.5))) - 0.5 * (1+math.erf((x_2_a - mu)/(sigma * 2**0.5)))
    
    print(round(p_between_20_and_22, 3))
    
  • + 0 comments

    in R Could be:

    stdin <- file('stdin')
    open(stdin)
    
    stats <- as.numeric(strsplit(trimws(readLines(stdin, n = 1, warn = FALSE), which = "right"), " ")[[1]])
    less <- as.numeric(trimws(readLines(stdin, n = 1, warn = FALSE), which = "both"))
    between <- as.numeric(strsplit(trimws(readLines(stdin, n = 1, warn = FALSE), which = "right"), " ")[[1]])
    mean <- stats[1]
    sd <- stats[2]
    cat(round(1 - pnorm(less, mean, sd, FALSE),3), fill=TRUE)
    cat(round(pnorm(between[2], mean, sd, TRUE) - pnorm(between[1], mean, sd, TRUE),3), fill=TRUE)
    
  • + 0 comments
    import math as m
    def cdf(mn, std, x):
        return 0.5 * (1 + m.erf((x-mn)/(std*m.sqrt(2))))
        
    print(f'{cdf(20,2,19.5):.3f}')
    print(f'{cdf(20,2,22) - cdf(20,2,20):.3f}')