+ All Categories
Home > Documents > [email protected] ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25:...

[email protected] ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25:...

Date post: 13-Jan-2016
Category:
Upload: franklin-blair
View: 216 times
Download: 0 times
Share this document with a friend
55
[email protected] • ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical & Mechanical Engineer [email protected] Engr/Math/Physics 25 Chp2 MATLAB Arrays: Part-1
Transcript
Page 1: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt1

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Bruce Mayer, PELicensed Electrical & Mechanical Engineer

[email protected]

Engr/Math/Physics 25

Chp2 MATLABArrays: Part-1

Page 2: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt2

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Learning Goals

Learn to Construct 1-Dimensional Row and Column Vectors

Create MULTI-Dimensional ARRAYS and MATRICES

Perform Arithmetic Operations on Vectors and Arrays/Matrices

Analyze Polynomial Functions

Page 3: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt3

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Position Vector The vector p can be

specified by three components: x, y, and z, and can be written as:

zyxzyx ,,or pkjip• Where i, j, k are

UNIT-Vectors Which are|| To The CoOrd Axes

MATLAB can accommodate Vectors having more than 3 Elements• See MATH6 for more info on “n-Space”

Page 4: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt4

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

ROW & COLUMN Vectors

To create a ROW vector, separate the elements by COMMAS

Use the Transpose operator (‘) to make a COLUMN Vector

9,7,3p Create Col-Vector Directly with SEMICOLONS

>>p = [3,7,9]p = 3 7 9

The TRANSPOSE Operation Swaps Rows↔Columns

>>p = [3,7,9]'p = 3 7 9

9

7

3

p

>>g = [3;7;9]g = 3 7 9

Page 5: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt5

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

“Appending” Vectors

Can create a NEW vector by ''appending''

one vector to another e.g.; to create the row vector u whose

first three columns contain the values of r = [2,4,20] and whose 4th, 5th, & 6th columns contain the values of w = [9,-6,3]• Typing u = [r,w] yields vector u = [2,4,20,9,-6,3]

>> r = [2,4,20]; w = [9,-6,3];>> u = [r,w]u = 2 4 20 9 -6 3

Page 6: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt6

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Colon (:) Operator

The colon operator (:) easily generates a large vector of regularly spaced elements.

Typing >>x = [m:q:n]• creates a vector x of values with a spacing q. The first value is m. The last value is n IF m - n is an integer multiple of q. IF NOT, the last value is LESS than n.

>> p = [0:2:8]p = 0 2 4 6 8>> r = [0:2:7]r = 0 2 4 6

Page 7: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt7

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Colon (:) Operator cont.

To create a row vector z consisting of the values from 5 to 8 in steps of 0.1, type z = [5:0.1:8].

If the increment q is OMITTED, it is taken as the DEFAULT Value of +1. >> s =[-11:-6]s = -11 -10 -9 -8 -7 -6>> t = [-11:1:-6]t = -11 -10 -9 -8 -7 -6

Page 8: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt8

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

linspace Comand

The linspace command also creates a linearly spaced row vector, but instead you specify the number of values rather than the increment

The syntax is linspace(x1,x2,n), where x1 and x2 are the lower and upper limits and n is the number of points• If n is omitted, then it Defaults to 100

Thus EQUIVALENT statements>> linspace(5,8,31) = >>[5:0.1:8]

Page 9: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt9

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

logspace Comand

The logspace command creates an array of logarithmically spaced elements

Its syntax is logspace(a,b,n), where n is the number of points between 10a and 10b

For example, x = logspace(-1,1,4) produces the vector x = [0.1000, 0.4642, 2.1544, 10.000]

>> x = logspace(-1,1,4); >> y = log10(x)y = -1.0000 -0.3333 0.3333 1.0000

11121110 10,,10,10,10 nabnanabanabanabax

13

1

3

11 10,10,10,10x

If n is omitted, the no. of pts defaults to 50

Page 10: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt10

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

logspace Example

Consider this command>> y =logspace(-1,2,6)y = 0.1000 0.3981 1.5849 6.3096 25.1189 100.0000

Calculate the Power of 10 increment

1 nabp

In this case

6.053

1612

p

110 kpaky

In this Casek Power yk

1 -1 0.1000

2 -0.4 0.3981

3 0.2 1.5849

4 0.8 6.3096

5 1.4 25.1189

6 2 100.0000

for k = 1→6, then the kth y-value

Page 11: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt11

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

logspace Example (alternative)

Consider this command>> y =logspace(-1,2,6)y = 0.1000 0.3981 1.5849 6.3096 25.1189 100.0000

Take base-10 log of the above

Calc Spacing Between Adjacent Elements with diff command

>> yLog10 = log10(y)yLog10 = -1.0000 -0.4000 0.2000 0.8000 1.4000 2.0000

>> yspc = diff(yLog10)yspc = 0.6000 0.6000 0.6000 0.6000 0.6000

5316121 nabp

Page 12: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt12

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Vector: Magnitude, Length, and Absolute Value Keep in mind the precise meaning of

these terms when using MATLAB• The length command gives the number

of elements in the vector• The magnitude of a vector x having

elements x1, x2, …, xn is a scalar, given by √(x1

2 + x22 + … + xn

2), and is the same as the vector's geometric length

• The absolute value of a vector x is, in MATLAB, a vector whose elements are the arithmetic absolute values of the elements of x

Page 13: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt13

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Mag, Length, and Abs-Val

Geometric Length

By Pythagoras Find vector a magnitude

2222

222

222 and

zyxa

zwa

yxw

so

222 zyxa

Thus the box diagonal

>> a =[2,-4,5]; >> length(a)ans = 3>> % the Magnitude M = norm(a)>> Mag_a = norm(a)Mag_a = 6.7082 >> abs(a)ans = 2 4 5

Page 14: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt14

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

3D Vector Length Example% Bruce Mayer * ENGR36% 25Aug09 * Lec03% file = VectorLength_0908.m% NOTE: using “norm” command is much easier%% Find the length of a Vector AB with%% tail CoOrds = (0, 0, 0)%% tip CoOrds = (2, 1, -5)%% Do Pythagorus in stepsvAB = [2 1 -5] % define vectorsqs = vAB.*vAB % sq each CoOrdsum_sqs = sum(sqs) % Add all sqsLAB = sqrt(sum_sqs) % Take SQRT of the sum-of-sqs

Page 15: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt15

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

3D Vector Length Example - RunvAB = 2 1 -5

sqs = 4 1 25

sum_sqs = 30

LAB = 5.4772

% Bruce Mayer * ENGR36% 25Aug09 * Lec03% file = VectorLength_0908.m%% Find the length of a Vector AB with%% tail CoOrds = (0, 0, 0)%% tip CoOrds = (2, 1, -5)%% Do Pythagorus in stepsvAB = [2 1 -5] % define vectorsqs = vAB.*vAB % sq each CoOrdsum_sqs = sum(sqs) % Add all sqsLAB = sqrt(sum_sqs) % Take SQRT of the sum-of-sqs

Page 16: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt16

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Matrices/Arrays

A MATRIX has multiple ROWS and COLUMNS. For example, the matrix M:

15123

948

7316

1042

M

VECTORS are SPECIAL CASES of matrices having ONE ROW or ONE COLUMN.

M contains• FOUR rows• THREE columns

Page 17: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt17

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Making Matrices

For a small matrix you can type it row by row, separating the elements in a given row with spaces or commas and separating the rows with semicolons. For example, typing

7316

1042A

spaces or commas separate elements in different columns, whereas semicolons separate elements in different rows.

The Command• >>A = [2,4,10;16,3,7];

Generates Matrix

Page 18: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt18

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Making Matrices from Vectors

Given Row Vectors: r = [1,3,5] and s = [7,9,11]

Combine these vectors to form vector-t and Matrix-D

>> r = [1,3,5]; s = [7,9,11];>> t = [r s]t = 1 3 5 7 9 11>> D = [r;s]D = 1 3 5 7 9 11

Note the difference between the results given by [r s](or [r,s]) and [r;s]

Page 19: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt19

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Directly Make Matrix

Use COMMAS/SPACES combined with SEMICOLONS to Construct Matrices

>> D = [[1,3,5]; [7 9 11]]D = 1 3 5 7 9 11

Note the use of • BOTH Commas and Spaces as

COLUMN-Separators• The SEMICOLON as the ROW-Separator

Page 20: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt20

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Make M

atrix Exam

ple

>> r1 = [1:5]

r1 = 1 2 3 4 5

>> r2 = [6:10]

r2 = 6 7 8 9 10

>> r3 = [11:15]r3 = 11 12 13 14 15

>> r4 = [16:20]r4 = 16 17 18 19 20

>> r5 = [21:25]r5 =

21 22 23 24 25>> A = [r1;r2;r3;r4;r5]

A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

Page 21: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt21

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Array Addressing The COLON operator SELECTS

individual elements, rows, columns, or ''subarrays'' of arrays. Some examples:• v(:) represents all the row or column

elements of the vector v• v(2:5) represents the 2nd thru 5th

elements; that is v(2), v(3), v(4), v(5). • A(:,3) denotes all the row-elements in the

third column of the matrix A.• A(:,2:5) denotes all the row-elements in

the 2nd thru 5th columns of A.• A(2:3,1:3) denotes all elements in the

2nd & 3rd rows that are also in the 1st thru 3rd columns.  

Page 22: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt22

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Array Extraction You can use array indices to extract a

smaller array from another array. For example, if you first create the array B

1715123

25948

187316

131042

B

to Produce SubMatrix C type C = B(2:3,1:3)

Rows 2&3 Cols 1-3

948

7316C

Page 23: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt23

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Array Extraction ExampleA = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

>> C = A(3:5,2:5)C = 12 13 14 15 17 18 19 20 22 23 24 25

Page 24: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt24

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Matrix Commands

Command Description

[u,v,w] = find(A)

Computes the arrays u and v, containing the row and column indices of the NONzero elements of the matrix A, and the array w, containing the values of the nonzero elements. The array w may be omitted.

length(A)Computes either the number of elements of A if A is a vector or the largest value of m or n if A is an m × n matrix.

size(A)Returns a row vector [m n] containing the sizes of the m x n array A.

Page 25: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt25

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Matrix Commands cont

Command Description

max(A)

* Returns the algebraically largest element in A if A is a VECTOR.* Returns a row vector containing the largest elements in each Column if A is a MATRIX.* If any of the elements are COMPLEX, max(A) returns the elements that have the largest magnitudes.

[x,k] = max(A)

Similar to max(A) but stores the maximum values in the row vector x and their indices in the row vector k.

Page 26: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt26

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Matrix Commands cont

Command Descriptionmin(A) and

[x,k] = min(A)

Like max but returns minimum values.

sort(A)Sorts each column of the array A in ascending order and returns an array the same size as A.

sum(A)Sums the elements in each column of the array A and returns a row vector containing the sums.

Page 27: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt27

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Examples: Matrix Commands

Given Matrix A

73

510

26

A

>> A = [[6,2]; [-10,5]; [3,7]];

>> size(A)ans = 3 2

>> length(A)ans = 3

>> max(A)ans = 6 7

>> min(A)ans = -10 2

Page 28: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt28

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

WorkSpace Browser

Allows DIRECT access to Variables for editing & changing

Page 29: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt29

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Array Editor

Permits changing of a single Array Valuewithout retyping the entire specification

Page 30: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt30

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

MultiDimensional (3) Arrays

3D (or more-D) Arrays Consist of two-dimensional arrays that ar “layered” to produce a third dimension. • Each “layer” is called a page.

3D pg1 pg2 pg3 pg4

Command Description

cat(n,A,B,C, ...)Creates a new array by concatenating the arrays A,B,C, and so on along the dimension n.

Page 31: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt31

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Vectors Digression

VECTOR Parameter Possessing Magnitude And Direction, Which Add AccordingTo The Parallelogram Law • Examples: Displacements,

Velocities, Accelerations

SCALAR Parameter Possessing Magnitude But Not Direction • Examples: Mass, Volume, Temperature

Vector Classifications• FIXED or BOUND Vectors Have Well

Defined Points Of Application That CanNOT Be Changed Without Affecting An Analysis

Page 32: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt32

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Vectors cont.• FREE Vectors May Be Moved In Space

Without Changing Their Effect On An Analysis

• SLIDING Vectors May Be Applied Anywhere Along Their Line Of Action Without Affecting the Analysis

• EQUAL Vectors Have The Same Magnitude and Direction

• NEGATIVE Vector Of a Given Vector Has The Same Magnitude but The Opposite Direction

Equal Vectors

Negative Vectors

Page 33: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt33

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Vector Addition

Parallelogram Rule For Vector Addition

Examine Top & Bottom ofThe Parallelogram• Triangle Rule For

Vector Addition

B

B

C

C

QPQP

PQQP • Vector Addition is

Commutative

• Vector Subtraction →Reverse Direction ofThe Subtrahend

Page 34: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt34

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Vector Addition cont.

Addition Of Three Or MoreVectors Through RepeatedApplication Of The Triangle Rule

The Polygon Rule ForThe Addition Of ThreeOr More Vectors• Vector Addition Is Associative SQP

Multiplication by a Scalar• Scales the Vector LENGTH

SQPSQP

Page 35: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt35

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Vector Notation

In Print and Handwriting We Must Distinguish Between• VECTORS• SCALARS

These are Equivalent Vector NotationsPPP P

• Boldface Preferred for Math Processors• Over Arrow/Bar Used for Handwriting• Underline Preferred for Word Processor

Page 36: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt36

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Dot Product of 2 Vectors

The SCALAR PRODUCT or DOT PRODUCT Between TwoVectors P and Q Is Defined As

resultscalarcosPQQP

PQQP

2121 QPQPQQP

undefined SQP

Scalar-Product Math Properties• ARE Commutative• ARE Distributive• Are NOT Associative

– Undefined as (P•S) is NO LONGER a Vector

Page 37: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt37

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Scalar Product – Cartesian Comps

Scalar Products With Cartesian Components

000

111

ikkjji

kkjjii

kQjQiQkPjPiPQP zyxzyx

2222 PPPPPP

QPQPQPQP

zyx

zzyyxx

MATLAB Makes this Easy with the dot(p,q) Command

>> p = [13,-17,-7]; q = [-16,5,23];>> pq = dot(p,q)pq = -454>> qp = dot(q,p)qp = -454>> r = [1 3 5 7]; t = [8,6,4,2];>> rt = dot(r,t)rt = 60

Page 38: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt38

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Cross Product

TWISTING Power of a Force MOMENTof the Force• Quantify Using VECTOR

PRODUCT or CROSS PRODUCT Vector Product Of Two Vectors

P and Q Is Defined as TheVector V Which Satisfies:• Line of Action of V Is Perpendicular To the

Plane Containing P and Q.• |V| =|P|•|Q|•sinθ• Rt Hand Rule Determines Line of Action for V

Page 39: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt39

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Vector Product Math Properties

Recall Vector ADDITION Behaved As Algebraic Addition

– BOTH Commutative and Associative.

The Vector PRODUCT Math-Properties do NOT Match Algebra. Vector Products• Are NOT Commutative• Are NOT Associative• ARE Distributive

veDistributi

tiveNONassocia

tiveNONcommuta

2121 QPQPQQP

SQPSQP

QPQPPQ

QP

PQ

Page 40: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt40

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Vector Prod: Rectangular Comps Vector Products Of Cartesian Unit

Vectors

0

0

0

kkikjjki

ijkjjkji

jikkijii

kQjQiQkPjPiPQPV zyxzyx

kQPQPjQPQPiQPQP xyyxzxxzyzzy

zyx

zyx

QQQ

PPP

kji

QP

Vector Products In Terms Of Rectangular Coordinates

• Summarize UsingDeterminateNotation

Page 41: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt41

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

cross command

3D Vector (Cross) product Evaluation is Painful• c.f. last Slide

MATLAB makes it easy with the cross(p,q) command• The two Vectors

MUST be 3 Dimensional

>> p = [13,-17,-7]; >> q = [-16,5,23];>> pxq = cross(p,q)pxq = -356 -187 -207>> qxp = cross(q,p)qxp = 356 187 207

Page 42: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt42

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Array Addition and Subtraction

Add/Subtract Element-by-Element

>> A = [6,-2;10,3];>> B = [9,8;-12,14];>> A+Bans = 15 6 -2 17

172

615

1412

89

310

26

16528194113917

BA

qp

>> p = [17 -9 3];>> q = [-11,-4,19];>> p-qans = 28 -5 -16

Using MATLAB

Page 43: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt43

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Example 2.3-2

55’

36’

z = Down

y = Nx = W25’

r

-20’

59’20’w

−r

v = w−r

222 253655

253655

r

kjir

k

jiv

rwrwv

2520

36595520

)(

Page 44: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt44

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Example 2.3-2 cont

z = Down

y = Nx = W

r

w -r

v = w-r

>> r = [55,36,25]; w = [-20,59,15];>> b = r.*rb = 3025 1296 625>> c = sum(b)c = 4946>> dist1 = sqrt(c)dist1 = 70.3278

>> v = w-rv = -75 23 -10>> dist2 = sqrt(sum(v.*v))dist2 = 79.0822

Page 45: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt45

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

CAVEAT

2D arrays are described as ROWS x COLUMNS• Elemement of D(2,5)

– 2 → ROW-2– 5 → COL-5

ROW Vector → COMMAS

COL Vector → SemiColons

>> r = [4,73,17]r = 4 73 17

>> c = [13;37;99]c = 13 37 99

Page 46: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt46

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Caveat cont

Array operations often CONCATENATE or APPEND• This Can Occur unexpectedly• Use the clear command to start from

scratch

concatenatecon·cat·e·nate ( P ) Pronunciation Key (kn-ktn-t, kn-)tr.v. con·cat·e·nat·ed, con·cat·e·nat·ing, con·cat·e·nates 1. To connect or link in a series or chain. 2. Computer Science. To arrange (strings of characters) into a chained list. adj. (-nt, -nt)3. Connected or linked in a series.

Page 47: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt47

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

All Done for Today

Matrix Multiplication • Explained in Fine

Detail in MATH6• Some UseFul Links

Next Time:More ArrayOperations – http://www.mai.liu.se/~halun/

matrix/matrix.html– http://people.hofstra.edu/

faculty/Stefan_Waner/RealWorld/tutorialsf1/frames3_2.html

– http://calc101.com/webMathematica/matrix-algebra.jspMatrix Multiplication

Page 48: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt48

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Bruce Mayer, PELicensed Electrical & Mechanical Engineer

[email protected]

Engr/Math/Physics 25

Appendix-1

Vector Math

Page 49: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt49

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Rectangular Force Components

Using Rt-Angle Parallelogram Resolve F into Perpendicular Components yx FFF

yxyx FF jiFFF

Define Perpendicular UNIT Vectors Which Are Parallel To The Axes

Vectors May then Be Expressed As Products Of The Unit VectorsWith The SCALAR MAGNITUDESOf The Vector Components

Page 50: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt50

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Adding by Components

Find: Resultant of 3+ ForcesSQPR

yyyxxx

yxyxyxyx

SQPSQP

SSQQPPRR

ji

jjjijiji

Plan: • Resolve Each Force Into Components• Add LIKE Components To Determine

Resultant• Use Trig to Fully Describe Resultant

Page 51: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt51

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Adding by Comp. cont.

The Scalar Components Of The Resultant Are Equal To The Sum Of The Corresponding Scalar Components Of The Given Forces

yyyyy

xxxxx

FSQPR

FQPPR

x

yyx R

RRRR 122 tan

Use The Scalar Components Of The Resultant to Find the Resultant Magnitude & Direction By Trig

Page 52: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt52

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

3D Rectangular Components

Resolve Fh into rectangular components

Resolve F into horizontal and vertical components.

yh

yy

FF

FF

F

sin

cos

F

sinsin

sin

cossin

cos

y

hz

y

hx

F

FF

F

FF

The vector F is contained in the plane OBAC.

Page 53: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt53

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

3D Rectangular Comp. cont.

kjiλ

λ

kji

kjiF

zyx

zyx

zyx

zzyyxx

F

F

FFF

FFFFFF

coscoscos

coscoscos

coscoscos

With the angles between F and the axes

is a UNIT VECTOR along the line of action of F, and cosx, cosy, and cosz, are the DIRECTION COSINES for F

Page 54: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt54

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

2-Pt Direction Cosines Consider Force, F,

Directed Between Pts• M(x1,y1,z1)

• N(x2,y2,z2)

The Vector MN Joins These Points with Scalar Components dx, dy, dz

d

d

d

d

d

d

d

FdF

d

FdF

d

FdF

dddd

F

dddd

zz

yy

xx

zz

yy

xx

zyx

zyx

coscoscos

1

222

kjiλF

d

12

1212

zzd

yydxxd

dddMN

z

yx

zyx

kjid

Page 55: BMayer@ChabotCollege.edu ENGR-25_Arrays-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.

[email protected] • ENGR-25_Arrays-1.ppt55

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

Bruce Mayer, PELicensed Electrical & Mechanical Engineer

[email protected]

Engr/Math/Physics 25

AppendixLive Demo


Recommended