Sei sulla pagina 1di 7

Problem sheet-2

Q1. Executing in the Command Window the following code

y = a + b , a = 2 ; b = sqrt(‐4) ;

returns

a. 2 + 2 i

b. 2 ‐ 2 i

c. error message

d. NaN

e. none of the above

Q2. Write the MATLAB command to generate a vector z that starts from 0, ends at 2000,and
count by 3?

Q3. Given a new vector t=z/z(end), what are:


a. t(3)
b. t(5)
c. t(end)

Q4. Write the matlab commands to generate a vector w that starts at 1 and counts by squares
to 576(24^2),that is: 1 4 9 16..

Q5. Given the vector w above,


a. What is the length of w?
b. what is w(7)?
Q6. Given vector x=[3,2,1,0] and y=[5 6 7 8], write each of the following matlab commands:
a. x.*y
b. y’
c. y-x(2)+4

d. (x.^2)/y(end-2)

Q7. After the code below executes, what does the variable x1 contain?
aa = linspace(0,pi,10);
x1 = cos(aa(10));
a. -1
b. 0
c. +1
d. error - not possible
e. some number that is not -1, 0, or +1

Q8. Which statement below will result in the variable y containing


[1 3 5 7]?
a. y = linspace(1,7,4);
b. y = 1 + 3 + 5 + 7;
c. y = 1:4:7
d. for y=1:2:7

Q9. The command shown below will produce what output?


fprintf('The value of pi = %4.2f',pi)
a. The value of pi = 3.14
b. 3.14
c. The value of pi = 3.1416
d. The value of 3.1416 = %4.2f
e. Invalid syntax

Q10. What value does the variable q contain after the Matlab code below executes?
a = [ 1 3 5 ];
q = a.*a;
q = q + 2;
a. [3 11 27]
b. nothing - operation is not possible
c. [1 3 5]
d. [3 5 7]
Q11.When used in the fprintf command, the \n is used to
a) add a space between any two characters
b) add a line space (enter key)

c) place a number into the comment


d) clear the comment

Q12.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

Q13. Run the MATLAB code:


a = 1:5;
d = a+i*a;
e = d'
f = d.'
Q14. Print a table that converts

C (from 0 to 100 with intervals of 20) to


F. Hint: c = 5 *(f - 32)/9;
Q15. We want to save a vector v=[1 2 3 4]; into a text file. How to that?
Q16. What are the methods of displaying variables in matlab?
Q17.How you can prompt user for input:

a. using scanf command


b. using printf command
c. using fprintf command
d. using input command
Q18. Fill in the blanks.

a. _ command displays the full path of the present working directory.


b. Display the names of the directories (folders) and files in the present working
directory.
c. Display the names of the M-files and MAT-files in the current directory.
d. Delete file from current directory.
e. Display contents of file.
f. Loads the values of the workspace values
previously stored in the file data_1.mat.
g. You can save script file in extension format.

Q19. Writing the following command in command window :


save a b x y
a. Saves variable a,b,x,y from workspace in current working directory.
b. Saves variable b,x,y from workspace in a file named a in present working directory.
c. Return error.

Q20. Executing in the Command Window the following code

a = 1:2 ; size(a)

returns

a. error message

b. 1 2

c. 2 1

d. 2

e. none of above
Q21. Which MATLAB statement is correct for obtaining a vector where the elements are
formed using

where x has been defined as x = ( 0 : .01 : 6 ) ?


A. y = x*cos(x) .+ sin(x)/( 4 + cos(x) )
B. y = x.*cos(x) + sin(x)/( 4 + cos(x) )
C. y = x.*cos(x) + sin(x)./( 4 + cos(x) )
D. y = x*cos(x.) .+ sin(x.)/( 4 + cos(x) )
E. None of these will work with that definition of x.

Q22. What is the value of D after the following MATLAB commands are executed:
A = [ 1 2 ; 3 4 ];
B = [ 0 1 ; 2 1 ];
C = A .* B;
D = B * C;
Q23. Consider the following MATLAB script:
z = [ 2 -1 ];
x = z(1);
y = z(2);
w1 = x^2 + y^2;
w2 = x;
output = [ w1 ; w2 ]
what is the value of output?

Q24. If the coefficient matrix of a linear system is non-singular, this means that there is exactly
one
solution to the problem (i.e., there is a unique solution to the linear system).
A. True
B. False
Q25. Give the MATLAB commands to create a 7x7 matrix with twos in the first and fourth rows
and zeroes elsewhere.

Q26.Which command will return the corner elements of a 10-by-10 matrix A?

A. A([1,end], [1,end])
B. A([1,1], [end,end])
C. A({[1,1], [1,end], [end,1], [end,end]})
D. A(1:end, 1:end)

Potrebbero piacerti anche