Deleting elements
Adding elements
Adding elements
Adding elements
Some useful Array functions
find(A) Computes an array containing the indices of the
nonzero elements of A.
Some useful Array functions
Some useful Array functions
max(x)/min(x): returns the max/min value of the vector, or returns the max/min value of each column in a matix.
Some useful Array functions
Some useful Array functions
[m,l] = max(x)/min(x): returns the max/min values into m and their locations into l.
Some useful Array functions
size(x): returns the number of rows and number of columns of a matrix x.
sort(x): sorts each column of x.
Exercise
For the matrix B shown below, use MATLAB to (a) find the largest and smallest element in B and their indices and (b) find the array resulted from the operation B([1 2 1],[2 3])
Exercise
Exercise
Element-by-Element Operations
SymbolOperationFormExample
+/-Scalar-array addition/subtractionA +/- b[6 3] + 4 = [10 7]
Array-array addition/subtractionA +/- B [6 3] - [2 1] = [4 2]
.*Array-array multiplicationA .* B [3 9].*[4 1] = [12 9]
*Scalar-array multiplicationa*B3*[7 2] = [21 6]
./Array-array right division
Scalar-array right division
A./B
a./B
[5 2]./[10 1] = [0.5 2]
9./[3 9] = [3 1]
.\Array-array left division
Scalar-array left division
A.\B
a.\B
[5 2].\[10 1] = [2 0.5]
3.\[9 3] = [3 1]
/ or \Array-scalar divisionA/b or b\A[12 6]/3 = [4 2]
3\[12 6] = [4 2]
.^Array exponentiationA.^B
a.^B
B.^a
[2 3].^[3 2] = [8 9]
2.^[3 2] = [8 4]
[2 3].^2 = [4 9]
Vectors applications
A train is heading east at 60 m/h. A car is heading northeast at 45 m/h as shown. What is the velocity and speed of the train relative to the car?
Vectors applications
Example
The maximum height of an object thrown at angle θ is given by the Newton’s law as a function of the angle θ and the initial speed v:
Create a table showing the maximum height for the following values of v and θ
v = 10, 12, 14, 16, 18, 20 θ = 50°, 60°, 70°, 80°
g
vh
2
sin2
Example
Matrix Multiplication