{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Recitation 03 Presentation

# Recitation 03 Presentation - 14:440:127 Introduction to...

This preview shows pages 1–9. Sign up to view the full content.

14:440:127 Introduction to Computers for Engineers Recitation 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
14:440:127 Recitation 3 Ways of selecting elements in a Matrix using colon (:) operator z = [ 7 2 6 3 ] [ 2 5 3 2 ] [ 3 6 4 2 ] z(:,2:3) % all rows, columns 2 through 3 ans = [ 2 6 ] Rutgers University SOE [ 5 3 ] [ 6 4 ] v = z(:) % turn z into a vector v = [ 7 2 3 2 5 6 6 3 4 3 2 2]
14:440:127 Recitation 3 Some more examples using Colon operator z = [ 7 2 6 3 ; 2 5 3 2 ; 3 6 4 2 ]; z(2,[1 3:4]) % row 2, columns 1 and 3 through 4 ans = [ 2 3 2 ] end is a special variable referring to the last row or last Rutgers University SOE column z(2:end,end) % 2nd through last row, last column ans = [ 2 ] [ 2 ] z(end,[1 3:4]) % last row, columns 1 and 3 through 4 ans = [ 3 4 2 ]

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
14:440:127 Recitation 3 Element by element math operations in Matlab Operands (vectors / matrices) must be of same dimension (same number of rows and columns) . Addition: a = [ 7 2 ; 6 3 ]; b = [ 1 3 ; 1 5 ]; a + b Rutgers University SOE ans = [ 8 5 ] [ 7 8 ] Subtraction: a - b ans = [ 6 -1 ] [ 5 -2 ]
14:440:127 Recitation 3 Multiplication Dot Multiplication Multiplies ‘element by element’. Syntax ‘ .* Example Rutgers University SOE a = [ 7 2 ; 6 3 ]; b = [ 1 3 ; 1 5 ]; a .* b ans = [ 7 6 ] [ 6 15 ]

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
14:440:127 Recitation 3 Matrix Multiplication: Inner dimension of the matrices must be equal. (i.e. the no of columns of the 1st matrix must be equal to the no of rows of the 2nd matrix) Dot product: a = [a1 a2 a3] b = [b1 b2 b3] dot product = (a1*b1)+(a2*b2)+(a3*b3) Rutgers University SOE The result is a Scalar. Dot product is different from dot multiplication. Cross product: a = [a1 a2 a3] b = [b1 b2 b3] Result = (a2*b3-b2*a3)i + (a3*b1-a1*b3)j + (a1*b2-a2*b1)k The result is a vector.
14:440:127 Recitation 3 Examples of Matrix multiplication Matrix Multiplication: a = [ 7 2 ; 6 3 ]; b = [ 1 3 ; 1 5 ]; a * b ans = [ 9 31 ] [ 9 33 ] Dot Product: Rutgers University SOE a = [ 7 2 3 ]; b = [ 1 3 5 ]; dot(a,b) ans = 28 Cross Product: cross(a,b) ans = [ 1 -32 19 ]

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
14:440:127 Recitation 3 Built in Matlab functions for vectors & matrices Sum : Vector, it adds individual elements of the vector.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}