Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Funkcja wczytująca dane
- void load_data(vector<double>& vec1, vector<double>& vec2, vector<double>& vec3)
- {
- ifstream ifile;
- ifile.open("losowe1.dat");
- double val;
- while(ifile >> val)
- {
- vec1.push_back(val / 97.0);
- }
- ifile.close();
- ifile.open("losowe2.dat");
- while(ifile >> val)
- {
- vec2.push_back(val / 32363.0);
- }
- ifile.close();
- ifile.open("losowe3.dat");
- while(ifile >> val)
- {
- vec3.push_back(val / 147483647.0);
- }
- ifile.close();
- }
- // Główna funkcja wykonująca zadanie
- void zad6()
- {
- const int N = 1000000;
- const double xmin = 0, xmax = 1;
- // Wczytanie danych
- vector<double> data1, data2, data3;
- load_data(data1, data2, data3);
- // Stworzenie, wypełnienie i narysowanie histogramów
- TH2D *h_corr1 = new TH2D("h_corr1", "Correlation (m=97, g=23)", 100, xmin, xmax, 100, 0, 1);
- TH2D *h_corr2 = new TH2D("h_corr2", "Correlation (m=32363, g=157)", 100, xmin, xmax, 100, 0, 1);
- TH2D *h_corr3 = new TH2D("h_corr3", "Correlation (m=147483647, g=16807)", 100, xmin, xmax, 100, 0, 1);
- for (int i = 0; i < N - 1; i++)
- {
- h_corr1->Fill(data1[i], data1[i+1]);
- h_corr2->Fill(data2[i], data2[i+1]);
- h_corr3->Fill(data3[i], data3[i+1]);
- }
- TCanvas* c1 = new TCanvas("c1", "c1", 1200, 600);
- c1->Divide(4, 2);
- c1->cd(1);
- h_corr1->GetXaxis()->SetTitle("x_{n}");
- h_corr1->GetYaxis()->SetTitle("x_{n+1}");
- h_corr1->Draw("COLZ");
- c1->cd(2);
- h_corr2->GetXaxis()->SetTitle("x_{n}");
- h_corr2->GetYaxis()->SetTitle("x_{n+1}");
- h_corr2->Draw("COLZ");
- c1->cd(3);
- h_corr3->GetXaxis()->SetTitle("x_{n}");
- h_corr3->GetYaxis()->SetTitle("x_{n+1}");
- h_corr3->Draw("COLZ");
- TH1D *h_uniform1 = new TH1D("h_uniform1", "Uniform (m=97, g=23)", 100, 0, 1);
- TH1D *h_uniform2 = new TH1D("h_uniform2", "Uniform (m=32363, g=157)", 100, 0, 1);
- TH1D *h_uniform3 = new TH1D("h_uniform3", "Uniform (m=147483647, g=16807)", 100, 0, 1);
- for (int i = 0; i < N; i++)
- {
- h_uniform1->Fill(data1[i]);
- h_uniform2->Fill(data2[i]);
- h_uniform3->Fill(data3[i]);
- }
- c1->cd(5);
- h_uniform1->GetXaxis()->SetTitle("x");
- h_uniform1->Draw();
- c1->cd(6);
- h_uniform2->GetXaxis()->SetTitle("x");
- h_uniform2->Draw();
- c1->cd(7);
- h_uniform3->GetXaxis()->SetTitle("x");
- h_uniform3->Draw();
- // Stworzenie zadanej funkcji na dwa sposoby
- TF1 *function = new TF1("f(x)", "0.5*exp(-x/2)", 0, 10);
- TH1D *transformed= new TH1D("transformed", "Distribution", 100, 0, 8);
- for (int i = 0; i < N; i++)
- {
- transformed->Fill((-2.0 * log(1.0 - data3[i])));
- }
- TH1D *transformed2= new TH1D("transformed2", "Distribution", 100, 0, 8);
- for (int i = 0; i < N; i++)
- {
- transformed2->Fill(-2.0 * log(1.0 - gRandom->Uniform(1.0)));
- }
- c1->cd(4);
- function->Draw();
- transformed->Scale(12.5/1000000);
- transformed->Draw("SAME");
- c1->cd(8);
- function->Draw();
- transformed2->Scale(12.5/1000000);
- transformed2->Draw("SAME");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement