75
5. Math 1 Agenda 1. Tools 2. Matrices 3. Least squares 4. Propagation of variances 5. Geometry

5. Math1 Agenda r 1. Tools r 2. Matrices r 3. Least squares r 4. Propagation of variances r 5. Geometry

Embed Size (px)

Citation preview

5. Math 1

Agenda

1. Tools 2. Matrices 3. Least squares 4. Propagation of variances 5. Geometry

5. Math 2

1. Tools

ExcelMatlabMathcadLabview

1. Tools

5. Math 3

Excel

SpreadsheetReadily availableSolver functions

1. Tools

5. Math 4

Matlab

Matrix basedPowerful analytical toolHandles transforms wellEasy to program

1. Tools

5. Math 5

Mathcad

Mathematical toolEvolving into handling transfer functionsHas special programming languageDocumentation closer to real math

1. Tools

5. Math 6

Labview

Powerful analysis toolUses graphical language to translate

concepts into C-code and then execute

1. Tools

5. Math 7

2. Matrices (1 of 2)

AdditionSubtractionMultiplicationVector, dot product, & outer productTransposeDeterminant of a 2x2 matrixCofactor and adjoint matricesDeterminantInverse matrix

2. Matrices

5. Math 8

Matrices (2 of 2)

Orthogonal matrixHermetian matrixUnitary matrix

2. Matrices

5. Math 9

Addition (1 of 2)

cIJ = aIJ + bIJcIJ = aIJ + bIJ

1 -1 0-2 1 -3 2 0 2

1 -1 -1 0 4 2-1 0 1

A= B=

2 -2 -1 -2 5 -1 1 0 3

C=

C=A+B

2. Matrices

5. Math 10

Addition (2 of 2)

Matrix addition using ExcelMatrix addition using Excel

2. Matrices

A + B = C1 -1 0 1 -1 -1 2 -2 -1-2 1 -3 0 4 2 -2 5 -12 0 2 -1 0 1 1 0 3

1. Highlight area for answer2. Type "="3. Highlight area of first matrix4. Type "+"5. Highlight area for second matrix6. Type CTL+SHIFT+ENTER

5. Math 11

Subtraction (1 of 2)

cIJ = aIJ - bIJcIJ = aIJ - bIJ

1 -1 0-2 1 -3 2 0 2

1 -1 -1 0 4 2-1 0 1

A= B=

0 0 1 -2 -3 -5 3 0 1

C=

C=A-B

2. Matrices

5. Math 12

Subtraction (2 of 2)

Matrix subtraction using ExcelMatrix subtraction using Excel

2. Matrices

A - B = C1 -1 0 1 -1 -1 0 0 1-2 1 -3 0 4 2 -2 -3 -52 0 2 -1 0 1 3 0 1

1. Highlight area for answer2. Type "="3. Highlight area of first matrix4. Type "-"5. Highlight area for second matrix6. Type CTL+SHIFT+ENTER

5. Math 13

Multiplication (1 of 2)

cIJ = aI1 * b1J + aI2 * b2J + aI3 * b3J cIJ = aI1 * b1J + aI2 * b2J + aI3 * b3J

1 -1 0-2 1 -3 2 0 2

1 -1 -1 0 4 2-1 0 1

A= B=

1 -5 -3 1 6 1 0 -2 0

C=

C=A*B

2. Matrices

5. Math 14

Multiplication (2 of 2)

Matrix multiplication using ExcelMatrix multiplication using Excel

2. Matrices

A * B = C1 -1 0 1 -1 -1 1 -5 -3-2 1 -3 0 4 2 1 6 12 0 2 -1 0 1 0 -2 0

1. Highlight area for answer2. Type "= MMULT(", or use INSERT FUNCTION3. Highlight area of first matrix4. Type ","5. Highlight area for second matrix6. Type CTL+SHIFT+ENTER

5. Math 15

Transpose (1 of 3)

bIJ = aJIbIJ = aJI

1 -1 0-2 1 -3 2 0 2

1 -2 2 -1 1 0 0 -3 2

A= B=

B=AT

2. Matrices

5. Math 16

Transpose (2 of 3)

Matrix transpose using ExcelMatrix transpose using Excel

2. Matrices

A A-transpose1 -1 0 1 -2 2-2 1 -3 -1 1 02 0 2 0 -3 2

1. Highlight area for answer2. Type "= TRANSPOSE(", or use INSERT FUNCTION3. Highlight area of matrix4. Type CTL+SHIFT+ENTER

5. Math 17

Transpose (3 of 3)

(AB)T = BT AT

1 -1 0-2 1 -3 2 0 2

1 -1 -1 0 4 2-1 0 1

A= B= 1 1 0 -5 6 -2 -3 1 0

(AB)T =

1 -2 2-1 1 0 0 -3 2

1 0 -1 -1 4 0 -1 2 1

AT = BT = BTAT = 1 1 0 -5 6 -2 -3 1 0

2. Matrices

5. Math 18

Vector, dot & outer products (1 of 2)

A vector v is an N x 1 matrixDot product = inner product = vT x v = a

scalarOuter product = v x vT = N x N matrix

2. Matrices

5. Math 19

Vector, dot & outer products (2 of 2)

Matrix inner and outer products using ExcelMatrix inner and outer products using Excel

2. Matrices

inner outerv v' v'*v v*v'1 1 2 3 14 1 2 32 2 4 63 3 6 9

5. Math 20

Determinant of a 2x2 matrix

2x2 determinant = b11 * b22 - bI2 * b212x2 determinant = b11 * b22 - bI2 * b21

B = 1 -1-2 1

= -1

2. Matrices

5. Math 21

Cofactor and adjoint matrices

1 -1 0-2 1 -3 2 0 2

A=

1 -3 0 2

-1 0 0 2

-1 0 0 -3

-2 -3 2 2

1 0 2 2

1 0-2 -3

-2 1 2 0

1 -1 2 0

1 -1-2 1

2 -2 -22 2 -23 3 -1

=B = cofactor =

2 2 3-2 2 3-2 -2 -1

C=BT = adjoint=

2. Matrices

-

- -

-

5. Math 22

Determinant 1 -1 0-2 1 -3 2 0 2

determinant of A =

The determinant of A = dot product of any row in A times the corresponding column in the adjoint matrix =

dot product of any row (or column) in A timesthe corresponding row (or column) in the cofactor matrix

The determinant of A = dot product of any row in A times the corresponding column in the adjoint matrix =

dot product of any row (or column) in A timesthe corresponding row (or column) in the cofactor matrix

1 -1 0

=4

2-2-2

= 4

2. Matrices

5. Math 23

Inverse matrix (1 of 3)

B = A-1 =adjoint(A)/determinant(A) = 0.5 0.5 0.75-0.5 0.5 0.75-0.5 -0.5 -0.25

1 -1 0-2 1 -3 2 0 2

0.5 0.5 0.75-0.5 0.5 0.75-0.5 -0.5 -0.25

1 0 00 1 00 0 1

=

2. Matrices

InverseInverse

5. Math 24

Inverse matrix (2 of 3)

Matrix inverse using ExcelMatrix inverse using Excel

2. Matrices

A inv(A)1 -1 0 0.5 0.5 0.75-2 1 -3 -0.5 0.5 0.752 0 2 -0.5 -0.5 -0.25

1. Highlight area for answer2. Type "= MINVERSE(", or use INSERT FUNCTION3. Highlight area of matrix4. Type CTL+SHIFT+ENTER

5. Math 25

Inverse matrix (3 of 3)(AB)-1 = B-1 A-1

1 -1 0-2 1 -3 2 0 2

1 -1 -1 0 4 2-1 0 1

A= B= 0.25 0.75 1.625 0 0 -0.5 -0.25 0.35 1.375

(AB)-1 =

0.5 0.5 0.75 -0.5 0.5 0.75-0.5 -0.5 -0.25

A-1 =

B-1 =

B-1A-1 = 0.25 0.75 1.625 0 0 -0.5 -0.25 0.35 1.375 2 0.5 1

-1 0 -1 2 0.5 2

Inverse of a productInverse of a product

2. Matrices

5. Math 26

Orthogonal matrix

An orthogonal matrix is a matrix whose inverse is equal to its transpose.

1 0 00 cos sin 0 -sin cos

1 0 00 cos -sin 0 sin cos

1 0 00 1 00 0 1

=

2. Matrices

5. Math 27

Hermetian matrix (1 of 3)

A Hermetian matrix is a matrix that is equal to its own Hermetian transpose• A = AH

The Hermetian transpose of A is the complex conjugate transpose of A• AH = AT

Hermetian matrixHermetian matrix

2. Matrices

5. Math 28

Hermetian matrix (2 of 3)

1 1-I 21+I 3 i2 -i 0

A =

1 1+I 21-I 3 - i2 +i 0

AT =

AT = 1 1-I 21+I 3 i2 -i 0

= A

ExampleExample

2. Matrices

5. Math 29

Hermetian matrix (3 of 3)

Hermetian matrix using ExcelHermetian matrix using Excel

2. Matrices

H H' conj(H')1 1-i 2 1 1+i 2 1 1-i 2

1+i 3 -i 1-i 3 i 1+i 3 -i2 i 0 2 -i 0 2 i 0

1. Use COMPLEX to enter complex numbers 2. Use IMCONJUGATE to convert cell-by-cell Note: Cell operations; not matrix

5. Math 30

Unitary matrix

A matrix is unitary if its inverse equals its Hermetian transpose• U-1 = UH

DFT and inverse DFT are unitary matrices

2. Matrices

5. Math 31

3. Least squares

Example 1Example 2

3. Least squares

5. Math 32

Example 1 (1 of 9)

x + 2y + 3z = 14-2x + + z = 1 2x + y = 4

1 2 3-2 0 1 2 1 0

A = -1 3 2 2 -6 -7 -2 3 4

A-1 = -1/3 b =14 1 4

xyz

= A-1 b = 1 2 3

Solve 3 equations and 3 unknownsSolve 3 equations and 3 unknowns3. Least squares

5. Math 33

Example 1 (2 of 9)

x + 2y + 3z = 14-2x + + z = 1 2x + y = 4 3x + y - z = 2

xyz

= 1 2 3

x + 2y + 3z = 13-2x + + z = 1 2x + y = 4 3x + y - z = 3

xyz

= ?

What happens if we have 4 equations and 3 unknownsWhat happens if we have 4 equations and 3 unknowns

3. Least squares

5. Math 34

Example 1 (3 of 9)

e1 = x + 2y + 3z - 13e2 = -2x + + z - 1e3 = 2x + y - 4e4 = 3x + y - z - 3

Minimize J = (e12 + e2

2 + e32 + e4

2)

Minimize the sum of squaresMinimize the sum of squares

3. Least squares

5. Math 35

Example 1 (4 of 9)

Solve using Solver in ExcelSolve using Solver in Excel3. Least squares

x y x b e e^20.46 3.37 1.91

coefficients1.0 2.0 3.0 13.0 -0.1 0.0-2.0 0.0 1.0 1.0 0.0 0.02.0 1.0 0.0 4.0 0.3 0.13.0 1.0 -1.0 3.0 -0.2 0.0

sum of squares 0.11

1. Set up matrix as shown2. Select Solver3. Select the cell containing the sum of squares4. Select "minimize"5. Set "by changing cells" to the unknowns -- x, y, z6. Select solve

5. Math 36

Example 1 (5 of 9)

e1 = x + 2y + 3z - 13e2 = -2x + + z - 1e3 = 2x + y - 4e4 = 3x + y - z - 3

A = 1 2 3-2 0 1 2 1 0 3 1 1

b = 13 1 4 3

ATA s = AT b s = [ATA]-1 AT b = xyz

= 0.46 3.37 1.91

Solve using matricesSolve using matrices3. Least squares

5. Math 37

Example 1 (6 of 9)

A = a1x a1y a1z

a2x a2y a2z

a3x a3y a3z

a4x a4y a4z

b = b1

b2

b3

b4

a1x a2x a3x a4x

a1y a2y a3y a4y

a1z a2z a3z a4z

AT =

akx akx aky akx akz akx

akx aky aky aky akz aky

akx akz aky akz akz akz

a1x a2x a3x a4x

a1y a2y a3y a4y

a1z a2z a3z a4z

a1x a1y a1z

a2x a2y a2z

a3x a3y a3z

a4x a4y a4z

AT A =

=

Express matrix solution in more general termsExpress matrix solution in more general terms3. Least squares

5. Math 38

Example 1 (7 of 9)

AT b = akxbk

akxbk

akzbk

Express matrix solution in more general terms (cont)Express matrix solution in more general terms (cont)

3. Least squares

5. Math 39

Example 1 (8 of 9)

J = [a1xx + a1yy + a1zz - b1]2 + [a2xx + a2yy + a2zz - b2]2 + [a3xx + a3yy + a3zz - b3]2 + [a4xx + a4yy + a4zz - b4]2

J/ x = 2[a1xa1xx + a1ya1xy + a1za1xz - a1xb1] + [a2xa2xx + a2ya2xy + a2za2xz - a2xb2] + [a3xa3xx + a3ya3xy + a3za3xz - a3xb3] + [a4xa4xx + a4ya4xy + a4za4xz - a4xb4]

2[ akx akx x aky akx y akz akxz - akxbk ]

= 0Minimize by calculusMinimize by calculus

3. Least squares

5. Math 40

Example 1 (9 of 9)

akx akx x aky akx y akz akxz - akxbk = 0 akx aky x aky aky y akz akyz - akybk = 0 akx akz x aky akz y akz akzz - akzbz = 0

akx akx aky akx akz akx

akx aky aky aky akz aky

akx akz aky akz akz akz

xyz

- = 0 akxbk

akybk

akzbk

Minimize by calculus (continued)Minimize by calculus (continued)

3. Least squares

5. Math 41

Example 2 (1 of 3) 1.1000 1.9000 2.9000 4.0000 5.0000 6.0000

x = 2.2000 3.0000 4.1000 5.0000 6.1000 6.9000

y =

Fit a curve to the following dataFit a curve to the following data

3. Least squares

5. Math 42

Example 2 (2 of 3)

Fit z = a + b xi + c xi2

A = [[1;1;1;1;1;1], x, x.*x] =

abc

= (ATA)-1 AT b

b = y

= 1.0126 1.0949 -0.0184

1.0000 1.1000 1.2100 1.0000 1.9000 3.6100 1.0000 2.9000 8.4100 1.0000 4.0000 16.0000 1.0000 5.0000 25.0000 1.0000 6.0000 36.0000

Fit curve z to dataFit curve z to data

3. Least squares

5. Math 43

Example 2 (3 of 3)error = a + b x + c x2 - y =

1 2 3 4 5 62

2.5

3

3.5

4

4.5

5

5.5

6

6.5

7

-0.0052 0.0266 -0.0668 0.0980 -0.0726 0.0200

Error in curve fitError in curve fit

3. Least squares

5. Math 44

4. Propagation of varianceCombining varianceMultiple dimensionsExample -- propagation of positionExample -- angular rotation

4. Propagation of variables

5. Math 45

Combining variances

Variances from multiple error sources can be combined by adding variances

Example

xorig = standard deviation in original position = 1 mvorig = standard deviation in original velocity = 0.5 m/sT = time between samples = 2 secxcurrent = error in current position

= square root of [(xorig)2 + (vorig * T)2] = sqrt(2)

4. Propagation of variables

5. Math 46

Multiple dimensions When multiple dimensions are included, covariance matrices can be added

When an error source goes through a linear transformation, resulting covariance is expressed as follows

P1 = covariance of error source 1P2 = covariance of error source 2P = resulting covariance = P1 + P2

T = linear transformationTT = transform of linear transformationPorig = covariance of original error sourceP = T * P * TT

4. Propagation of variables

5. Math 47

Example -- propagation of position

xorig = standard deviation in original position = 2 mvorig = standard deviation in original velocity = 0.5 m/sT = time between samples = 4 secxcurrent = error in current position

xcurrent = xorig + T * vorig

vcurrent = vorig

1 4 0 1

T = Porig =22

00

0.52

Pcurrent = T * P orig * TT = 1 4 0 1

1 0 4 1

40

00.25

= 164

40.25

4. Propagation of variables

5. Math 48

Example -- angular rotation

5. Statistics

Xoriginal = original coordinates

Xcurrent = current coordinates

T = transformation corresponding to angular rotation

cos -sin sin cos

T = where = atan(0.75)

Porig =1.64 -0.48-0.48 1.36

Pcurrent = T * P orig * TT = 0.8 -0.60.6 0.8

= 20

01

1.64 -0.48-0.48 1.36

0.8 0.6-0.6 0.8

x’

y’

x

y

5. Math 49

5. Geometry

Unit vectorsAngle between two linesPerpendicular to a planePointing

5. Geometry

5. Math 50

Unit vectors

A unit vector is a vector of length 1.Unit vectors are frequently used to denote

vectors that have the same direction, such as those parallel to a chosen axis of a coordinate system

5. Geometry

5. Math 51

Angle between two lines (1 of 10)

The dot product is the result of multiplying the length of a vector A times the length of the component of vector B that is parallel to A

A • B = |A| |B| cos , where is the angle between the vectors

Dot productDot product

5. Geometry

5. Math 52

Angle between two lines (2 of 10)

To find the angle between two lines,• Establish a vector A and a vector B

along each line• Solve for = arccos[A • B /( |A| |B| )]• 0

Solving for using dot productSolving for using dot product5. Geometry

5. Math 53

Angle between two lines (3 of 10)A = [1 2], B = [2 1]|A| = SQRT(12 + 22) = SQRT(5)|B| = SQRT(22 + 12) = SQRT(5)A • B = [1 2] • [2 1]T = [2 • 1 + 2 • 1] = 44 = SQRT(5) • SQRT(5) cos cos = 4/5

A

Bx

y

Example using dot productExample using dot product5. Geometry

5. Math 54

Angle between two lines (4 of 10)

Using Excel to compute valuesUsing Excel to compute values5. Geometry

A B A' B' A'*A B'*B A'*B1 2 1 2 2 1 5 5 42 1 2.24 2.24

1. Use dot product to compute square of hypotenuse

angle(radians) angle(degrees) = angle (radians)*180/pi0.64 36.9

1. Use ACOS to compute angle in radians2. Use 180/pi to convert angle to degrees 3. Use PI function to compute pi Note: PI must be followed by "(" if typed

5. Math 55

Angle between two lines (5 of 10)

The cross product is the result of multiplying the length of a vector A times the length of the component of vector B that is perpendicular to A

A x B = |A| |B|sin , where is the angle between the vectors

The vector A x B is perpendicular to the plane containing A and B

Cross productCross product5. Geometry

5. Math 56

Angle between two lines (6 of 10)

To find the angle between two lines,• Establish a vector A and a vector B

along each line• Solve for = arcsin[A x B /( |A| |B| )]• - /2 /2

Solving for using cross productSolving for using cross product

5. Geometry

5. Math 57

Angle between two lines (7 of 10)

A = i j kAx Ay AzBx By Bz

=

i j k1 2 02 1 0

= -3k

Example using cross productExample using cross product5. Geometry

5. Math 58

Angle between two lines (8 of 10)

A = [1 2], B = [2 1]|A| = SQRT(12 + 22) = SQRT(5)|B| = SQRT(22 + 12) = SQRT(5)A x B = -3 k-3 = SQRT(5) • SQRT(5) sin sin = -3/5

Example using cross product (continued)Example using cross product (continued)

5. Geometry

5. Math 59

Angle between two lines (9 of 10)

= atan2(sin , cos )

Combining dot product and cross productCombining dot product and cross product

5. Geometry

5. Math 60

Angle between two lines (10 of 10)

Using Excel to compute arctangentsUsing Excel to compute arctangents

5. Geometry

x y ATAN ATAN2-0.6 -0.8 53.13 -127

1. Use ATAN2 for four quadrant arctangentNote: First argument is X and not Y as in FORTRAN

5. Math 61

Perpendicular to a plane The cross product defines the direction

perpendicular to the plane defined by the two vectors A and B

5. Geometry

5. Math 62

Pointing (1 of 14)

A (3,1,1)

B (2,3,2)

camera x0

y0

Change pointing of camera so that points A and B are on the same level

Point camera as directedPoint camera as directed5. Geometry

5. Math 63

Pointing (2 of 14)

A (3,1,1)

B (2,3,2)

x0

y0

camera

x1

y1

z0 and z1 are positive out of page

Pan camera to point at A in the x0-y0 planePan camera to point at A in the x0-y0 plane5. Geometry

5. Math 64

Pointing (3 of 14)

= atan2(3,1) = 18.4o

cos sin 0-sin cos 0 0 0 1

311

=3.160.001.00

cos sin 0-sin cos 0 0 0 1

232

=2.852.222.00

T01

Determine T01 as followsDetermine T01 as follows

5. Geometry

5. Math 65

Pointing (4 of 14)

A (3.16,0,1)

B (2.85,2.22,2)

x1

y1

camera

z1 is positive out of page

Redraw problem in x1-y1Redraw problem in x1-y1

5. Geometry

5. Math 66

Pointing (5 of 14)

A (3.16,0,1)

B (2.85,2.22,2)

x1

z1

camera

y1 is positive into page

View x1-z1 planeView x1-z1 plane

5. Geometry

5. Math 67

Pointing (6 of 14)

A (3.16,0,1)

B (2.85,2.22,2)

x1

z1

camera

x2

z2

y1 and y2 are positive into page

Elevate camera to point at A in x1-z1 planeElevate camera to point at A in x1-z1 plane5. Geometry

5. Math 68

Pointing (7 of 14)

= atan2(1,3.16) = 17.5o

cos 0 sin 0 1 0 -sin 0 cos

=3.160.000.00

=2.852.222.00

3.160.001.00

cos 0 sin 0 1 0 -sin 0 cos

3.322.211.05

T12

Determine T12 as followsDetermine T12 as follows5. Geometry

5. Math 69

Pointing (8 of 14)

A (3.16,0,0)

B (3.32,2.21,1.05)

z2x2 is positive into page

y2

View y2-z2 planeView y2-z2 plane

5. Geometry

5. Math 70

Pointing (9 of 14)

A (3.16,0,0)

B (3.32,2.21,1.05)

z2

x2 and x3 are positive into page

y2

z3y3

Roll camera so that A and B are on horizontal lineRoll camera so that A and B are on horizontal line5. Geometry

5. Math 71

Pointing (10 of 14)

= atan2(1.05.2.21) = 25.4o

= 1 0 0 0 cos sin 0 -sin cos

3.322.450.00

3.322.211.05

T23

Determine T23 as followsDetermine T23 as follows

5. Geometry

5. Math 72

Pointing (11 of 14)

A (3.16,0,0)

B (3.32,2.45,0)

z3x3 is positive into page

y3

View y3-z3 planeView y3-z3 plane5. Geometry

5. Math 73

Pointing (12 of 14)

T01T T12T T23T 001

-0.12-0.49 0.86

=

Express unit vector perpendicular to AB in x0-y0-z0 planeExpress unit vector perpendicular to AB in x0-y0-z0 plane5. Geometry

5. Math 74

Pointing (13 of 14)

A = i j kAx Ay AzBx By Bz

=

i j k3 1 12 3 2

= (- i - 4j +7k)/sqrt(66)

-0.12-0.49 0.86

=

Compare perpendicular unit vector to cross productCompare perpendicular unit vector to cross product5. Geometry

5. Math 75

Pointing (14 of 14)

T01, T12, T23, and any of their products are examples of direction cosine matrices

The element in aij is the cosine between axis i and axis j

Define direction cosine matrixDefine direction cosine matrix5. Geometry