Feb 17, 2014 at 2:31pm UTC
Hi,
I'm currently having a few problems with the following code. My knowledge of coding is pretty limited so I'm not sure what to do.
The program below runs two loops to calculate P. The current problem I am having is
The main problem is that, when N goes to values of ~30,000, Z becomes very very large and keeps giving Infinity as an answer, I think anyways.
Any help would be greatly appreciated even if it just hints how to get around this exponential. As a novice I'm using Quincy as a compiler.
Thanks Again.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
long double T, X, Y, Z;
double N, n, P, q, S;
N = 100; //Number of Bins
S = 0.24723;
Y = N*((1 + S) / (1 + 0.27));
Z = 0;
for (q=1;q<=N;q++){
X = 1;
for (n=1;n<=N-q;n++){
X*=Y/n;
}
Z+=X;
}
P = exp (-Y + log(Z));
cout << P;
return 0;
}
* As a note this is part of a bigger program *
Last edited on Feb 17, 2014 at 5:19pm UTC
Feb 17, 2014 at 3:49pm UTC
I ran it and it prints 0.558427. Is it expected to crash?
Feb 17, 2014 at 3:56pm UTC
The current program works for values of N up to several thousand. However, N will eventually range from say 2000 to 200,000 which becomes problematic at the higher N.
(Thanks for looking into this as well).
Last edited on Feb 17, 2014 at 3:56pm UTC