Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ELEC0021 - Programming and Control Systems

2022

Answer ALL questions

Section A - Control

1.   Consider the system described by the following block diagram in Figure 1.1.

 

Figure 1.1

(a) Write  the  transfer  function  between  the  input  u1    and  the  output  y   as  a  function  of P(s), Q(s), R(s).

[5 marks]

(b) Write  the  transfer  function  between  the  input  u2    and  the  output  y   as  a  function  of P(s), Q(s), R(s).

[5 marks]

Consider now a dynamical system described by the transfer function

T(s) = 

(c) Compute, if possible (please justify this), the steady-state value of the output y(t) when the system described by T(s)  is driven by a unitary step input (u(t) = 1(t)) starting from null initial conditions.

[5 marks]

(d) Compute the analytic expression of the system response y(t) in time domain, starting from

null initial conditions, when the system described by T(s) is driven by the input u(t) = −2  ∙ 1(t).

[5 marks] (e) Compute the analytic expression of the system response y(t) in time domain, starting from

null initial conditions, when the system described by T(s) is driven by the input u(t) = −26(t),

where  6(t − t0 )  is  the  unitary  impulse  function  at  timet0 .  Hint:  consider  exploiting  the formulation of the system response to the unitary step.

[5 marks]

2.   Consider the system described by the following block diagram in Figure 2.1, where the transfer function is

(1 − S)(1 + 10S)

L(S) = u       (1 + S)2           , u > 0.

 

Figure 2.1

(a) Sketch the  asymptotic  Bode  diagrams for the system with u = 0.5 (using the  provided logarithmic charts).

[5 marks] (b)

(i)  Sketch the Nyquist plot for the frequency response of the system with u = 0.5.

[3 marks] (ii)  Consider the Nyquist plots for values of u > 0. By using the Nyquist criterion, determine

the values of u for which the system is asymptotically stable, marginally stable and unstable, respectively. Mathematically justify your answer.

[5 marks]

(c) Using a different approach than the one used in Point (b), determine the values of u for which the system is asymptotically stable, marginally stable and unstable, respectively.

[5 marks]

(d) Consider the system described by the block diagram in Figure 2.1, where the transfer function now is

L(S) = u

TS

(1 + S)2

Compute the phase margin for the system when u = 10 and T = 0.5. Discuss the system’s stability.

[7 marks]

 

 


Section B - Programming

3.   The Python class Land shown below represents a piece of land modelled as a grid. Every element in the grid represents the height above the sea level (in meters) of the piece of land in that square. The method numberOfPeaks must return the number of peaks, where a peak is an element in the array representing the grid surrounded by 8 elements with lower values.

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

15.

16.

17.

18.

19.

20.

21.

22.

23.

24.

25.

26.

27.

28.

29.

30.

31.

32.

33.

34.

35.

36.

37.

38.

import numpy as np

class Land:

#initialisation of the grid size and content

def __init__(self, size):

self.size=3

self.setSize(size)

self.grid=np.random.random([self.size,self.size])*10

self.grid=self.grid.round(2)

# “prettyprint

def __str__(self):

return "Grid of "+ str(self.size)+"x"+str(self.size)+"\n"+str(self.grid)

#size of grid is setup

def setSize(self,size):

if(size>=3):

self.size=size

#returns True if element [i,j] is a peak, False otherwise

def isPeak(self,i,j):

for k in range(i-1,i+2):

for m in range(j-1,j+2):

if(self.grid[i,j]<self.grid[k,m]):

return False

return True


#returns number of peaks in the grid

def numberOfPeaks(self):

#code of method

def main():

grid_size=int(input("Please, enter the size of the grid: "))

land1=Land(grid_size)

print(land1)

print("This land has", land1.numberOfPeaks(), "peaks")

if __name__=="__main__":

main()


(a) Write the code of the method numberOfPeaks, that returns the number of peaks in the land. Document your code.

[5 marks]

(b) Write an example of the information printed on screen when the user enters number 2. Please, explain your answer referring to specific lines in the code to support your explanation.

[5 marks]

(c) Modify the function main to be robust against any abnormal input from the user.

[5 marks]

(d) The algorithm KNN is trained with the following data:

Volume

Weight

Price

4

3

1000

4

4

1000

0

1

25

1

1

25

5

3

1000

1

2

25

What is the prediction for K=3 for an object with a volume of 2 and a weight of 2? Please explain.

[5 marks]

4.

(a) Write a Python function randomList(list) which takes as parameter a list and returns a      randomly chosen element from that list. Document your code. Note: you should NOT use the random package Random choice(list) method which does exactly this.

[5 marks]

(b) Lets assume there is no built-in operator ** or function pow in Python. Implement a

power(m,

n) function which calculates mn for a floating-point base m and an integer exponent n,          where base and exponent can have any value, positive, zero or negative. If the            exponent is a floating-point  number with  a  non-zero  decimal  part,  the  function  should print  an  error message and return 0. Document your code.

If we were to make power(m, n) a method of a class Math, present it as method of that class but without its implementation, simply add a comment in the method body.

[10 marks]

5.

(a) What is meant by public instance variables and why making instance variables public is not considered good practice in object-oriented programming? What is a better approach for class design? Comment on the approach used in Python for such design and compare it to that of other object-oriented programming languages.

Give an example of a class that demonstrates the benefits of a design with no public instance variables.

[6 marks]

(b) A Fibonacci series starts with 0 and 1 and every subsequent number is the sum of the previous two. As such, it lends itself naturally to a recursive implementation.

Implement a class that provides a method that allows its user to calculate the Fibonacci value of a number n recursively but also allows its user to find out how many times this method has been called; focus on good object-oriented design. Write also an excerpt of code that uses this class to calculate the Fibonacci value of integer n and print out the value and the times the relevant method was called. Document your code.

[9 marks]