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

This preview shows pages 1–8. 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 orfanidi@ece.rutgers.edu week 9

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

View Full Document
Week 1 Week 2 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 Week 8 - For-loops, while-loops (ch. 9) Week 9 - Review Week 10 - Matrix algebra – solving linear equations (ch. 10) – Exam 2 Week 11 - Cell arrays and structures (ch. 11) Week 12 - Numerical methods (ch. 13) Week 13 - Numerical methods (ch. 13), Symbolic Toolbox (ch.12) Week 14 - Exam 3 Weekly Topics Textbook: H. Moore, MATLAB for Engineers , 3 d ed., Prentice Hall, 2011
Review Examples 1. User-defined function functions 2. Pitfalls in piece-wise function definitions 3. Finite examples 4. Terminating divergent while-loops 5. Summing infinite series with prescribed accuracy 6. Vectorized forms of fprintf / fscanf

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

View Full Document
Example 1: User-defined function functions function [xmax,fmax] = fmaxbnd(f,a,b) [xmax,fmax] = fminbnd(@(x) -f(x), a, b); fmax = -fmax; function handle function y = xsin(x) y = x.*sin(x); M-file: fmaxbnd.m M-file: xsin.m f = @(x) x.*sin(x); anonymous definition
0 1 2 3 0 0.5 1 1.5 2 x x  sin(x) [xmax,fmax] = fmaxbnd(@xsin,0,3); [xmax,fmax] = fmaxbnd(f,0,3); x = linspace(0,3,301); y = xsin(x); plot(x,y,'b', xmax,fmax,'ro'); [xmax,fmax] ans = 2.0288 1.8197

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

View Full Document
Example 2: Pitfalls in piece-wise function definitions method 1 – vectorized – using relational operators method 2 – vectorized – using the function find method 3 – not vectorized – used with a for-loop implemented in the M-files: f1.m, f2.m, f3.m
function y = f1(x) y = exp(x+1).*(x<-1) + . .. abs(x).*(abs(x)<=1) + . .. exp(-x+1).*(x>1);

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.

## This note was uploaded on 03/26/2012 for the course ENGINEERIN 440:127 taught by Professor Blase during the Spring '10 term at Rutgers.

### Page1 / 35

week09 - Rutgers University School of Engineering Spring...

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

View Full Document
Ask a homework question - tutors are online