{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# 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 [email protected] week 9

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 - Relational & logical operators, if, switch statements (ch. 8) 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 for-loop & while-loop 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) + ...

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

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern