Created
September 12, 2018 02:46
-
-
Save EvanMu96/9d653d05104c8f8634a14a5f5f98d283 to your computer and use it in GitHub Desktop.
Programming: Homework at page 122
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#= | |
This is a program to simulate Homework @probability.pdf page 122 | |
Author: Evan MU | |
=# | |
# source type A | |
rate_A = 10 | |
num_A = 20 | |
prob_A = 0.1 | |
# 1-prob_A is idle probability of source type A | |
# source type B | |
rate_B = 1 | |
num_B = 80 | |
prob_B = 0.05 | |
# 1-prob_B is idle probability of source type B | |
# calculate Expectation of each source | |
Exp_A = rate_A * prob_A | |
Exp_B = rate_B * prob_B | |
# calculate Variance of each source | |
Var_A = (rate_A^2)*prob_A*(1-prob_A) | |
Var_B = (rate_B^2)*prob_B*(1-prob_B) | |
Exp_total = num_A*Exp_A + num_B*Exp_B | |
Var_total = num_A*Var_A + num_B*Var_B | |
R_total = num_A*rate_A+num_B*rate_B | |
Copt = min(R_total, Exp_total+3*sqrt(Var_total)) | |
output = "The answer is $(Copt)" | |
println(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment