MA2552 Introduction to Computing (DLI)

MA2552 Introduction to Computing (DLI) 2024/25

Computer Assignment 1

  1. (10 points) Write a function that take as an input an array x and an integer m,and outputs a matrix of size length(x) × m, whose columns are the first m Taylorapproximations of either cos(x) or sin(x) (this choice is part of the inputs). Yourfunction should avoid using iterative loops.
  1. (10 points) A prime number which is one less than a power of 2 is called a ‘Mersenneprime’. For a given natural number n > 2, write a function which outputs a row vectorcontaining all Mersenne primes less than or equal to n.
  1. (10 points) The equation of an ellipse oriented along the x-y axis with semi-axis ofsize a and b, respectively, is given by x a  2 +  y b  2 = 1.In this exercise you will create a function that outputs an N-points discretisation of anellipse of semi-axis lengths a and b, that is rotated at an angle theta with respect tothe x axis.Write a function with header E = ellipse(a, b, theta, N) following the steps herebelow.(i) Using linspace, create an array of size 1xN consisting of evenly-spaced doublesbetween 0 and 2π.(ii) Create an array of size 2×N where the first/second row is the cosine/sine of thevalues of the array you created in (i). This will give you an N-points discretisationof a circleiii) The result of (ii) is an N-points discretisation of a circle with radius 1, where thex coordinate is the first row and the y coordinate is the second row. Scale eachcoordinate by a and b, respectively, to obtain the discrete version of an ellipsewith semi-axis lengths a and b.(iv) The matrix cos( sin(θ θ ) cos( ) sin( θ θ ) ) is a rotation matrix – it maps any given vectore u R 2 to another vector v R 2such that u= vand the angle between the u and v (anticlokwise) is θ. Usinthis, create an array of size 2× N whose columns are θ rotations of the columnsof the discretised ellipse of (iii).You can visualise your results using the command plot(E(1,:), E(2,:)), axis equal.
  1. (10 points) To read an image in MATLAB one can use the command I = imread(yourImage),which creates a multidimensional array I of size n×m×3 (n and m are the dimensionsof the image), where the first two index 代 写MA2552 Introduction to Computing (DLI)  dimensions indicate the indices of each pixel,and the third index indicate one of each the red, green, and blue (RGB) components of1MA2552 Introduction to Computing (DLI) 2024/25each color pixel. Create afunction that takes as an input a colour image and repaintst according to a given a mapping from the primary colours to the primary coloursthis mapping is also an input of your function). Show your results with one or moreimages of your choosing.
  1. (10 points) A square matrix H of size n is called a Hadamard matrix if its elementsare either 1 or -1, and H × Ht = nI, where I denotes the identity matrix. Write afunction that checks if a matrix is Hadamard.
  2. (10 points) A Hadamard matrix of size 2k can be obtained using the following recurrence relationWrite a recursive function that obtain such Hadamard matrix. Use the function ofquestion 2 to verify your method.
  1. (10 points) The Legendre polynomials satisfy the following recurrence relation.(2n + 1)xPn(x) = (n + 1)Pn+1(x) + nPn1(x), with P0(x) = 1 and P1(x) = x. Show that Pn(x) = O(x n ) for x → ∞.Hint: use inductive/recursive thinking.
  2. (10 points) (3 points) What is the big O complexity, as a function of n, of thefollowing code? Justify your answer.
  3. (10 points) Write a function that transforms an array of 0 and 1, to a float in decimals.The function should decide on the single or double precision depending on the lengthof the input array.

(10 points) Implement a code that read the excel file ‘LDIstudents.xls’ (in the ‘assesments / computer assignments’ folder in blackboard) and store the information of eachstudent in a MATLAB structure that you will call Student. For each group, calculatethe average mark as well as the standard deviation. Compute the correlation betweenthe marks of all students and the ‘Assistance to lectures’, ‘Assistance to tutorials’, andhe ‘Height’.2

posted @ 2024-10-05 19:08  n58h2r  阅读(4)  评论(0编辑  收藏  举报