Sei sulla pagina 1di 2

Recitation Problems Week 3

440:127 Fall 2015 N. B. Mandayam and S. Khan


Please do the following drill problems on matrix properties during your recitation session, including any additional
problems given to you by your TA. Upload your completed work within 48hrs of your recitation session. Please follow
3. Try statement below, see what these
your TAs instructions on how and where to upload your files.
1. Consider the following 3 4 matrix and define it in MATLAB:
Hint:
2
3
1.You have to create names for each problems' result.
8 1 6 5
2. For problems that may change your original A,define a matrix A = 4 5 4 5 8 5
B which equal to A to preserve your A matrix, so that you will get
3 7 2 2
the right result for next problems.

statements do to the matrix A.


A([2,3],[2,3,4])
A(:,[2,4])
A([1,3],:)
A([2:1:3],[2:1:4])
A([3,1,2],[2,4,1,3])

Using appropriate MATLAB functions do the following, each with a single MATLAB command:
a. Determine the minima of the columns and their locations. Then, determine the minima of the rows and their
locations without transposing the matrix. Then, repeat for the maxima of the columns and rows.
b. Compute the column means. Compute the row means without transposing the matrix. Compute the column
sums; then, the row sums. Compute the column products; then, the row products.
c. Apply the functions cumsum, cumprod, and di on the matrix A column-wise, and then apply them on
A, row-wise.
d. Sort A column-wise in decreasing order. Sort A row-wise in increasing order.
e. Replace by zeros the 22 submatrix defined at the intersection of the second and third columns and the
second and third rows of A.
f. Flip the matrix A upside-down. Then, flip A left-right. Combine the previous two operations into one that
Combine these two operations do not necessarily
flips A both upside-down and left-right.
mean that only one command is used

g. Replace the main diagonal (i.e., the A11 , A22 , . . . , matrix elements) by zeros. Replace all elements of A by
Pay attention to 'diag' functions output
zeros except for its elements in the upper-left 22 submatrix.
when input has different dimensions

h. Swap the second and fourth columns of A. Swap the first and third rows of A.

i. Rearrange A into a 26 matrix whose elements in each column are taken column-wise from those of A.
Similarly, reshape A into a 43 matrix and compare it with the transpose of A. Then, reshape A into a 62
matrix. Finally, reshape A into a 223 three-dimensional array.
j. Using the function repmat, replicate A three times horizontally. Replicate A two times vertically. Replicate
A three times horizontally and two times vertically. Re-do these replications without the use of repmat,
just by appropriately concatenating A with itself.
k. What do the commands, A==5, and, q = find(A==5), do? With one command, replace all the entries
of A that are equal to 5 by the value of 50. Then, with another single command restore their values back to
5.
l. Insert the row vector [10, 20, 30, 40] between rows 2 and 3 of the matrix A without re-typing the matrix
elements of A. Insert the column [10; 20; 30] between columns 2 and 3 of the matrix A.
m. Delete simultaneously the third column of A and its second row (without re-typing any matrix elements).
2. Consider the windchill temperature example discussed on pp. 50-52 of the week-3 lecture slides. Modify the
given code appropriately, and using only four fprintf commands, generate a printed output that looks exactly
as that shown below:

V
10
20
30
40
50
60

temperature (F)
|
50
40
30
20
10
0
-10
-20
-30
-----------------------------------------------------|
46
34
21
9
-4
-16
-28
-41
-53
|
44
30
17
4
-9
-22
-35
-48
-61
|
42
28
15
1
-12
-26
-39
-53
-67
|
41
27
13
-1
-15
-29
-43
-57
-71
|
40
26
12
-3
-17
-31
-45
-60
-74
|
39
25
10
-4
-19
-33
-48
-62
-76

Next, modify the code again to print the results excatly as shown below using only four fprintf commands:

F
-30
-20
-10
0
10
20
30
40
50

When it says fprintf only, that means you could not use repmat

wind speed (mph)


|
10
20
30
40
50
60
------------------------------------| -53
-61
-67
-71
-74
-76
| -41
-48
-53
-57
-60
-62
| -28
-35
-39
-43
-45
-48
| -16
-22
-26
-29
-31
-33
|
-4
-9
-12
-15
-17
-19
|
9
4
1
-1
-3
-4
|
21
17
15
13
12
10
|
34
30
28
27
26
25
|
46
44
42
41
40
39

Potrebbero piacerti anche