# week03 - Rutgers University School of Engineering Spring...

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

Rutgers University School of Engineering Spring 2012 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) – Exam 1 Week 6 - Input-output formatting – fprintf, fscanf (ch. 7) Week 7 - Program flow control & relational operators (ch. 8 & 9) Week 8 - Program flow control & relational operators (ch. 8 & 9) Week 9 - Matrix algebra – solving linear equations (ch. 10) Week 10 - Cell arrays and structures (ch. 11) – Exam 2 Week 11 - Numerical methods – part I (ch. 13) Week 12 - Numerical methods – part II (ch. 13) Week 13 - Symbolic toolbox (ch. 12) Week 14 - Exam 3 Weekly Topics Textbook: H. Moore, MATLAB for Engineers , 3 d ed., Prentice Hall, 2011
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 no. rows no. columns 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,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
inserting rows or columns >> A = [1 2 3; 2 0 4; 0 8 5] A = 1 2 3 2 0 4 0 8 5 % insert new column between columns 2 & 3 A = [A(:,1:2), [10 20 30]', A(:,3)] A = 1 2 10 3 2 0 20 4 0 8 30 5 % insert new row between rows 1 & 2 A = [A(1,:); [60 70 80 90]; A(2:3,:)] A = 1 2 10 3 60 70 80 90 2 0 20 4 0 8 30 5
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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 51

week03 - Rutgers University School of Engineering Spring...

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

View Full Document
Ask a homework question - tutors are online