Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Dashboard / My courses / LE/EECS1560 A - Introduction to Computing for Mathematics and Statistics (Fall 2019-2020) / Lab 3 Material
/ Lab 3 (Thu)
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.
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 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. (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
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.
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
HINT: To create a symmetric matrix, create a random matrix and add to it its transpose.
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.
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
b. a quick and simple mechanism to display data with a default (or no) formatting
e. a very sophisticated mechanism to display data that will replace the old and simplistic fprintf
The correct answer is: a quick and simple mechanism to display data with a default (or no) formatting
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;
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';
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 '%'
e. Use o/o (three characters) and matlab will replace it with the percent symbol.
Question 11 According to the manual, the main difference between fprintf and sprintf is
Incorrect
b. fprintf writes formatted data into a file or the command window and sprintf puts the formatted data into a string
e. fprintf writes formatted data to a file and sprintf writes formatted data to string or the command window
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.
e. We know that there is a problem because the next fprintf that uses the file descriptor returned by fopen fails
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 ]
https://moodle.yorku.ca/moodle/mod/quiz/review.php?attempt=2415481&cmid=2181410 6/6