|
Nrep 값을 이용해서 for 문을 돌리신것 같은데 그 for문 안에서 처음 Nrep값이 0일때 Nrep값이 몫인 상태에서 나눗셈을 한번 하고 있네요.. 그게 문제입니다.
int Nrep; //number of replications
for (Nrep = 0; Nrep <= 200; Nrep++)
{
:
:
cout <<"Avg Estimated WIP is "<<EstWIP/Nrep<<" parts"<<endl;
cout <<"Avg Time an entity spends in system is "<<T/(EstWIP/Nrep)<<" minutes"<<endl;
double Mean = T/(EstWIP/Nrep);
Variance = EstVAR/Nrep;
}
위와 같은 구조에서 초기 Nrep값이 0일때 나눗셈을 한번 하고 있는 것입니다.
방황 님이 쓰신 글 :
: #include <iostream>
: #include <cmath>
: #include <ctime>
: #include <cstdlib>
:
: using namespace std;
:
: int main()
: {
:
: double EstWIP = 0; //estimated # of WIP in system
: double EstVAR = 0; //variance
: int Nrep; //number of replications
:
: for (Nrep = 0; Nrep <= 200; Nrep++)
: {
: int y;
: double sum =0;
: int D = 1000000000;
: int T = 0;
: int X = 0;
:
:
: srand((unsigned int)time(NULL));
: int A = rand()%5+4;
:
: for (T = 0; T<= 60; T)
: {
: if (D > A) // part arrives before departs
: {
: sum = sum + (A-T)*X; //total time(minutes) spend in system
: T = A; //arrival time is new simulation time
: X = X + 1;
: y = rand()%5+4; //interarrival time
: A = T + y; //next arrival time (update A)
:
: if (X == 1) //If only 1 part in the system
: {
: y = rand()%3+2;
: D = T + y; //next departure time (update D)
: }
:
: }
: else // part departs before arrives
: {
: sum = sum + (D-T)*X;
: T = D; //departure time is new simulatino time
: X = X-1;
: if (X > 0) //If more than 1 part in system
: {
: y = rand()%2+4;
: D = T + y; //next departure time (update D)
: }
: else //no part in system
: {
: D = 1000000000; //big number since no parts in the system
: }
: }
:
:
: EstWIP = EstWIP + sum/T;
: EstVAR = EstVAR + pow(EstWIP-sum, 2);
: cout <<"Estimate WIP is " <<EstWIP<<endl; //sometimes T is greater than 60 <---need to fix
: cout <<"Estimated VAR is " <<EstVAR<<endl;
:
: }
: cout <<"================================================================"<<endl;
: cout <<"Avg Estimated WIP is "<<EstWIP/Nrep<<" parts"<<endl;
: cout <<"Avg Time an entity spends in system is "<<T/(EstWIP/Nrep)<<" minutes"<<endl;
: double Mean = T/(EstWIP/Nrep);
: cout <<"Mean is " <<Mean<<endl;
: double Variance;
: double Sigma;
: Variance = EstVAR/Nrep;
: Sigma = sqrt (Variance);
: cout <<"Estimated Variance is "<<Variance<<endl;
: cout <<"Estimated Standard Deviation is "<<Sigma<<endl;
:
:
: }
: system("pause");
: return 0;
: }
:
: C++ 시작한지 얼마 안된 학생입니다.
:
: Sigma = sqrt (Variance); 에서 저는 단순히 Variance 값에 루트를 씌우려는건데 더 큰 숫자가 나와버립니다ㅠ.
:
: 예를들어 Variance 값이 1.64 얼마였으면 sqrt 한 값은 더 작아야하는데 4059. 얼마가 나와버립니다. 제가 뭘 놓치고 있는걸까요?
:
:
|