0

I'm trying to plot $$p(n)=1-\sum_{i=0}^{\lfloor n/2 \rfloor}\frac{365!n!}{i!(365-n+i)!2^{i}(n-2i)!365^{n}}$$ over various positive integer values of $n$ in MATLAB, but it obviously has very large numbers in it deriving from the factorials leading me to rearrange it as $$1-\sum_{i=0}^{\lfloor n/2 \rfloor}\prod_{j=366-n+i}^{365} \,j \,\prod_{t=n-2i+1}^{n}t\,\frac{1}{i!2^{i}365^{n}} \enspace,$$ which is leading me to get numbers rather than just inf. My current script is below, but it currently still isn't giving me a correct plot. Is my rearrangement incorrect or is the code wrong and if so how do I fix it?

for n=1:100;
    i=0:floor(n/2);
    j=(366-n+i):365;
    t=(n-2.*i+1):n;
    tosum=prod(j) * prod(t) * (1)./(factorial(i) .* (2.^i) .* (365^n));
    p(n)=1-sum(tosum);
end
n=1:100;
plot(n,p)
EditPiAf
  • 20,898
Agnes
  • 195
  • $\lfloor n/2 \rfloor$ is obtained wit h\lfloor n/2 \rfloor. Could you proofread the line that assigns to tosum? – Fabio Somenzi Jan 28 '18 at 16:53
  • @FabioSomenzi thanks, I edited in the floor symbol and went back through the tosum line and added some spacing to ensure everything was shown properly. – Agnes Jan 29 '18 at 09:37
  • The semicolon at the end of the first line is unnecessary, but more importantly, what do you expect the third line to do? Note that i is a row vector, and the range (colon) operator expects scalar arguments. – Fabio Somenzi Jan 29 '18 at 18:08

0 Answers0