machine exercises
TRANSCRIPT
-
8/11/2019 Machine Exercises
1/2
Chapter 3 Machine Exercises
Instructions: For each item, store the matrix/ices in any variable in MATLAB. Follow the instructions written on the
second column. For items with more than one instruction, do the next instruction on the result from the previous
instruction. You can write as many commands as you want, as long as the final matrix is displayed in the end. Yourcommands SHOULD APPLY GENERALLY to any matrix with the same size as the given matrix.
Given Matrix Instructions
1 [ ]Copy the elements from the first column to the second column. (Do
not assign new values)
2 [ ] Replace all the ones with threes.
3 [ ] Display the sum of the elements in the main diagonal.
4 [ ] Display the product of the elements in the 3rd
row only.
5 [ ]Display the matrix where the 3
rdcolumn is increased by 1. (Do not
assign new values)
6
[
]
Display the matrix where the main diagonal is increased by 2. (Do not
assign new values)
7 [ ]Display a 2-by-2 matrix whose elements are the corner elements of
the given matrix (preserve their positions).
8 [ ]Multiply the 1
strow by 4. Replace the 2
ndrow by the result of the [1
st
row minus the 2nd
row].
9 Display a matrix that looks like the given matrix rotated 90 degreescounterclockwise. (Do not assign new values)10
Concatenate the two vectors into one row vector.11 Move the last element to the position before the first element. (Do
not assign new values)
12 Store the product of the main-diagonal elements in X. Store theproduct of the off-diagonal elements in Y. Display XY.13 Replace all the negative elements with zeros.
-
8/11/2019 Machine Exercises
2/2
14 Display a 2-element vector containing only the first and last elementsof the given vector.
15 Display a 3-element vector containing the 5t to the last, 4t to thelast, and 3
rdto the last element of the given vector.
16 Display a vector containing all elements whose index is odd.17 Display the sum of the 10t to the 15t element.18 [ ] Interchange the 1
stand 2
ndcolumn.
19 [ ] Interchange the 1st
and 3rd
row.
20 Display the minimum absolute difference between two adjacent
elements.
21 Display the arithmetic mean of the elements.22 [ ]
Display a 9-by-9 matrix containing 9 copies of the given matrix in a 3-
by-3 configuration.
23 [ ]Display a 9-by-9 matrix of all zeros, except for the given matrix that
should be found in the middle.
24 [ ]Display a 9-by-9 matrix of all ones, except for the given matrix located
such that its first element is at row 5, column 3.
25 Display the same matrix but with the elements reversed.26 Display the same vector but with each element squared.27
Display the dot product of the two vectors.28 Convert each element from Kelvin to degrees Fahrenheit.29
Square the elements in the first half and cube the second half.
30 Divide all elements by the largest element (this is normalization).