David, Thanks for the problem. I really liked it. However poissinv([0.05 0.95],10) formula produces [5 15]. In the definition lowerlimit = 4 and upperlimit = 15. The poissinv function systematically produces one unit below the lower limits reported in the test suite.
It should be : The poissinv function systematically produces one unit above the lower limits reported in the test suite.
Hello, Mehmet OZC. Thanks for your kind words and interesting observation. . . . From the documentation: "X = poissinv(P,lambda) returns the smallest value X such that the Poisson cdf evaluated at X equals or exceeds P" — i.e. the associated probably would be ≥ P. . . . This won't generally satisfy the requirement in the present problem statement: "not be faced more than 5% of the time" — i.e. the associated probably must be ≤ 5%. That accounts for the difference that you noticed. . . .
Thanks for your kind response. If you don't mind, I want to ask another question. When mu=10 first six cumulative probs are : [0.0 0.0 0.0 0.0103 0.0293 0.0671]. so cumulative prob for 5 isn't below 0.05. If I was not interested in the problem, I would not ask questions. I had to ask this one.
No problem: keep asking and we will all learn from it! . . . In "EXAMPLE 1" and the corresponding test in the Test Suite: mu = 10; lowerLimit = 4. For this lower limit the corresponding probability Pr(N≤4) satisfies my requirement that Pr(N≤k) ≤ 5%. That's why lowerLimit = 4 is the correct solution here. Indeed Pr(N≤0) et cetera would also satisfy that part of the requirement, but implicitly [sorry if it wasn't clear to everyone] the _largest_ value of k that satisfies Pr(N≤k) ≤ 5% is of most relevance. . . . As you noticed, Pr(N≤5) does not satisfy my requirement that Pr(N≤k) ≤ 5%. The "poissinv" function reports a value of k=5 because it instead finds the _smallest_ value of k that satisfies Pr(N≤k) ≥ 5% [note flipped inequality]. That is not consistent with the condition specified in the problem statement. . . . On the other hand, for the upper limit both the Test Suite and the "poissinv" function find the smallest value of k that satisfies Pr(N≤k) ≥ 95%. That's why there was no difference in results for upperLimit. . . . Of course, there is freedom to define other requirements in a different Cody problem. The requirements in this problem have a nice symmetry and consistency in never allowing the probability in either of the 'tails' to exceed 5%. On the other hand, the sum of the two 'tails' will typically be considerably less than 10% when using the values of lowerLimit and upperLimit specified here (e.g. only 7.8% for mu=10). For some purposes that might be seen as 'too conservative': choosing instead lowerLimit=5 would increase the sum of the two 'tails' to 11.6% — although it doesn't satisfy the strict requirements of the present problem, notice that it is closer to 10% (in this instance). . . . I hope that some of the above has addressed your question.
Neat solution using some additional mathematical knowledge.
Scoring for oriented dominoes
Square Digits Number Chain Terminal Value (Inspired by Project Euler Problem 92)
Test Driven Solution - Probability Problem 1
Make roundn function
Probability of red tulips (at both ends of a row)
Code breaker, Part III: Operation Xiangliu
Make your own Test Suite (part 2)
Make your own Test Suite (part 0)
Comparison of floating-point numbers (singles)
Curve fitting (linear functions) & function handles
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office