4321 ENGG1801 Page 1 of 10 FACULTY OF ENGINEERING AND INFORMATION TECHNOLOGIES ENGG1801 ENGINEERING COMPUTING SAMPLE EXAM A TIME ALLOWED: TWO HOURS This examination paper comprises 10 pages INSTRUCTIONS TO CANDIDATES Answer all questions using blue or black pen on this examination paper in the spaces provided. The paper comprises 7 questions, each with multiple parts. Questions are not worth equal marks. The mark awarded for each part is indicated. Marks total 50. To pass the exam you need at least 20 marks. THIS EXAMINATION PAPER IS NOT TO BE REMOVED FROM THE EXAMINATION ROOM. OFFICE USE ONLY Q1 (6 marks) Q2 (10 marks) Q3 (6 marks) Q4 (6 marks) Q5 (8 marks) Q6 (8 marks) Q7 (6 marks) Total (50 marks) CONFIDENTIAL SEAT NUMBER: ................………..................... STUDENT ID: ................………..................... SURNAME: ................………..................... OTHER NAMES: ................………..................... SIGNATURE: ................………..................... 4321 ENGG1801 Page 2 of 10 Question 1 [6 marks, each part is worth 1 mark] Given are a, b, c and d: >> a=[1 6 10 1 7; 1 3 6 5 8] a = 1 6 10 1 7 2 3 6 5 8 >> b=[10;2;3;1;2] b = 10 2 3 1 2 >> c=[20 6 12 1 17] c = 20 6 12 1 17 >> d='ENGG1801 Engineering Computing' d = ENGG1801 Engineering Computing What will Matlab display? a) >> a(1,4) b) >> a*b c) >> c./b' d) >> a-ones(5) 4321 ENGG1801 Page 3 of 10 e) >> d(end:-2:12) f) >> [a(1,:), c(2:3)] Question 2 [10 marks] For each part of this question, indicate what the code will display. a) [3 marks] x=3; switch(x) case 1 disp('One') case {2,3} disp('Two') case {4,5,6} disp('Three') otherwise disp('Do what?') end b) [3 marks] for i=6:-1:1 disp(['i=',num2str(i)]); end 4321 ENGG1801 Page 4 of 10 c) [4 marks] k=0; for i=1:10 while k
k=k+100; end disp(k+i); end 4321 ENGG1801 Page 5 of 10 Question 3 [6 marks] The above spreadsheet shows the results of an experiment in which a Force given in column A is applied to three different masses given in cells B2, C2 and D2. Force, mass and acceleration are related by the equation F = m a. a) [3 marks] What formula should you enter in cell B6 to calculate the acceleration, rounded to 1 decimal place? This formula should be able to be dragged down to cell B15, and across to cell D6 to complete the grid. b) [3 marks] What formula should you enter in cell B18 to calculate the average of all the values of acceleration greater than 1 m/s/s? This formula should be able to be dragged across to cell D18. 4321 ENGG1801 Page 6 of 10 Question 4 [6 marks] Write a Matlab program to solve a system of four linear equations such as the following: x + 3y - 2z + 4t = 1 -2x + 3y + 4z - t = 1 -4x - 3y + z + 2t = 1 2x + 3y - 4z + t = 1 Your program should read a csv file equations.csv containing the equation coefficients. For the above system of equations the csv file would look like this: 1,3,-2,4,1 -2,3,4,-1,1 -4,3,1,2,1 2,3,-4,1,1 Your program should then print out the value of x, y, z and t. 4321 ENGG1801 Page 7 of 10 Question 5 [8 marks] a) Write a Matlab program to read the csv file file.csv which contains data in CSV format b) The data content is as follows. The first column contains measurements of the parameter x, the second column contains measurements of the parameter y, the last but one column contains x_new, values of x for which you would like to estimate the value of y, and the last column contains y_target, the true values of y for x_new. Write a Matlab program to: - compute 3 best polynomial fits for the x and y data: degree 1, 2 and 3 polynomial; - compute y_predicted, the predicted values of y for x_new, using the computed best fit models; - evaluate the quality of the prediction by computing the absolute error of each model defined as: error= where i is over all data points; - find the model which predicts best, i.e. has the smallest error, and display a message saying which was the best model and what was its error, e.g. The model with lowest error is a degree 2 polynomial and its error is 1.77 4321 ENGG1801 Page 8 of 10 Question 6 [8 marks, each part is worth 4 marks] a) Write a Matlab program to plot the surface z = sin(x)sin(y) for -3π ≤ x,y ≤ 3π with an increment of 0.1. Show only the connection lines of the surface without the faces. Label the axes appropriately. b) Given is the following system of linear equations: 3x+4y+5z=2 2x-3y+7z=-1 x-6y+z=3 Write a Matlab program to: - Check if a solution exists; - If a solution exists, solve the system using the backslash operator. If a solution does not exist, display an appropriate message. 4321 ENGG1801 Page 9 of 10 Question 7 [6 marks] You have 500 litres of paint, and want to paint as many spherical balls as possible. Write a function number_painted() that takes a vector giving the radii of the balls in metres, and returns the maximum number that can be painted. The surface area of a sphere is given by: € A = 4πr2 One litre of paint covers 15 square metres. Your function should work like this: >> number_painted([[20.0, 40.0, 10.0, 50.0, 30.0]) 2 spheres can be painted 4321 ENGG1801 Page 10 of 10 FOR ROUGH WORK 欢迎咨询51作业君