- #1

- 310

- 0

## Homework Statement

So, you're asked to write a function that computes the probability of two people at a party having the same birthday. The probability function itself is

P(n) = 0, n = 1

P(n) = 1 - (capital pi from k = 1 to k = n - 1)(1 - k/365), 2 <=n <= 365

P(n) = 1, n >= 366

The function is used to calculate the minimum value of m (your chosen n) for which P(m) >= q. Where q (0, 1], i.e. an arbitrary probability entered by the user. The function should accept q as an input and return m as an output.

## Homework Equations

## The Attempt at a Solution

Code:

```
function [m] = Prob(q)
m = 0;
P = 0;
while P < q
m = m + 1;
if m == 1
P = 0;
elseif m >= 2 && m <= 365
S = 1;
for k = 1: m - 1
S = S * (1 - k/365);
end
P = 1 - S;
else
P = 1;
end
end
```

Last edited by a moderator: