MatLab Inputs: 1. (double) The number of apples 2. (double) The number of orange
ID: 2247299 • Letter: M
Question
MatLab
Inputs:
1. (double) The number of apples
2. (double) The number of oranges
3. (double) The number of good apples
4. (double) The number of good oranges
Outputs:
1. (double) The probability of randomly picking a bad apple
2. (double) The probability of randomly picking a bad orange
Function Description:
This function should calculate the probability of randomly picking a bad apple or bad
orange from a bag. The total number of apples and oranges will be given in the first two inputs
and the number of good apples and good oranges will be given as the third and fourth inputs.
The output value should be expressed as a percentage, not a decimal. So if there was a 25%
chance of drawing a bad apple, this would be expressed as the integer 25 rather than the
decimal 0.25. Round all percentages to the nearest hundredth of a percent.
Notes:
The number of good apples/oranges will always be less than or equal to the number of
apples/oranges.
Explanation / Answer
when you pick objects simultaneously, it's the same as picking them one at a time, without replacement - so that's the easiest way to attack the question.
There are two outcomes that make us happy:
bad then good; and
good then bad.
Since we want EITHER outcome, we ADD the probabilities.
Bad then good = 1/5 * 4/4 = 4/20 = 1/5
Good then bad = 4/5 * 1/4 = 4/20 = 1/5
adding them together we get 2/5 as the final answer.
* * *
A second method would be to use the "1 minus" approach:
Prob(what you want) = 1 - prob(what you don't want)
Here, we don't want two good in a row, so:
Prob(good, good) = 4/5 * 3/4 = 12/20 = 3/5
prob(not good,good) = 1 - 3/5 = 2/5
* * *
A third method (and my personal favourite) is logic; if there's one bad apple in the bowl out of 5 apples in total, and if we're pulling x apples, there will always be an x/5 chance of getting the bad one:
1 pull, 1/5 shot;
2 pulls, 2/5 shot;
3 pulls, 3/5 shot;
4 pulls, 4/5 shot; and
5 pulls, sure thing!