{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# week02 - 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 2

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 - User-defined functions (ch. 6) Week 5 - Plotting – 2D and 3D plots (ch. 5) – Exam 1 Week 6 - Input-output formatting – fprintf, fscanf (ch. 7) Week 7 - Program flow control & relational operators (ch. 8 & 9) Week 8 - Matrix algebra – solving linear equations (ch. 10) Week 9 - Matrix algebra, structures & cell arrays (ch. 10 & 11) Week 10 – Data 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
1. MATLAB desktop 2. MATLAB editor 3. Getting help 4. Variables, built-in constants, keywords 5. Numbers and formats 6. Arrays and matrices 7. Operators and expressions 8. Functions 9. Basic plotting 10. Function maxima and minima 11. Relational and logical operators 12. Program flow control 13. Matrix algebra and linear equations MATLAB Basics These should be enough to get you started. We will explore them further, as well as other topics, in the rest of the course. week 1 week 2

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

View Full Document
6. Arrays and Matrices arrays and matrices are the most important data objects in MATLAB Last week we discussed one-dimensional arrays, i.e., column or row vectors. Next, we discuss matrices, which are two-dimensional arrays. We will explore them further in Chapters 4 & 9.
>> 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

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

View Full Document
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
>> 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: rows become columns and vice versa => transposition operation

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

View Full Document
>> help elmat Elementary matrices and matrix manipulation. Elementary matrices. zeros - Zeros array. ones - Ones array. eye - Identity matrix. repmat - Replicate and tile array. linspace - Linearly spaced vector. logspace - Logarithmically spaced vector. etc. For more information on elementary matrices see:
7. Operators and Expressions operation element-wise matrix-wise addition + + subtraction - - multiplication .* * division ./ / left division .\ \ exponentiation .^ ^ transpose w/o complex conjugation . ' transpose with complex conjugation ' >> help / >> help precedence

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

View Full Document
>> a = [1 2 5]; >> b = [4 -5 1]; >> a+b ans = 5 -3 6 >> a.*b ans = 4 -10 5 >> a./b ans = 0.2500 -0.4000 5.0000 >> a.\b ans = 4.0000 -2.5000 0.2000 % note: (a./b).*(a.\b) = [1,1,1]
>> a = [2 3 4 5]; >> a.^2 % [2^2, 3^2, 4^2, 5^2] ans = 4 9 16 25 >> 2.^a % [2^2, 2^3, 2^4, 2^5] ans = 4 8 16 32 >> a+10 ans = 12 13 14 15

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

View Full Document
>> A = [1 2; 3 4] A = 1 2 3 4 >> [A, A.^2; A^2, A*A] % form sub-blocks ans = 1 2 1 4 3 4 9 16 7 10 7 10 % note A^2 = A*A 15 22 15 22 >> B = 10.^A; >> [B, log10(B)] ans = 10 100 1 2 1000 10000 3 4
8. Functions >> help elfun % elementary functions list Some typical built-in elementary functions are: sin(x), cos(x), tan(x), cot(x) asin(x), acos(x), atan(x), acot(x) sinh(x), cosh(x), tanh(x), coth(x)

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 ]}