We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 5: Normal Distribution II
Day 5: Normal Distribution II
+ 0 comments import math as m def cdf(mn, std, x): return 1/2 * (1 + m.erf((x-mn)/(std*m.sqrt(2)))) print(f'{(1 - cdf(70,10,80))*100:.2f}') print(f'{(1 - cdf(70,10,60))*100:.2f}') print(f'{cdf(70,10,60)*100:.2f}')
+ 0 comments public class Solution { public static void main(String[] args) { double mean = 70; double stdDeviation = 10; double x1 = 80, x2 = 60; double result1 = 1 - probability(mean, stdDeviation, x1); double result3 = probability(mean, stdDeviation, x2); double result2 = 1 - result3; System.out.println(round(result1*100)); System.out.println(round(result2*100)); System.out.println(round(result3*100)); } public static double probability(double mean, double stdDeviation, double x) { final double z = calcZ(mean, stdDeviation, x); return 1 - (1 + erf(z)) / 2; } public static double calcZ(double mean, double stdDeviation, double x) { return (mean - x) / (stdDeviation * Math.sqrt(2)); } public static double erf(double z) { double sum = 0; for (int n = 0; n < 11; n++) { double sfsfsf = z / (2 * n + 1); for (int i = 1; i <= n; i++) sfsfsf *= -z * z / i; sum += sfsfsf; } return 2 / Math.sqrt(Math.PI) * sum; } static double round(double v) { return Math.round(v * 100)*1d/100; } }
+ 0 comments JS
function erf(x) { var a1 = 0.254829592; var a2 = -0.284496736; var a3 = 1.421413741; var a4 = -1.453152027; var a5 = 1.061405429; var p = 0.3275911; var sign = 1; if (x < 0) { sign = -1; } x = Math.abs(x); var t = 1.0 / (1.0 + p * x); var y = 1.0 - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * Math.exp(-x * x); return sign * y; } let value = input.split(/[ \n]/g); let h = 100 * (1 - (0.5 * (1 + erf((parseFloat(value[2]) - parseFloat(value[0])) / (parseFloat(value[1]) * Math.sqrt(2.0)))))); let m = 100 * (1 - (0.5 * (1 + erf((parseFloat(value[3]) - parseFloat(value[0])) / (parseFloat(value[1]) * Math.sqrt(2.0)))))); let l = 100 * (0.5 * (1 + erf((parseFloat(value[3]) - parseFloat(value[0])) / (parseFloat(value[1]) * Math.sqrt(2.0))))); console.log(h.toFixed(2)); console.log(m.toFixed(2)); console.log(l.toFixed(2));
+ 0 comments import math def cdf_(grades_, mu_, sigma_): probability_ = 0.5 * (1 + math.erf((grades_ - mu_)/(sigma_ * math.sqrt(2)))) return probability_ * 100 mean_, st_dev_ = map(float, input().split()) grade_pass = float(input()) grade_fail = float(input()) print(round(100 - cdf_(grade_pass, mean_, st_dev_), 2)) print(round(100 - cdf_(grade_fail, mean_, st_dev_), 2)) print(round(cdf_(grade_fail, mean_, st_dev_), 2))
+ 0 comments python3
import sys import math as m mu, sig = map(float, input().split()) g1 = float(input()) g2 = float(input()) z1 = (g1 - mu)/(sig*m.sqrt(2)) z2 = (g2 - mu)/(sig*m.sqrt(2)) print(round(100*(0.5 - 0.5*m.erf(z1)),2)) print(round(100*(0.5 - 0.5*m.erf(z2)),2)) print(round(100*(0.5 + 0.5*m.erf(z2)),2))
Load more conversations
Sort 84 Discussions, By:
Please Login in order to post a comment