deleting elements. adding elements some useful array functions find(a) computes an array containing...

19
Deleting elements

Post on 20-Dec-2015

224 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Deleting elements. Adding elements Some useful Array functions find(A)  Computes an array containing the indices of the nonzero elements of A

Deleting elements

Page 2: Deleting elements. Adding elements Some useful Array functions find(A)  Computes an array containing the indices of the nonzero elements of A

Adding elements

Page 3: Deleting elements. Adding elements Some useful Array functions find(A)  Computes an array containing the indices of the nonzero elements of A

Adding elements

Page 4: Deleting elements. Adding elements Some useful Array functions find(A)  Computes an array containing the indices of the nonzero elements of A

Adding elements

Page 5: Deleting 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

find(A) Computes an array containing the indices of the

nonzero elements of A.

Page 6: Deleting 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

Page 7: Deleting 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

max(x)/min(x): returns the max/min value of the vector, or returns the max/min value of each column in a matix.

Page 8: Deleting 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

Page 9: Deleting 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

[m,l] = max(x)/min(x): returns the max/min values into m and their locations into l.

Page 10: Deleting 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

size(x): returns the number of rows and number of columns of a matrix x.

sort(x): sorts each column of x.

Page 11: Deleting elements. Adding elements Some useful Array functions find(A)  Computes an array containing the indices of the nonzero elements of A

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])

Page 12: Deleting elements. Adding elements Some useful Array functions find(A)  Computes an array containing the indices of the nonzero elements of A

Exercise

Page 13: Deleting elements. Adding elements Some useful Array functions find(A)  Computes an array containing the indices of the nonzero elements of A

Exercise

Page 14: Deleting elements. Adding elements Some useful Array functions find(A)  Computes an array containing the indices of the nonzero elements of A

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]

Page 15: Deleting elements. Adding elements Some useful Array functions find(A)  Computes an array containing the indices of the nonzero elements of A

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?

Page 16: Deleting elements. Adding elements Some useful Array functions find(A)  Computes an array containing the indices of the nonzero elements of A

Vectors applications

Page 17: Deleting elements. Adding elements Some useful Array functions find(A)  Computes an array containing the indices of the nonzero elements of A

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

Page 18: Deleting elements. Adding elements Some useful Array functions find(A)  Computes an array containing the indices of the nonzero elements of A

Example

Page 19: Deleting elements. Adding elements Some useful Array functions find(A)  Computes an array containing the indices of the nonzero elements of A

Matrix Multiplication