난수, exponential, Binomial, Geometric, Poisson
- 최초 등록일
- 2012.12.16
- 최종 저작일
- 2009.09
- 30페이지/ MS 워드
- 가격 1,000원
소개글
확률과 랜덤변수 보고서 matlab code 포함
목차
없음
본문내용
<확률과랜덤변수>
Project 1
STEP1.
숫자를랜덤하게발생시켜랜덤변수를구성한다.
#include
#include
#include
#include
#include
#include
void main(){
int R=0, Z=0, i=0, T=0 , F=0;
float p=0;
srand(GetTickCount());
R = (rand() % 101) ;// 0~100 까지의난수발생
p = 0.2;
for( i=1 ; i<=100 ; i++ ){ // 0 or 1난수의발생개수
R = (rand() % 101) ;// 0~100 까지의난수발
if(R<=p*100) Z=1, T=T+1;
else Z = 0, F=F+1 ;
printf("%d", Z);
}
printf("\n성공%d \n", T);
printf("실패%d \n", F);
}
* 1~100 까지의난수를발생시켜서한번난수발생시마다주어진확률에대해난수를판단하여 0 or 1 의숫자를부여함. 이과정을원하는수만큼반복하여각각독립인확률 p를가진수행을반복하여몇번의 1(성공) 과몇번의 0(실패) 나오는지를알수있게코딩
STEP2.
Binomial
#include
#include
double Factorial(constdouble k){ // 팩토리얼함수야요
return (k <= 1) ? 1 : k * Factorial(k-1);
}
double BN(constdouble n, constdouble k, double p){ // 바이노미알식이야요;
//return Factorial(n) / (Factorial(k) * Factorial(n-k));
return (pow(p,k)*pow(1-p,n-k)*Factorial(n)) / ( Factorial(k) * Factorial(n-k) );
}
int main(){
int n=100, k=0 ;
double p =0.200;
참고 자료
없음