Sei sulla pagina 1di 6

12/24/2019 Lab 3 (Thu): Attempt review

Dashboard / My courses / LE/EECS1560 A - Introduction to Computing for Mathematics and Statistics (Fall 2019-2020) / Lab 3 Material
/ Lab 3 (Thu)

Started on Thursday, 26 September 2019, 1:00 PM


State Finished
Completed on Thursday, 26 September 2019, 3:47 PM
Time taken 2 hours 47 mins
Marks 18.00/24.00
Grade 75.00 out of 100.00

Question 1
Which of the following matrices A is idempotent. Matrix I is an identity matrix, matrix M is any matrix and vector b is any
Incorrect
vector, all of compatible sizes. To answer the question create random matrices and vectors M, b etc, compute matrix A and
Mark 0.00 out of verify that it is idempotent using the norm trick. Remember a matrix A is idempotent when
1.00
A = A2

Select one:
a. A = I - ( b b T )/(b2)
where the superscript T means transpose and b2 is dot(b,b)

b. A = I - b b T
where the superscript T means transpose

c. A = M MT
where M is any matrix of the right size and the superscript T means transpose. 

d. A = I - M MT
where M is any matrix of the right size and the superscript T means transpose.

e. A = M2where M is any matrix of the right size.

Your answer is incorrect.


The correct answer is: A = I - ( b b T )/(b2)
where the superscript T means transpose and b2 is dot(b,b)

https://moodle.yorku.ca/moodle/mod/quiz/review.php?attempt=2415481&cmid=2181410 1/6
12/24/2019 Lab 3 (Thu): Attempt review

Question 2
Matrix
Correct
I - 2 b bT
Mark 1.00 out of
where vector b is a any unit vector, has the following properties:
1.00
Note 1: a vector b is a unit vector if the dot product by itself (i.e. dot(b,b)) is equal to 1. To create a random unit vector
first create a random vector using rand and then divide this vector by the norm of itself.

Note 2: a matrix is symmetric if it is equal to its transpose.


Note 3: a matrix is skew symmetric if it is equal to the negative of its transpose. Or equivalently, the sum of the matrix
and its transpose is the zero matrix.

Note 4: a matrix is diagonal if every element not on the diagonal is zero.


Note 5: a matrix is orthogonal if it is equal to the inverse (inv) of its transpose. Or equivalently, the product of the matrix
and its transpose is the identity (eye) matrix.

Note 6: a matrix is idempotent if it is equal to the the square of itself (i.e. A = A2)
Note 7: Check all properties except diagonality using the norm trick.

Select one:
a. Diagonal

b. Skew symmetric and idempotent

c. Symmetric and idempotent

d. Skew symmetric and orthogonal

e. Symmetric and orthogonal 

Your answer is correct.


The correct answer is: Symmetric and orthogonal

Question 3 The inverse of the product AB of matrices A and B is:


Correct

Mark 1.00 out of Select one:


1.00
a. (AB)-1 = (B)-1(A+B)(A)-1

b. (AB)-1 = (A)-1(B)-1

c. (AB)-1 = A(B)-1+B(A)-1

d. (AB)-1 = (B)-1(A)-1 

e. (AB)-1 = (B)-1A+B(A)-1

Your answer is correct.


The correct answer is: (AB)-1 = (B)-1(A)-1

https://moodle.yorku.ca/moodle/mod/quiz/review.php?attempt=2415481&cmid=2181410 2/6
12/24/2019 Lab 3 (Thu): Attempt review

Question 4 When dealing with matrices AB is not necessarily the same as BA. But sometimes for some specific pairs of matrices A and B
Incorrect the products AB and BA are equal, and this means that we can switch the order of multiplication. For which of the following
Mark 0.00 out of pair of matrices A and B can we do this
1.00

Select one:
a. When they have the form
A = I + S
and
B = I - S
where S is any matrix and I is the identity matrix.

b. When A and B are both skew symmetric.

HINT: To create a skew symmetric matrix, create a random matrix and subtract from it its transpose.

c.
When they have the form
A = S' + S
and
B = S' - S
where S is any matrix

d.
When they have the form
A = S
and
B = S'
where S is any matrix

e. When A and B are both symmetric.

HINT: To create a symmetric matrix, create a random matrix and add to it its transpose. 

Your answer is incorrect.

The correct answer is: When they have the form


A = I + S
and
B = I - S
where S is any matrix and I is the identity matrix.

Question 5 fprintf is...


Correct

Mark 1.00 out of Select one:


1.00
a. a matlab command to produce space efficient, machine readable output (i.e. not easily readable by humans but
requiring little disk space)

b. fprintf is a sophisticated mechanism to do anything from simple to complex formatting 

c. an old mechanism that will soon be replaced by disp

d. a quick and easy way to print matrices but with very limited formatting options

e. is one of the most successful ideas introduced by Matlab and its parent company.

Your answer is correct.

The correct answer is: fprintf is a sophisticated mechanism to do anything from simple to complex formatting

https://moodle.yorku.ca/moodle/mod/quiz/review.php?attempt=2415481&cmid=2181410 3/6
12/24/2019 Lab 3 (Thu): Attempt review

Question 6 disp is...


Correct

Mark 1.00 out of Select one:


1.00
a. the only way to show data on the screen that works on both Windows and Mac systems

b. a quick and simple mechanism to display data with a default (or no) formatting 

c. a command to save data in a file, just in case the computer crashes.

d. a mechanism to display images or video

e. a very sophisticated mechanism to display data that will replace the old and simplistic fprintf

Your answer is correct.

The correct answer is: a quick and simple mechanism to display data with a default (or no) formatting

Question 7 We can write formatted output to a file using


Correct

Mark 1.00 out of Select one:


1.00
a. Use fprintf like
fd = fopen('tryfile','w')
fprintf(fd,'The meaning of life is %f\n\n',42)
fclose(fd) 
b. The save command which saves and formats data in all kinds of different ways

c. The only way is cut and paste and clicking Save

d. The disp command as in


disp('myfile',47)

e. The disp command as in


disp('myfile.mat',47)

Your answer is correct.

The correct answer is: Use fprintf like


fd = fopen('tryfile','w')
fprintf(fd,'The meaning of life is %f\n\n',42)
fclose(fd)

Question 8 We want to create a vector V with 10 elements in which every element V[i] is equal to i squared. The code (script) that
Correct does this is
Mark 1.00 out of
1.00 Select one:
a. V = 1:10; V = V.^2; 

b. V = 1:10; V = V*V';

c. V = 1:10; V = V^2;

d. V = 1:10:10^2

e. V = 1:10; V = V'*V;

Your answer is correct.

The correct answer is: V = 1:10; V = V.^2;

https://moodle.yorku.ca/moodle/mod/quiz/review.php?attempt=2415481&cmid=2181410 4/6
12/24/2019 Lab 3 (Thu): Attempt review

Question 9 Which of the following Matlab scripts produces an identity matrix. To check if a matrix ID is an identity matrix take the
Correct norm of the difference of ID and an identity matrix of the same size, i.e. norm(ID-eye(3))
Mark 1.00 out of
1.00 Select one:
a. ID = rand(3)*inv(rand(3));

b. A = rand(3); ID = A*inv(A); 

c. A = rand(3); ID = A.*A^-1;

d. A = rand(3); ID = A*A';

e. A = rand(3); ID = A-A';

Your answer is correct.

The correct answer is: A = rand(3); ID = A*inv(A);

Question 10
We need to print the character % (percent) in a formatting print statement (like fprintf or sprintf). A simple way (but not
Incorrect
the best) to do it is to:
Mark 0.00 out of
1.00 (To answer this question copy an example from the provided material and modify it)

Select one:
a. To use %s (s stands for string) and provide an extra argument '%'

b. Write it as "percent" and matlab will replace it with %

c. Put % in double quotes 

d. To use an escape sequence \%

e. Use o/o (three characters) and matlab will replace it with the percent symbol.

Your answer is incorrect.


The correct answer is: To use %s (s stands for string) and provide an extra argument '%'

Question 11 According to the manual, the main difference between fprintf and sprintf is
Incorrect

Mark 0.00 out of Select one:


1.00
a. sprintf is the old version of fprintf

b. fprintf writes formatted data into a file or the command window and sprintf puts the formatted data into a string

c. fprintf is fast formatted print and sprintf is slow formatted print

d. fprintf is the old version of sprintf

e. fprintf writes formatted data to a file and sprintf writes formatted data to string or the command window 

Your answer is incorrect.


The correct answer is: fprintf writes formatted data into a file or the command window and sprintf puts the formatted data
into a string

https://moodle.yorku.ca/moodle/mod/quiz/review.php?attempt=2415481&cmid=2181410 5/6
12/24/2019 Lab 3 (Thu): Attempt review

Question 12
If fopen cannot open a file (filename mistyped, file does not exist in the current directory (folder), we have no permission
Correct
to open the file, etc) then:
Mark 1.00 out of
1.00 (HINT: to answer this question read the on-line manual and play with the code provided in the manual)

Select one:
a. fopen issues a standard matlab error (in scary red font) explaining the problem

b. The file will always be created if it does not exist and fopen always opens a file. It is the responsibility of the
programmer to make sure that the file is indeed what he intended.

c. fopen returns -1 and we know there is a problem and fix it. 

d. Errors involving fopen are rare.

e. We know that there is a problem because the next fprintf that uses the file descriptor returned by fopen fails

Your answer is correct.


The correct answer is: fopen returns -1 and we know there is a problem and fix it.

Question 13 Write a short script and name it Lab3XXXX.m where XXXX is your user ID, that writes a vector V in a file named XXXX.m where
Complete XXXX is again your user ID, in a format that can be read by Matlab. Vector V should be defined in your command window,
Mark 10.00 out not in the Lab3XXXX.m file.
of 12.00
Your script should open the file XXXX.m for writing, then write in the file
V1 = [

then write all the elements of the vector V as a comma separated list  and then write
];

and then close the file. Keep in mind that fprintf, if given a vector as argument it will write all the elements of the vector
by reusing the format string.If you need to find the number of elements of the vector V read the documentation for
function length.
To make sure your program works have a look in the file XXXX.m you created and then have Matlab read the XXXX.m file by
typing XXXX in the command window and then compare the vector V with vector V1 using the norm trick.
As always, your script should include a comment header with your name, date and a very brief description of (1-2 lines) of
the script.

Lab3jair2018.m

Comment:
there is a comma before the ]

◄ Lab 3 (Tue) Jump to... Lecture Notes and Examples ►

https://moodle.yorku.ca/moodle/mod/quiz/review.php?attempt=2415481&cmid=2181410 6/6

Potrebbero piacerti anche