Добавил:
okley
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Моделирование процессов в физике частиц (7 сем) / prog1
.cpp#include <iostream>
#include <math.h>
#include <time.h>
#include "hist.hpp"
using namespace std;
// This function generates basic random
double gamma(){
return (rand()+0.5)/(RAND_MAX+1.0);
}
// simulate discrete distributions
int main(){
double ksi; // random value
int x[]={ 2, 0, 1, 3};
double px[]={ 3./8., 1./3., 1./6., 1./8.};
int k; // random integer
srand(time(NULL)); // initialize the random generator
// discrete random from array
int num_bin = 4;
Hist *hist = new Hist(-0.5, num_bin - 0.5, num_bin);
for( int i=0; i<2400000; i++ ){
// *****************************************************************
ksi = gamma();
k = 0;
while (ksi > 0){
ksi -= px[k];
k++;
}
// *****************************************************************
hist->fill(x[k-1]); // fill histogramm
}
for(int i=0; i<hist->get_num_bin(); i++){
cout << hist->get_bin(i) << "\t"; // get middle of bin boundary
cout << hist->get_bin_value(i) << "\n"; // get number of counts in the bin
}
hist->draw(60); // draw histogramm
delete hist; // destroy histogramm
}
Соседние файлы в папке Моделирование процессов в физике частиц (7 сем)
