Sie sind auf Seite 1von 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. Your
commands 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 3
rd
row only.

5 [



]
Display the matrix where the 3
rd
column 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
st
row by 4. Replace the 2
nd
row by the result of the [1
st

row minus the 2
nd
row].

9 [


]
Display a matrix that looks like the given matrix rotated 90 degrees
counterclockwise. (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 the
product of the off-diagonal elements in Y. Display X Y.

13 [

] Replace all the negative elements with zeros.

14 [

]
Display a 2-element vector containing only the first and last elements
of the given vector.

15 [

]
Display a 3-element vector containing the 5
th
to the last, 4
th
to the
last, and 3
rd
to the last element of the given vector.

16 [

] Display a vector containing all elements whose index is odd.

17 [

] Display the sum of the 10
th
to the 15
th
element.

18 [



] Interchange the 1
st
and 2
nd
column.

19 [



] Interchange the 1
st
and 3
rd
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).

Das könnte Ihnen auch gefallen