# week03 - Rutgers University School of Engineering Fall 2011...

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

Rutgers University School of Engineering Fall 2011 14:440:127 - Introduction to Computers for Engineers Sophocles J. Orfanidis ECE Department [email protected] week 3

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

View Full Document
Week 1 - Basics – variables, arrays, matrices, plotting (ch. 2 & 3) Week 2 - Basics – operators, functions, program flow (ch. 2 & 3) Week 3 - Matrices (ch. 4) Week 4 - Plotting – 2D and 3D plots (ch. 5) Week 5 - User-defined functions (ch. 6) Week 6 - Input-output formatting – fprintf, sprintf (ch. 7) Week 7 - Program flow control & relational operators (ch. 8) Week 8 - Matrix algebra – solving linear equations (ch. 9) Week 9 - Structures & cell arrays (ch. 10) Week 10 - Symbolic math (ch. 11) Week 11 - Numerical methods – data fitting (ch. 12) Week 12 – Selected topics Weekly Topics Textbook: H. Moore, MATLAB for Engineers , 2 nd ed., Prentice Hall, 2009
Matrix Manipulation defining matrices accessing matrix elements colon operator, submatrices transposing a matrix changing/adding/deleting entries concatenating matrices special matrices diagonals, block-diagonal matrices replicating and reshaping matrices element-wise operations functions of matrices (element & column operations) meshgrid, ndgrid examples: DTMF keypad, Taylor series, polynomials

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

View Full Document
>> A = [1 2 3; 2 0 4; 0 8 5] A = 1 2 3 2 0 4 0 8 5 >> size(A) % [N,M] = size(A), NxM matrix ans = 3 3 matrix indexing convention defining matrices column row dimension dimension NxM matrix M N
accessing matrix elements >> A(1,1) % 11 matrix element ans = 1 >> A(2,3) % 23 matrix element ans = 4 >> A(:,2) % second column ans = 2 0 8 >> A(3,:) % third row ans = 0 8 5

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

View Full Document
concatenating columns >> A = [1 2 3; 2 0 4; 0 8 5] A = 1 2 3 2 0 4 0 8 5 >> A(:) % concatenate columns ans = 1 2 0 2 0 8 3 4 5 A(6) A(9) concatenating rows B = A'; B(:) column-wise indexing
building a matrix column-wise >> A = zeros(3); >> A(:) = [1 2 0 2 0 8 3 4 5] A = 1 2 3 2 0 4 0 8 5 define desired size enter elements in a row (or column) elements are re-arranged column-wise

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

View Full Document
sub-matrices A = [ 2 4 1 3 5 8 6 7 4 9 3 2 5 2 1 5 6 1 8 4 ]; A(3:4, 2:4) ans = 2 5 2 6 1 8 A(1:3, [1,5]) ans = 2 5 8 9 3 1
>> A = [1 2 3 4; 2 0 5 6; 0 8 7 9] % size 3x4 A = 1 2 3 4 2 0 5 6 0 8 7 9 >> A' % size 4x3 ans = 1 2 0 2 0 8 3 5 7 4 6 9 transposing a matrix => transposition operation

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

View Full Document
adding/deleting rows or columns >> A = [1 2 3; 2 0 4; 0 8 5] >> A(5,:) = [7 8 9] % add a fifth row A = 1 2 3 2 0 4 0 8 5 0 0 0 7 8 9 >> A(:,2) = [] % delete second column A = 1 3 2 4 0 5 0 0 7 9 4 th row is automatically allocated [ ] denotes an empty 0x0 matrix alternatively, redefine A by omitting its second column: >> A = A([1,3],:);
replacing rows or columns >> A = [1 2 3; 2 0 4; 0 8 5] A = 1 2 3 2 0 4 0 8 5 >> A(:,2) = [20 30 40]' % replace second column A = 1 20 3 2 30 4 0 40 5 >> A(3,:) = [50 60 70] % replace third row A = 1 20 3 2 30 4 50 60 70

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

View Full Document
concatenating matrices >> A = [1 2; 3 4]; >> B = [5 6; 7 8]; >> C = [A, B] C = 1 2 5 6 3 4 7 8 >> C = [A; B] C = 1 2 3 4 5 6 7 8 A,B must have same number of rows A,B must have same number of columns
appending columns or rows >> A = [1 2; 3 4; 5 6]; >> b = [7; 7; 7]; >> c = [8 8 8]'; >> B = [A,b,c] B = 1 2 7 8 3 4 7 8 5 6 7 8 >> C = [b,A,c] C = 7 1 2 8 7 3 4 8 7 5 6 8 >> D = [A; [7 7];] >> E = [[8 8]; A] D = 1 2 3 4 5 6 7 7 E = 8 8 1 2 3 4 5 6

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

View Full Document
special matrices eye(3)
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 47

week03 - Rutgers University School of Engineering Fall 2011...

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

View Full Document
Ask a homework question - tutors are online