Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1) Which command will return the upper right corner element of a 5-by-5 matrix A? a. A([end, 1], [end, 1]) b. A(1,end) c. A({[1, end]})

1) Which command will return the upper right corner element of a 5-by-5 matrix A?

a. A([end, 1], [end, 1])

b. A(1,end)

c. A({[1, end]})

d. A(1:10, 1:10)

.-------------------------------------------------------------------------------------------------------

2) Given two matrices that have the same dimensions and are square, which of the following are TRUE:

a. A^B = B^A

b. A.*B = B.*A

c. A-B = B-A

d. A*B = B*A

.-------------------------------------------------------------------------------------------------------

3) Which MATLAB statement is correct for obtaining a vector y where the elements are formed using the formula:

y=xcos(x)+sin(x)4+cos(x)y=xcos(x)+sin(x)4+cos(x)

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 this definition of x.

.-------------------------------------------------------------------------------------------------------

4) Which of the following MATLAB commands will create a row vector with exactly three zeros, as for example, [0 0 0 ]?

a. linspace(0,3,0)

b. linspace(0,1,3)

c. zeros(3)

d. 0 * rand(1,3)

.-------------------------------------------------------------------------------------------------------

5)The following commands are typed in the MATLAB command window:

>> y = -2;

>> c = 4;

>> x = swap(y)

The function swap is given below. What is the value of x after executing the commands shown above?

function c = swap(x)

temp = x;

y = x;

c = 1 - x;

end

a. ERROR

b. -2

c. -3

d. 3

.-------------------------------------------------------------------------------------------------------

6) Assume that vec and arr have been defined as follows

vec = [5.1 2.3 1.7];

arr = [4 7 8; 3 1 6];

Consider this line of Matlab code:

arr[1,2] = 0;

Will attempting to execute the code result in an error?

True/False?

.-------------------------------------------------------------------------------------------------------

7) Consider the following lines of Matlab code:

1 arr=[4,7,2,5,1,6];

2 for j = 2:length(arr)

3 key = arr(j);

4 i = j 1;

5 while i >= 1 && arr(i) > key

6 arr(i+1) = arr(i);

7 i=i-1;

8 end %end of while loop

9 arr(i+1) = key;

10 end %end of for loop

After all the lines of code are executed, what is this code achieving with respect to the elements of array arr?

a. All the elements are replaced with the value of the second element, 7.

b. The elements of the array are arranged from the largest to the smallest.

c. All the elements are replaced with the value 0.

d. The elements of the array are arranged from the smallest to the largest.

-------------------------------------------------------------------------------------------------------

8) Consider the following lines of Matlab code:

1 arr=[4,7,2,5,1,6];

2 for j = 2:length(arr)

3 key = arr(j);

4 i = j 1;

5 while i >= 1 && arr(i) > key

6 arr(i+1) = arr(i);

7 i=i-1;

8 end %end of while loop

9 arr(i+1) = key;

10 end %end of for loop

After line 8 gets executed the first time, the state of the array arr is:

arr = [4, 7, 7, 5, 1, 6]

What is the state of the array arr after line 8 is executed the third time?

a. arr = [2, 7, 7, 5, 1, 6]

b. arr = [4, 4, 7, 5, 1, 6]

c. arr = [2, 4, 7, 7, 1, 6]

d. arr = [2, 4, 4, 7, 1, 6]

-------------------------------------------------------------------------------------------------------

9) What must be TRUE to be able to multiply two matrices together

a. The inner dimensions must agree

b. The matrices must be the same size

c. The outer dimensions must agree

d. You can't multiply two matrices

-------------------------------------------------------------------------------------------------------

10) Which of the following commands will generate a random real number bigger than 20 and smaller than 40

a. randi([20,40])

b. rand()*20 + 20

c. rand(20,40)

d. rand([0,1])*20 + 20

-------------------------------------------------------------------------------------------------------

11) What are the values of x and y at the end of the loop

x = 0;

y = 0;

for i = 1:5

x = x + i;

y = x + i;

end

a. x = 15, y = 35

b. x = 10, y = 14

c. x = 15, y = 20

d. x = 20, y = 15

-------------------------------------------------------------------------------------------------------

12) Which command will return the bottom right corner element of a 5-by-5 matrix A?

a. A(1:5, 1:5)

b. A(end,5)

c. A([end, 1], [end, 1])

d. A(5,1)

-------------------------------------------------------------------------------------------------------

13) Consider the following MATLAB function

function output = result( a, b )

x = a*2 + b ;

y = 2*a + 1 ;

output = [ x ; y ]

end

Which of the following is the proper way to call the function with input values 2 and 1?

a. z=output([2,1])

b. z=result(2,1)

c. z=result([2,1])

d. z=output(2,1)

-------------------------------------------------------------------------------------------------------

14) The following commands are typed in the MATLAB command window

>> y = -2;

>> c = 4;

>> x = swap(y)

The function swap is given below. What is the value of x after executing the commands shown above?

function c = swap(x)

temp = x;

y = x;

x = temp;

end

a. error

b. 4

c. -2

d. 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions