C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[70141] Re:sqrt 를 쓰는데 값이 오히려 커져요.
김시환 [godson2] 2366 읽음    2013-09-20 18:08
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. 얼마가 나와버립니다. 제가 뭘 놓치고 있는걸까요?
:
:

+ -

관련 글 리스트
70139 sqrt 를 쓰는데 값이 오히려 커져요. 방황 5920 2013/09/19
70141     Re:sqrt 를 쓰는데 값이 오히려 커져요. 김시환 2366 2013/09/20
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.