Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. // lab2.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include <iostream>
  5. #include<math.h>
  6. using namespace std;
  7.  
  8. double genExp(double l)
  9. {
  10. double U;
  11. U = (double)rand() / (RAND_MAX + 1);
  12. return (-1 * log(1 - U) / l);
  13. }
  14.  
  15. double genGauss(double m, double sigma)
  16. {
  17. double suma = 0;
  18. int i;
  19. for (i = 1; i <= 12; i++)
  20. suma = suma + (double)rand() / RAND_MAX;
  21. return m + sigma * (suma - 6);
  22. }
  23.  
  24. double tp(int n)
  25. {
  26. double t;
  27. if (n == 1)
  28. t = 1.2;
  29. else
  30. t = 1.2 + 0.0010*(n - 1);
  31. return t;
  32. }
  33.  
  34. int NS = 1000000;
  35. double STa = 0;
  36. double pc = 0;
  37. double T = 60 * 1000 / 7200;
  38. double ns = 63;
  39. int main()
  40. {
  41. double C = 16383;
  42. double lambda = 0.00019647658;
  43. //int c;
  44. //cout << "Hello World!\n";
  45. int i=0;
  46. double b, c, t;
  47. while (i < NS)
  48. {
  49. b = genGauss(20, 5.42857);
  50. c = genExp(lambda);
  51.  
  52. STa += tp(c) * abs(pc - c);
  53. STa += T / 2;
  54. STa += b * T / ns;
  55. pc = c;
  56.  
  57. i++;
  58. }
  59.  
  60. double TmaC = STa / NS;
  61.  
  62. cout << "TmaC= " << TmaC << endl;
  63. system("pause");
  64. return 0;
  65. }
  66.  
  67. // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
  68. // Debug program: F5 or Debug > Start Debugging menu
  69.  
  70. // Tips for Getting Started:
  71. // 1. Use the Solution Explorer window to add/manage files
  72. // 2. Use the Team Explorer window to connect to source control
  73. // 3. Use the Output window to see build output and other messages
  74. // 4. Use the Error List window to view errors
  75. // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
  76. // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement