


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
THe second tutorial for second year electrical engineering from 2025
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Write a program randomgraph.py that takes as command-line arguments an integer N and a floating-point value p ∈ [0, 1]. The program should plot N equally spaced points on the circumference of a unit circle. Each pair of points should furthermore be connected by a line with probability p, i.e. the presence of each line is determined independently with probability p. Example output for various parameters is given below.
Encode the eight-page example shown below for use as input to transition.py in a file called eightpage.txt. Then implement and use transition.py to obtain a transition matrix for the example. Use this matrix to calculate the page ranks by implementing and using both randomsurfer.py and markov.py.
Now modify transition.py to ignore the effect of multiple links. That is, if there are multiple links from one page to another, count them as one link only. Call your modified program singletransition.py. Repeat the analysis above on the example, but using the modified transition matrix obtained with singletransition.py. Repeat the analysis described above on the three-page example provided in threepage.txt in the tutorial resources. Compare your results in each case: which do you think is a better approach to ranking web pages?
3 The binomial distribution (JBook 2.1.34)
Write a function
def binomial(n, k, p)
in a program binomial.py to compute the probability of obtaining exactly k heads in N flips of a biased coin (heads with probability p) using the formula
f (n, k, p) = pk(1 − p)n−kN !/(k!(n − k)!)
Hint: To stave off overflow, compute x = ln f (n, k, p) and then return ex. You may want to use an additional function for this. Write a main function for your program that obtains N and p from the command line and prints out ∑n
k=
f (n, k, p) ,
which should be equal to one (up to numerical accuracy). Set up your program to call the main function when it is executed, but not when it is imported: in the former case, the value of the special variable name is ’ main ’; in the latter, it is the name of the module (i.e. ’binomial’ in this case). Also use the class binomialclient.py provided in the tutorial resources to test your binomial function. Take a look at the contents of binomialclient.py and ensure you un- derstand how it tests the code.
4 The Erlang loss formula
Consider a model of a telephone network switch where λ is the arrival rate of telephone calls (measured in calls per second) to a switch that can carry maximally N calls, and 1/μ is the average duration (measured in seconds) of a call. In telephony jargon, λ is called the offered traffic per unit time and ρ = λ/μ the offered load. The load ρ is measured in units of “Erlangs”. It is known that (under some reasonable assumptions we don’t go into here) the probability that an incoming call is lost because all N circuits are busy is a function of the load, ρ, and N. This blocking probability is given by the Erlang loss formula (also known as the Erlang B-formula):
B(N, ρ) = ρN^ /N! ∑N n=0 ρ n/n! (1)
Eqn. (1) looks easy to evaluate, but think of the situation where ρ = 100 and N = 200. Then there is a term of the form (100)^200 /200! that needs to be evaluated, and this is difficult to do exactly, even for a computer. To get around this we use a recursive formulation for B(N, ρ) which calculates B(N, ρ) in terms of B(N − 1 , ρ)
B(N, ρ) = ρ B(N − 1 , ρ) N + ρB(N − 1 , ρ)
where B(0, ρ) = 1. Create a program erlang.py, and use it to perform the following:
(a) (b) (c) (d)
Figure 2: Order
(a) (b) (c) (d)
Figure 3: Right
(a) (b) (c) (d)
Figure 4: Shaded