MATLAB essential/Quiz 1 &3 PDF

Title MATLAB essential/Quiz 1 &3
Course Department of English
Institution جامعة بغداد
Pages 6
File Size 171.1 KB
File Type PDF
Total Downloads 31
Total Views 143

Summary

MATLAB essential/Quiz 1: Lecture 1 &3...


Description

MATLAB essential/Quiz 1: Lecture 1 Multiple Choice (1 mark each, 25 marks total) 1.

Which of the following MATLAB calculations would result the value 1? a) 1+4/5 b) 6/2*3 c) 3A2/3*3 d) 1+2+3/1+2+3 e) None of the above 2. Which of the following MATLAB expression gives -1. a) cos(180) b) cosd(pi) c) sind(3*pi/2) d) sin(-pi/2) e) None of the above 3. The volume of a cylinder is V = nr 2 h. Define r as 3 and h as the row column h = [1,5,12]. Which of the following MATLAB expression is correct for solving the volumes of cylinders with the above h values. a) r=3; h=[1,5,12]; V=nr2h b) r=3; V=n*rA2*h[1,5,12] c) r=3; V=n*rA2*h(1,5,12) d) r=3; h=[1,5,12]; V=pi*rA2*h e) Both c and d

4. Which of the following expressions generates an evenly spaced vector x containing 15 values between 4 and 20. a) x=linspace(4,15,20) b) x=linspace(15,4,20) c) x=linspace(4,20,15) d) x=4:15:20 e) x=4:20:15 5. The general equation for the distance y that a free falling body has travelled (neglecting air friction) is

y = ½ gt 2

| Assume that g = 9.8 m/s 2 . Which of the following expressions generates a table of time versus distance traveled for time from 0 to 100 seconds. a) t = [0,100] ; g = 9.8; y(t ) = 0.5 * g * t2; dis p([t ,y] ') b) t = 0,100; g = 9.8; y(t ) = 0.5 * g * t A 2; disp([ t,y] ') c) t = 0:100; g = 9.8; y(t ) =0.5 * g * t. A2; disp ([ t', y' ]) d) t = 0:100; g = 9.8; y(t ) = 0.5 * g * t A 2; disp ([ t ',y']) e) None of the above 6. Which of the following expression generates the matrix shown below

2.7 1.8 10 20 5 7.5 6.2 1

2 30 9 2

9 40 4. 38

a) A = [2.7; 1.8; 2; 9; 10; 20; 30; 40; 5; 7.5; 9; 4.8; 6.2; 1; 2; 3] b) A = [2.7; 1.8; 2; 9,10; 20; 30; 40, 5; 7.5; 9; 4.8, 6.2; 1; 2; 3] c) A = [2.7 1.8 2 9; 10 20 30 40; 5 7.5 9 4.8; 6.2 1 2 3] d) A = [2.7,1.8,2,9; 10, 20, 30,40; 5, 7.5,9,4.8; 6.2,1, 2, 3] e) Both c and d 7. Given the matrix A above (Question 11) which of the following is the correct value for the expression x = s um(A) a) b) c) d) e)

x=[23.9 30.3 43 56.8] x=154 x=[15.5; 100.0; 26.3; 12.2] x=[15.5 100.0 26.3 12.2] x=[23.9; 30.3; 43; 56.8]

8. Examine the following MATLAB code. What is the value of B at the end of the program: A=2; for ii=0:2:4 A=[A, A*ii]; end B=A a) B=2,0,0,0 b) B=2 20200 2000 c) B= 2 0 4 0 8 0 16 0 d) B= 2 2 4 8 e) None of the above 9. The difference between a function and a script is: a) only a function file can be run from the command line b) only a function requires inputs c) only a script file can perform a series of commands d) functions cannot save variable values e) function variable names only have meaning within the function, whereas script variables are available to other programs

10. What does Matlab stand for? a) Math Laboratory b) Matrix Laboratory c) Mathworks d) Nothing e) none of the above Ans: b 11. What symbol precedes all comments in Matlab? a) “ b) % c) // d) < e) none of the above Ans: e 12. This Matlab command clears all data and variables stored in memory: a) clc b) clear c) delete d) deallocate e) none of the above Ans: b 13. Which of the following will correctly define x, y, and z as symbols? a) sym (x, y, z) b) syms x y z c) syms x, y, z d) sym x, y, z e) none of the above Ans: b

14. Which of the following is used to see if two elements are equal in MATLAB? a) ! = b) == c) isequal d) = e) none of the above Ans: b 15. If vector = [1 2 3 4; 11 24 92 100; 345 65 90 1]. What will the value of a be equal to if this code is entered into MATLAB >>[a b] = size (vector)? a) 1 2 3 4 b) 12 c) 1 3 d) 4 e) 3

Ans: e 16. To add a comment to the mfile, the MATLAB command is a) % b) ; c) comment(' ') d) & Ans: a 17. To display 'Question 2' in the command window, the correct command is a) disp(Question 2) b) display('Question 2’) c) disp('Question 2’) d) Question 2 Ans: c 18. The clc command is used to a) clear the command window b) erase everything in the mfile c) clean the desktop d) save the existing mfile Ans: a 19. The num2str command a) converts a number to string b) converts string to a number c) concatenates numbers and strings d) concatenates strings Ans: a 20. Consider the following MATLAB program: x = [1 2]; y = [3 4]; z = [ x' [ y ; y ] ]'; What is the value of z after this program executes? 123 434 133 244 134 234 12 ★ 33 44

a) None of the other answers are correct 4

21. Consider the following MATLAB function stored in prink.m: function [ f g ] = prink( x,y ) f = x . ˄  0.5; g = y + f .*2; end Which of the following correctly assigns the results of a call to prink f to F and g to G, respectively? a) F,G = prink( 2,3 ); b) [ FG ] = prink( [ 2 3 ] ); c) [ FG ] = prink( 2 3 ) ; d) [ FG ] = prink [ 2 3 ]; e) ★ [F G ] = prink( 2,3 ); 22. Recollect that MATLAB represents polynomials as an array of coefficients from the highest-order coefficient to the lowest. For instance, x3 + x + 2 is written as the array [10 1 2 ] . How would we represent the summation of the two polynomials x2 + x + 1 and x3 + x2 - 1 as a MATLAB polynomial array? a) [ 1 1 1 ] + [ 1 1 0 -1 ] b) [ 1 1 1 ] + [ -10 1 1 ] c) ★ [ 0 111 ] + [ 11 0 -1 ] d) [ 1 1 1 0 ] + [ 1 1 0 -1 ] 23. Consider the following MATLAB program: s = (2 < 3) & ((2 > 3) | (1 ~= 0)) What is the final value of s? a) True b) ★ 1 c) 0 d) False 24. What is the final value of x = linspace( -1,1,101 ); y1 = exp( x ); y2 = tan( x );

5

y3 = rand( 1,numel(x) ); How would you successfully plot all three of these data series as points? (Assume any given plot format strings are valid.) e) ★ plot( x, y1 , ' r . ' , x , y2 , ' g. ' , x , y3 , ' b . ' ) ; f) plot( x, y1 , ' r . ' , y2 , ' g. ' , y 3, ' b . ' ) ; g) hold on; plot( x, y1 ); plot( x, y2 ); plot( x, y3 ); h) plot( x,y1, x,y2, x,y3 ); 25. Consider the following program, which produces 10,000 random numbers selected from a certain distribution and plots them: x = randn( 10000,1 ); plot( x,'k.' ); Which of the following plots could result from executing this program?

26. Consider the following equation: Where G is a constant equal to 6.673x10-11, and ml , m2, and r are all arrays of size n by 1. Circle the answer to the following questions about writing this equation in MatLab. 27. What is the correct way to calculate the array F? a) F = G*m1*m2/r˄2 b) F = G*m1.*m2/r*r c) F = G*m1.*m2./r˄2 d) F = G*m1.*m2./r.˄2 e) F = G*(m1.*m2)./r.*r

6...


Similar Free PDFs