Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // lab2.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include <iostream>
- #include<math.h>
- using namespace std;
- double genExp(double l)
- {
- double U;
- U = (double)rand() / (RAND_MAX + 1);
- return (-1 * log(1 - U) / l);
- }
- double genGauss(double m, double sigma)
- {
- double suma = 0;
- int i;
- for (i = 1; i <= 12; i++)
- suma = suma + (double)rand() / RAND_MAX;
- return m + sigma * (suma - 6);
- }
- double tp(int n)
- {
- double t;
- if (n == 1)
- t = 1.2;
- else
- t = 1.2 + 0.0010*(n - 1);
- return t;
- }
- int NS = 1000000;
- double STa = 0;
- double pc = 0;
- double T = 60 * 1000 / 7200;
- double ns = 63;
- int main()
- {
- double C = 16383;
- double lambda = 0.00019647658;
- //int c;
- //cout << "Hello World!\n";
- int i=0;
- double b, c, t;
- while (i < NS)
- {
- b = genGauss(20, 5.42857);
- c = genExp(lambda);
- STa += tp(c) * abs(pc - c);
- STa += T / 2;
- STa += b * T / ns;
- pc = c;
- i++;
- }
- double TmaC = STa / NS;
- cout << "TmaC= " << TmaC << endl;
- system("pause");
- return 0;
- }
- // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
- // Debug program: F5 or Debug > Start Debugging menu
- // Tips for Getting Started:
- // 1. Use the Solution Explorer window to add/manage files
- // 2. Use the Team Explorer window to connect to source control
- // 3. Use the Output window to see build output and other messages
- // 4. Use the Error List window to view errors
- // 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
- // 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