Skip to main content
留学咨询

辅导案例-ICP2021

By May 15, 2020No Comments

1 ICP2021 ASSIGNMENT 1 Weight: 20% of the total mark of the module. Total number of points: 100 Deadline: 6th March, 4pm. The submission point will close automatically thereafter. Submission: Submit one zip file containing: ONE m file with answers to all assignment questions, separate function files that you wrote, and all image files for the code to run. When I run your lab m file, MATLAB should produce all required outputs. Notes: Write your name in a comment line at the top of your m file. Write “reasonable” comments. Inefficient or longer than necessary code will score a lower mark. Plagiarism: DO NOT copy from one another. Changing the variable names does not make the code your own! A mark of zero will be awarded for assignments which are too similar. I reserve the right to interview you about your submission and change your mark if I discover that you cannot explain your code in enough detail. 1 (a) Write a MATLAB function that will take as input a square matrix A and will return value 1 if A is symmetric, and value 0, otherwise. Check whether the two dimensions of A are equal, and output an error message if they are not. Demonstrate in your script that your function behaves as expected. You may not use MATLAB built-in function issymmetric within your function. [15] 1 (b) Subsequently, use the function you created in (a) to estimate the probability that a randomly generated 2- by-2 matrix with integer entries between -3 and +3 is symmetric. (To do this, generate a large number of such matrices and estimate the proportion of symmetric matrices among them.) Format and print your answer in MATLAB’s Command Window. For this exercise, you are not allowed to use commands mean or sum. [12] 2 (a) Ask the user to input an even integer, n, between 10 and 100. If n is odd, not an integer, or is outside the specified interval, keep asking for another number. (You may not use MATLAB function isinteger.) When a suitable n has been entered, create an n-by-n matrix according to the following rules: [15] i. The outer two rows must be equal to 1. ii. The inside of the matrix must contain rows with consecutive numbers from 3 to n-2. iii. The innermost 4 cells must be equal to 1. An example for n = 10 is shown in Table 1. 2 (b) Visualise your matrix using the indexed image approach. Choose a colour and make the colourmap go from white to your chosen colour, spanning different shades of your chosen colour. An example is shown in Table 1. [11] 3. Plot a stick-man cartoon. An example is shown in Figure 1. You can choose your own design and portray what you want. There should be a least two figures on the plot, some text, and your copyright note at the bottom. The surrounding box should be visible too. The proportions of the lines (arms, legs and torso) are not important as long as the human figure has all its touching line components. 2 Table 1. Expected output for problem 2. Matrix for n = 10 Visual representation of the matrix for colour [0, 0.4, 0] (dark green) 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 4 5 6 7 8 1 1 1 1 3 4 5 6 7 8 1 1 1 1 3 4 1 1 7 8 1 1 1 1 3 4 1 1 7 8 1 1 1 1 3 4 5 6 7 8 1 1 1 1 3 4 5 6 7 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Figure 1. An example of a stick-man cartoon. Look up command text to position text on a figure. Hint: draw your sketch on a piece of grid paper to figure out the coordinate of the elements. Note that you can plot more than one line within the same plot command. More points will be awarded for short and elegant code. (I may give extra points for originality of the design.) Marking scheme: • Figure and box [7] • Stick men [16] • Text [6] 3 4 (a) Upload a jpg or png colour image of your choice and show it in a figure as in Figure 2a. Convert it to grey scale and invert the bottom half of the image. Show the result as in Figure 2b. Don’t forget to include your image in the zip file! [9] 4 (b) After completing part (a), prepare a new image in colour such that the top part of the image is shown in colour and the bottom part, in grey. The expected outcome is shown in Figure 2c. [8] Figure 2. Expected output for problem 4.

admin

Author admin

More posts by admin