Question

In: Statistics and Probability

write a program in matlab to produce a discrete event simulation of a switching element with...

write a program in matlab to produce a discrete event simulation of a switching element with 10 inputs and 3 outputs. Time is slotted on all inputs and outputs. Each input packet follows a Bernoulli process. In a given slot, the independent probability that a packet arrives in a slot is p and the probability that a slot is empty is (1– p). One packet fills one slot. For a switching element if 3 or less packets arrives to some inputs, they are forwarded to the switching element outputs without a loss. If more than 3 packets arrive to the inputs of the switching element, only 3 packets are randomly chosen to be forwarded to the switching element outputs and the remaining ones are discarded. In your simulation the program will mimic the operation of the switch and collect statistics. That is, in each time slot the program randomly generates packets for all inputs of the switching element and counts how many packets can be passed to the output of the switching element (causing throughput) and, alternatively counts how many packets are dropped (when the switching element has more than 3 input packets at a given time slot) . Your task is to collect throughput statistics for different values of p (p = 0.05, 0.1 up to 1.0 in steps of 0.05), by running the procedure described above for each value of p and for many slots (at least a thousand slots per value of p). The more simulated slots, the more accurate the results will be. Based on this statistics, plot two graphs: 1) the average number of busy outputs versus p, and 2) the average number of dropped packets versus p.

Solutions

Expert Solution

outputs:

code in text format:

//Include the required header files.

#include <iostream>

#include <random>

#include <iomanip>

#include<time.h>

using namespace std;

//Define the array and variables

float p1[10]={};

float d1[10]={};

int l=0;

//Define the function BernoulliProcess()

int BernoulliProcess(float p, int packetGen)

{

//Define the variables

int passed =0;

int count=0, drop =0;

//Use the bernoulli's distribution.

default_random_engine generator;

bernoulli_distribution distribution(p);

//Iterate and generate the distribution.

//Increase the count.

for (int i=0; i<packetGen; ++i)

{

if (distribution(generator))

{

++count;

}

}

//Evaluate the passed packets from the count.

if(count >3)

passed = 3;

else

passed =count;

//Evaluate the dropped packets from the passed packets.

drop = packetGen-passed;

//Display the Probability, passed and dropped packets.

cout<<"Probability:"<<p<<endl;

cout<<"passed:"<<passed<<endl;

cout<<"Drop:"<<drop<<endl<<endl;

//Return the passed packets.

return passed;

}

//Define the main function.

int main()

{

//Generate the numbewr of packets in range 1 to 10.

srand(time(NULL));

int packetGen = rand() % (10 - 1 + 1) + 1;

//Dispaly the packet generated.

cout<<"Packet generated:"<<packetGen<<endl<<endl;

//Define the variables and array.

float p =0.05,d=0.5;

int p2[50]={},d2[50]={};

//collect throughput statistics for different values

//of p (p = 0.05, 0.1 up to 1.0 in steps of 0.05),

for(int j=0; j<50;j++)

{

//Evaluate the passed and dropped packets.

//and Probabilities.

p2[j]=BernoulliProcess(p, packetGen);

d2[j]= 10-p2[j];

p= p+0.05;

d =1-p;

}

int k=0;

//Display the average number of busy outputs versus p.

cout<<"The average number of busy outputs versus p:"<<endl;

for (float i=0.05; i<0.95; i=i+0.05)

{

k++;

cout <<setprecision(2)<<fixed<< i << "-" << (i+0.05) << ": ";

for(int j=0;j<p2[k];j++)

cout<<"*";

cout<<endl;

}

cout<<endl;

k=0;

//Display the average number of dropped packets versus p.

cout<<"The average number of dropped packets versus p:"<<endl;

for (float i=0.05; i<0.95; i=i+0.05 )

{

k++;

cout <<setprecision(2)<<fixed<< i << "-" << (i+0.05) << ": ";

for(int j=0;j<d2[k];j++)

cout<<"*";

cout<<endl;

}

//Return the value 0.

return 0;

}


Related Solutions

Explain briefly. In Simulation Modelling. How is a random number the engine of discrete event simulation?
Explain briefly. In Simulation Modelling. How is a random number the engine of discrete event simulation?
In a discrete event simulation, a physical system, such as a galaxy or solar system, is...
In a discrete event simulation, a physical system, such as a galaxy or solar system, is modeled as it changes over time based on simulated forces. The objects being modeled define events that are scheduled to occur in the future. Each event, e, is associated with a time, te,in the future. To move the simulation forward,the event,e,that has smallest time,te,in the future needs to be processed. To process such an event, e is removed from the set of pending events,...
2. Vector Element Calculation Write a MATLAB script which will randomly generate a 20-element vector with...
2. Vector Element Calculation Write a MATLAB script which will randomly generate a 20-element vector with integer values ranging between −100 to +100. Using LOOP command, determine the number of negative elements in the vector. For example, given A = [15 −6 0 -8 −2 5 4 −10 -3 −5], the number of negative numbers are 6.
USE MATLAB Write a program in Matlab that would continuously ask the user for an input...
USE MATLAB Write a program in Matlab that would continuously ask the user for an input between 1 and 6, which would represent the result of rolling a die. The program would then generate a random integer between 1 and 6 and compare its value to the value entered by user. If the user’s die is larger, it should display, “Mahahanap mo na ang forever mo. Sana all!” If the user’s die is smaller, it should display, “Gising na friend,...
Matlab Implement Fading Channel Simulation: Jakes Model with using Matlab
Matlab Implement Fading Channel Simulation: Jakes Model with using Matlab
Write a user defined MATLAB program that performs power factor correction. The inputs to the MATLAB...
Write a user defined MATLAB program that performs power factor correction. The inputs to the MATLAB function should be voltage across the load (in Vrms, assume 0 phase), frequency Resistance of the load Inductance of the load power factor of the load target power factor The output of the function should be the size of the capacitor that one would need to place in parallel with the load to reach the target power factor. Please submit the code for the...
My projects is to write or find Matlab code for 4FSK(frequency shift keying) with simulation pictures...
My projects is to write or find Matlab code for 4FSK(frequency shift keying) with simulation pictures and create the signal after that add noise to it and finally demodulate it .. Please help me to do this project.
Probability and Statistics Write a Matlab simulation to solve problem 2.4.4. 2.4.4. Each problem has a...
Probability and Statistics Write a Matlab simulation to solve problem 2.4.4. 2.4.4. Each problem has a failure probability q, independent of any other component. A successful operation requires: 1. components 1, 2, and 3 all work, or 4 works 2. component 5 or component 6 works. with q = 0.2, simulate the replacement of a component with an ultrareliable component. For each replacement of a regular component, perform 100 trials.
Write a program in Matlab where the program plays a hot and cold game. The user...
Write a program in Matlab where the program plays a hot and cold game. The user answers two inputs: x=input('what is the x location of the object?') y=input('what is the y location of the object?') You write the program so that the computer plays the game. Pick a starting point. Program Calculates the distance to the object. Program picks another point, calculates the distance to the object. Program knows its at the right spot when the distance is less than...
Write a Matlab script that computes the element level stiffness matrix and force vector for linear...
Write a Matlab script that computes the element level stiffness matrix and force vector for linear elasticity.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT