Question

In: Computer Science

1. In the command fprintf within the string statement what operator executes a linefeed? () (4...

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)

Solutions

Expert Solution

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


Related Solutions

1) How do you extract a part of a string? Give the command and examples (in...
1) How do you extract a part of a string? Give the command and examples (in arduino) 2) Explain how negation and comparison operators combine together. (in Arduino) 3) What are the qualifiers? (in Arduino) 4) List the increment and decrement operators. (in Arduino)
---------------- Exercise 2: String Permutations ---------------- Create a program that takes a string from the command...
---------------- Exercise 2: String Permutations ---------------- Create a program that takes a string from the command line and prints every permutation of that string. You may assume the string will contain all unique characters. You may print the permutations in any order, as long as you print them all. ---------------- Output: ---------------- $>./prog dog d do dog dg dgo o od odg og ogd g gd gdo go god ---------------- I need help on this exercise that requires recursion only....
---------------- Exercise 2: String Permutations ---------------- Create a program that takes a string from the command...
---------------- Exercise 2: String Permutations ---------------- Create a program that takes a string from the command line and prints every permutation of that string. You may assume the string will contain all unique characters. You may print the permutations in any order, as long as you print them all. ---------------- Output: ---------------- $>./prog dog d do dog dg dgo o od odg og ogd g gd gdo go god ---------------- I have no idea on coding this. The files I...
Write a MIPS program that executes the statement: s = (a + b) – (c +...
Write a MIPS program that executes the statement: s = (a + b) – (c + 101), where a, b, and c are user provided integer inputs, and s is computed and printed as an output. Answer the following: a. Suppose the user enters a = 5, b = 10, and c = -30, what is the expected value of s? b. Which instruction in your program computed the value of s and which register is used? c. What is...
1.If one statement is nested within another statement, as in a loop or recursive call, what...
1.If one statement is nested within another statement, as in a loop or recursive call, what is the running time of the two statements when considered as a block? the running time for the inner statement added to the running time for the outer statement the running time for the inner statement multiplied by the running time for the outer statement the running time for the inner statement divided by the running time for the outer statement the running time...
Make a modification of the program below, that will read in the string as a “command-line...
Make a modification of the program below, that will read in the string as a “command-line argument” to your program, instead of having the user type it while your program is running. Your program should print out the inverted string to the screen. #include <iostream> #include <cstring> using namespace std; int Reverse(char * destination, const char * source, int num); int main() // this is the test/driver code, for your function { const int STRINGSIZE = 10; char oldCString[] =...
1. What command is used to change the current working directory at the command line?
1. What command is used to change the current working directory at the command line?
Suppose a stock is trading at $4 in July. An options trader executes a spread by...
Suppose a stock is trading at $4 in July. An options trader executes a spread by selling an August put with strike $30 for $50, buying an August put with strike $40 for $300, buying an August call with strike $40 for $300 and selling an August call with strike 50 for $50. Write the payoff function of the spread and provide the corresponding diagram. Write a paragraph discussing if the spread provides a limited/unlimited profit potential and possible corresponding...
Apply ?̂2 and ?̂?operator on the following wavefunctions, a. ( 3 4? ) 1/2 ???? b....
Apply ?̂2 and ?̂?operator on the following wavefunctions, a. ( 3 4? ) 1/2 ???? b. ( 3 8? ) 1/2 ???? ? ?? c. ( 3 8? ) 1/2 ???? ? −?? What is the result? Which is these functions are eigen functions of both operators? Is there anything else you like to conclude?
Q.3 1- Why is the typecast operator needed to compute the mean in the statement mean...
Q.3 1- Why is the typecast operator needed to compute the mean in the statement mean = static_cast(float)(total)/value;? What do you think will happen if it is removed? Modify the code and try it. Record what happens. Make sure that you try both even and odd cases. Now put static_cast<float> total back in the program. 2- What happens if you enter a float such as 2.99 instead of an integer for value? Try it and record the results. 3- Modify...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT