Engr 0012 (04-1) LecNotes 13-01. Engr 0012 (04-1) LecNotes 13-02 Functional analysis y = f(x) things to do 1. sketch graph 2. find roots (zeros) 3. find.

Slides:



Advertisements
Similar presentations
Lecture 5.
Advertisements

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
259 Lecture 17 Working with Data in MATLAB. Overview  In this lecture, we’ll look at some commands that are useful for working with data!  fzero  sum,
Introduction to Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
Introduction to Matlab
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
M AT L AB Programming: scripts & functions. Scripts It is possible to achieve a lot simply by executing one command at a time on the command line (even.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
Suggested problems from text (6 th edition) Chapter 3.1 p85 Problems 1, 4, 9, 10 Computer problems 1, 2, 4, 7 Chapter 3.2 p101 Problems 4, 15, 17, 19 Computer.
More on Functions… Lecture 8. Preserving Data between Calls to a function Persistent statement is declared in order to preserve some local information.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 19P. 1Winter Quarter MATLAB: Script and.
Engr 0012 (04-1) LecNotes Declaring/using a function for evaluation String Function Declaration sfname = '2*x+2'; Calculating “y-values” x = linspace(-5,5,8);
Scripts and Flow Control. Scripts So far we have been entering commands directly into the command line But there is a better way Script files (and functions)
Relative Extrema.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Setting Up Clear any equations or lists from your calculator to start! Clear any equations or lists from your calculator to start! ~From the Y= list ~From.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
AP CALCULUS AB Chapter 4: Applications of Derivatives Section 4.1:
Objective: I can write linear equations that model real world data.
Chapter 1 A Beginning Library of Elementary Functions
1.4 Functions I. Function A) Definition = a relation in which each value of x has exactly one solution y. B) Testing for functions. 1) From a graph: Use.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB is a powerful program for numerical computations, plotting and programming.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
Department of Mechanical Engineering, LSU Session IV MATLAB Tutorials Session IV Mathematical Applications using MATLAB Rajeev Madazhy
Introduction to MATLAB ENGR 1181 MATLAB 1. Opening MATLAB  Students, please open MATLAB now.  CLICK on the shortcut icon → Alternatively, select… start/All.
Introduction to Matlab By E. Noura Semary. Contents MATLAB Environment  Command window, Workspace, Path window, Editor window,and Figure window) Basic.
Analyzing Functions (4.16) y=f(x) MATLAB. Functional Analysis includes: Plotting and evaluating a function Finding extreme points Finding the roots (zeros.
Numerical Analysis 3D Plots. A numerical method is a technique for computing a numerical approximation of the solution to a mathematical problem.
2D Plots 2 ENGR 1181 MATLAB 13. Plotting in the Real World 2D plots generated by MATLAB can be used in a variety of fields, including the one shown here,
13-4 The Sine Function Today’s Objective: I can graph the sine function.
1-d Arrays & Plotting.
More Functions in MATLAB. Functions that operate on other functions A function F() can take another function G() as an argument by using a notation:
Greg Kelly, Hanford High School, Richland, Washington.
POLYNOMIALS REVIEW The DEGREE of a polynomial is the largest degree of any single term in the polynomial (Polynomials are often written in descending order.
PS 5-3 Integration –Discrete data –Polynomial functions Differentiation –Discrete data –Polynomial functions Roots (i.e., zeros) of functions –Polynomial.
Finding zeros (also called roots) of a function Overview: Define the problem Methods of solution Graphical Newton’s Bisection Secant.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Chapter 15 General Least Squares and Non- Linear.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
POLYNOMIALS REVIEW The DEGREE of a polynomial is the largest degree of any single term in the polynomial (Polynomials are often written in descending order.
Ch : Which Values Are Possible? Domain & Range.
MA Day 19- February 1, 2013 Begin Differential Multivariable Calculus Section 11.1 Section 9.6.
Engr 0012 (04-1) LecNotes loading data from files >> file_name = input( 'Enter data file name ==> ','s') Enter data file name ==> c:\temp\speed_mpg.dat.
Using and Programming with MATLAB as an Engineering Tool [ Part III ]
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
1 Lecture 8 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Matlab Tutorial Iman Moazzen First Session – September 11, 2013.
POLYNOMIALS REVIEW The DEGREE of a polynomial is the largest degree of any single term in the polynomial (Polynomials are often written in descending order.
MATLAB Numerical Basics. Roots of Polynominals MATLAB can find all roots (both real and imaginary) of polynominals. Store coefficients in a vector v =
전자장 1 실험 - Matlab 사용법 - Photonic Systems Laboratory School of EE, Seoul National University Photonic Systems Lab School of EECS, S.N.U.
What do these situations have in common? Explain..
Stationary/Turning Points How do we find them?. What are they?  Turning points are points where a graph is changing direction  Stationary points are.
Introduction to Programming for Mechanical Engineers
Working with Data in MATLAB
Section 3.2 – Domain & Range
MATLAB Basics Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.
User Defined Functions
Chapter 4: Lesson 4.5 Graphs of Sine and Cosine Functions
MATH 493 Introduction to MATLAB
Plotting Data with MATLAB
Review Make sure current directory is set properly Create a diary
Chapter 7: Optimization
Applications of User Defined functions in MATLAB
Basics of Functions and Their Graphs
Using Script Files and Managing Data
Matlab Basics Tutorial
Objective: To graph square root functions
Chapter 4 Graphing and Optimization
Presentation transcript:

Engr 0012 (04-1) LecNotes 13-01

Engr 0012 (04-1) LecNotes Functional analysis y = f(x) things to do 1. sketch graph 2. find roots (zeros) 3. find minima 4. find maxima 5. find area “under” curve 6. show  f(x) dx 7. show d[f(x)]/dx

Engr 0012 (04-1) LecNotes Declaring/using a function for evaluation two methods string declaration fcn_name = 'function definition'; myfcn = ' 2*cos(3*x)./exp(x) ' myfcn = 2*cos(3*x)./exp(x) creates a string variable for function string use - use eval function yvalues = eval(fcn_name); >> x = linspace(0,pi,8); creates 8 points in (0,  ) required!! a vector or variable with same name as variable used in fucntion >> y1 = eval(myfcn) y1 = evaluates fcn at those 8 points

Engr 0012 (04-1) LecNotes Declaring/using a function for evaluation string use >> clear x >> xpts = linspace(0,pi,8); >> y1 = eval(myfcn) ??? Undefined function or variable 'x'. no longer have a vector or variable “x” in the workspace potential problem: if eval is working, is it working on the data set you intended to use - or some prior definition of x?

Engr 0012 (04-1) LecNotes Declaring/using a function for evaluation string declaration/use advantages easy to use in MATLAB command window good for one-time evaluations disadvantages hard-wired - cannot change without effort can’t use in general purpose script or function must have vector with same variable name as used in function declaration

Engr 0012 (04-1) LecNotes Declaring/using a function for evaluation m-file declaration function [y] = fcn_name(x) needs results function [y] = f13a(x) y = 2*cos(3*x)./exp(x); create function, save to current directory m-file use - use feval function >> fname = input( 'Enter function file name ==> ', 's' ) Enter function file name ==> f13a fname = f13a ask for function name - response does not need to have.m because it must be an m-file y_vec = feval(fcn_name,x_vec) “indirect” reference to the function

Engr 0012 (04-1) LecNotes Declaring/using a function for evaluation m-file use - use feval function >> ypts = feval(fname,xpts) y2 = >> xnew = 1:1:5 xnew = >> ynew = feval(fname,xnew) ynew = feval works with any vector name - not just the one that was used in the function file

Engr 0012 (04-1) LecNotes Declaring/using a function for evaluation m-file declaration/use advantages generic - can write scripts that ask for function name scripts can be used for multiple function evaluations without editing works with any independent vector name/set disadvantages have to create separate function with equation cumbersome to use in MATLAB command window

Engr 0012 (04-1) LecNotes Quick plot of a function - fplot >> domain = [min(x),max(x)] domain = establish domain for plot >> fplot(fname,domain) m-file function >> fplot(myfcn,domain) string function can use either declaration form with fplot

Engr 0012 (04-1) LecNotes Finding roots - fzero xzero = fzero(fcn_name,approximate location of root) >> xzero1 = fzero(fname,0.5) xzero1 = >> xzero2 = fzero(myfcn,1.5) xzero2 = can use either declaration form with fzero

Engr 0012 (04-1) LecNotes Finding minima - fminbnd xmin = fminbnd(fcn_name,xlow,xhigh) >> xmin1 = fminbnd(fname,0.5,1.5) xmin1 = >> xmin2 = fminbnd(fname,2.5,max(x)) xmin2 = can use either declaration form with fminbnd

Engr 0012 (04-1) LecNotes Finding maxima no fmaxbnd command can define new function string >> neg_myfcn = ['-1*(',myfcn,')']; call fminbnd with negative of function >> max1 = fminbnd(neg_myfcn,1.5,2.5) max1 = m-file function [y] = neg_f11a(x) y = -2*cos(3*x)./exp(x); need to create and save in current directory >> negf = input( 'neg fcn name? ==> ','s' ); neg fcn name? neg_f13a >> max2 = fminbnd(negf,1.5,2.5) max2 =

Engr 0012 (04-1) LecNotes Finding areas neg area pos area easiest: use quad area = quad(fcn_name,xmin,xmax) >> area1 = quad(myfcn,1.5,2.5) area1 = >> area2 = quad(fname,min(x),max(x)) area2 = can use either declaration form with quad

Engr 0012 (04-1) LecNotes Finding areas more complex and not as accurate!!! use trapz area = trapz(xtrap,ytrap) need to define x & y vectors of points numtraps = 100; xtrap = xlow:(xhigh-xlow)/numtraps:xhigh; ytrap = feval(fcn_name,xtrap) area = trapz(xtrap,ytrap)

Engr 0012 (04-1) LecNotes Finding  f(x) dx over a range objective is to create a vector of cumulative area versus x value and then plot them on the graph (i.e. area(x) vs x % create xpts for plotting; xpts = xlow:(xhigh-xlow)/200:xhigh; for i = 1:1:length(xpts) cumarea(i) = quad(fcn_name,xpts(1),xpts(i)); end % plot cumulative area plot(xpts,cumarea,‘g-’)

Engr 0012 (04-1) LecNotes Finding d[f(x)]/dx over a range objective is to create a vector of derivatives versus x value and then plot them on the graph (i.e. deriv(x) vs x similar to cumulative area see text, Section 4.15, for discussion