Recitation 03 Presentation

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

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
14:440:127 Introduction to Computers for Engineers Recitation 3
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 Rutgers University SOE ans = [ 2 6 ] [ 5 3 ] [ 6 4 ] v = z(:) % turn z into a vector v = [ 7 2 3 2 5 6 6 3 4 3 2 2]
Background image of page 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 ] nd a special variable referring to the last row or last Rutgers University SOE end is a special variable referring to the last row or last 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 ]
Background image of page 3

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

View Full DocumentRight Arrow Icon
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 ]; Rutgers University SOE a + b ans = [ 8 5 ] [ 7 8 ] Subtraction: • a - b ans = [ 6 -1 ] [ 5 -2 ]
Background image of page 4
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 ]
Background image of page 5

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

View Full DocumentRight Arrow Icon
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] ot product = (a1*b1)+(a2*b2)+(a3*b3) Rutgers University SOE dot product = (a1*b1)+(a2*b2)+(a3*b3) 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.
Background image of page 6
Examples of Matrix multiplication Matrix Multiplication: a = [ 7 2 ; 6 3 ]; b = [ 1 3 ; 1 5 ]; a * b ans = [ 9 31 ] [ 9 33 ] Rutgers University SOE Dot Product:
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 26

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

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online