In: Computer Science
1. In the command fprintf within the string statement what operator executes a linefeed?
() (4 points).
A. \n B. \l C. \d D. /n
2. To multiply two arrays element-by-element, what operator must you use? ( ) (4 points).
A. + B. * C. .* D. ./
3. The default base of log function in MATLAB is ( ) (4 points).
A. e B. 2 C. 10 D. 5
4. Which one of the following is a valid placeholder in an fprintf statement ( ) (4
points).
A. %d B. %n C. %p D. %r E. %v
5. Which of the following names is NOT a valid name for a user-defined function? ( )
(4 points).
A. Poker B. Bla4jack C. Solitare8 D. Card-Pickup
6. If mathematical expressions are written in MATLAB without required parentheses,
operations start from left to right in order. (True or False) ( ) (4 points).
7. A MATLAB code is saved with .m extension while functions are saved with .f
extension. (True or False) ( ) (4 points).
8. Every variable used in a MATLAB code appears in the workspace until they are
cleared. (True or False) ( ) (4 points).
9. MATLAB automatically puts comments in our codes when we create codes and save
them in an M-File. (True or False) ( ) (4 points).
10. A function must return numerical outputs. (True or False) ( ) (4 points).
11. Write commands to generate a 3x5 array containing random numbers between 1 to 21 and then assign this array to A. Transpose A and assign to B. Sort the rows of B based on the 2nd column in a descending order and assign it to C. (15)
12. Write commands to create the following graph using the following parameters. All the elements in the graph must be addressed by commands. (20
-? < ? < ?
Y=sin(?),
Z=log(?).
13. According to the trajectory line (below), the height(m) y=v0sin(?)t-gt2/2. Given the initial velocity is 2 m/s, please write a user-defined function to calculate the initial ? degree, and write commands to test your function program to calculate ? in degree when height=0.0786 m and t=0.2 s. (25)
1. In the command fprintf within the string statement what operator executes a linefeed?
A. \n B. \l C. \d D. /n
Answer: Option A. \n
MatLab uses the standard character ‘\n’ as linefeed character and therefore the answer is option A.
2. To multiply two arrays element-by-element, what operator must you use? ( ) (4 points).
A. + B. * C. .* D. ./
Answer: Option C .*
The element wise multiplication operator in MATLAB is .*
3. The default base of log function in MATLAB is ( ) (4 points).
A. e B. 2 C. 10 D. 5
Answer: Option A. e
The log function in MATLAB returns the natural logarithm (base e)
4. Which one of the following is a valid placeholder in an fprintf statement ( ) (4points).
A. %d B. %n C. %p D. %r E. %v
Answer: Option A %d
%d is the valid placeholder for base 10 signed intger
5. Which of the following names is NOT a valid name for a user-defined function? ( ) (4 points).
A. Poker B. Bla4jack C. Solitare8 D. Card-Pickup
Answer: Option D. Card-Pickup
A MATLAB identifier cannot have a character –
6. If mathematical expressions are written in MATLAB without required parentheses, operations start from left to right in order. (True or False) ( ) (4 points).
Answer: False
In the absence of parentheses, operators are executed in the order of the precedence of the operators and not from left to right order.
7. A MATLAB code is saved with .m extension while functions are saved with .f extension. (True or False) ( ) (4 points).
Answer: False
The function defined in MATLAB will be a part of .m file and they do not have a separate file extenstion.
8. Every variable used in a MATLAB code appears in the workspace until they are cleared. (True or False) ( ) (4 points).
Answer: TRUE
MATLAB variable will be available in workplace until they are explicitly cleared or session ends.
9. MATLAB automatically puts comments in our codes when we create codes and save them in an M-File. (True or False) ( ) (4 points).
Answer: FALSE
Comments will not be added into .m files by MATLAB. They need to be explicitly added by the programmer using the percent (%) symbol.
10. A function must return numerical outputs. (True or False) ( ) (4 points).
Answer: FALSE
A function can return no or single or multiple values of any data type supported