Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.13 KB | None | 0 0
  1. //Funkcja wczytująca dane
  2. void load_data(vector<double>& vec1, vector<double>& vec2, vector<double>& vec3)
  3. {
  4.     ifstream ifile;
  5.     ifile.open("losowe1.dat");
  6.     double val;
  7.     while(ifile >> val)
  8.     {
  9.         vec1.push_back(val / 97.0);
  10.     }
  11.     ifile.close();
  12.     ifile.open("losowe2.dat");
  13.     while(ifile >> val)
  14.     {
  15.         vec2.push_back(val / 32363.0);
  16.     }
  17.     ifile.close();
  18.     ifile.open("losowe3.dat");
  19.     while(ifile >> val)
  20.     {
  21.         vec3.push_back(val / 147483647.0);
  22.     }
  23.     ifile.close();
  24. }
  25.  
  26.  
  27.  
  28. // Główna funkcja wykonująca zadanie
  29. void zad6()
  30. {
  31.     const int N = 1000000;
  32.     const double xmin = 0, xmax = 1;
  33.  
  34.     // Wczytanie danych
  35.     vector<double> data1, data2, data3;
  36.     load_data(data1, data2, data3);
  37.    
  38.     // Stworzenie, wypełnienie i narysowanie histogramów
  39.     TH2D *h_corr1 = new TH2D("h_corr1", "Correlation (m=97, g=23)", 100, xmin, xmax, 100, 0, 1);
  40.     TH2D *h_corr2 = new TH2D("h_corr2", "Correlation (m=32363, g=157)", 100, xmin, xmax, 100, 0, 1);
  41.     TH2D *h_corr3 = new TH2D("h_corr3", "Correlation (m=147483647, g=16807)", 100, xmin, xmax, 100, 0, 1);
  42.     for (int i = 0; i < N - 1; i++)
  43.     {
  44.         h_corr1->Fill(data1[i], data1[i+1]);
  45.         h_corr2->Fill(data2[i], data2[i+1]);
  46.         h_corr3->Fill(data3[i], data3[i+1]);
  47.     }
  48.     TCanvas* c1 = new TCanvas("c1", "c1", 1200, 600);
  49.     c1->Divide(4, 2);
  50.     c1->cd(1);
  51.     h_corr1->GetXaxis()->SetTitle("x_{n}");
  52.     h_corr1->GetYaxis()->SetTitle("x_{n+1}");
  53.     h_corr1->Draw("COLZ");
  54.     c1->cd(2);
  55.     h_corr2->GetXaxis()->SetTitle("x_{n}");
  56.     h_corr2->GetYaxis()->SetTitle("x_{n+1}");
  57.     h_corr2->Draw("COLZ");
  58.     c1->cd(3);
  59.     h_corr3->GetXaxis()->SetTitle("x_{n}");
  60.     h_corr3->GetYaxis()->SetTitle("x_{n+1}");
  61.     h_corr3->Draw("COLZ");
  62.     TH1D *h_uniform1 = new TH1D("h_uniform1", "Uniform (m=97, g=23)", 100, 0, 1);
  63.     TH1D *h_uniform2 = new TH1D("h_uniform2", "Uniform (m=32363, g=157)", 100, 0, 1);
  64.     TH1D *h_uniform3 = new TH1D("h_uniform3", "Uniform (m=147483647, g=16807)", 100, 0, 1);
  65.     for (int i = 0; i < N; i++)
  66.     {
  67.         h_uniform1->Fill(data1[i]);
  68.         h_uniform2->Fill(data2[i]);
  69.         h_uniform3->Fill(data3[i]);
  70.     }
  71.     c1->cd(5);
  72.     h_uniform1->GetXaxis()->SetTitle("x");
  73.     h_uniform1->Draw();
  74.     c1->cd(6);
  75.     h_uniform2->GetXaxis()->SetTitle("x");
  76.     h_uniform2->Draw();
  77.     c1->cd(7);
  78.     h_uniform3->GetXaxis()->SetTitle("x");
  79.     h_uniform3->Draw();
  80.  
  81.  
  82.  
  83.     // Stworzenie zadanej funkcji na dwa sposoby
  84.     TF1 *function = new TF1("f(x)", "0.5*exp(-x/2)",   0, 10);
  85.     TH1D *transformed= new TH1D("transformed", "Distribution", 100, 0, 8);
  86.     for (int i = 0; i < N; i++)
  87.     {
  88.         transformed->Fill((-2.0 * log(1.0 - data3[i])));
  89.     }
  90.     TH1D *transformed2= new TH1D("transformed2", "Distribution", 100, 0, 8);
  91.     for (int i = 0; i < N; i++)
  92.     {
  93.         transformed2->Fill(-2.0 * log(1.0 - gRandom->Uniform(1.0)));
  94.     }
  95.     c1->cd(4);
  96.     function->Draw();
  97.     transformed->Scale(12.5/1000000);
  98.     transformed->Draw("SAME");
  99.     c1->cd(8);
  100.     function->Draw();
  101.     transformed2->Scale(12.5/1000000);
  102.     transformed2->Draw("SAME");
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement