Applications of User Defined functions in MATLAB

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,
MATLAB Optimization Greg Reese, Ph.D Research Computing Support Group Miami University.
Engr 0012 (04-1) LecNotes Engr 0012 (04-1) LecNotes Functional analysis y = f(x) things to do 1. sketch graph 2. find roots (zeros) 3. find.
Copyright © 2014, 2010, 2007 Pearson Education, Inc.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Spring 2004ENGR 111A1 MATLAB – Palm Chapter 3, Part 2 Function Files Class 6.1 Chapter 3: Section 2.
Part 2 Chapter 7 Optimization
Analytical vs. Numerical Minimization Each experimental data point, l, has an error, ε l, associated with it ‣ Difference between the experimentally measured.
X-intercept(s): y-intercept: Domain: Axis of Symmetry: Zero(s): Range: What are the Characteristics of Quadratic Functions?? MM2A3c. Investigate and explain.
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.
topics covered Numerical Analysis Examples - applications
SWBAT…analyze the characteristics of the graphs of quadratic functions Wed, 2/15 Agenda 1. WU (10 min) 2. Characteristics of quadratic equations (35 min)
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:
Basis of Mathematical Modeling LECTURE 3 Numerical Analysis with MATLAB Dr. N.K. Sakhnenko, PhD, Professor Associate.
Root Finding UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
MATLAB Numerical Basics. Roots of Polynominals MATLAB can find all roots (both real and imaginary) of polynominals. Store coefficients in a vector v =
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 2 - Chapter 7 Optimization.
EE 201 1C10-2 Spring 2012 LOOPS For.  Achieve Comprehension LOL of using Loops in programming. Class Learning Objectives 2C10-2 Spring 2012.
Quadratic Functions PreCalculus 3-3. The graph of any quadratic function is called a parabola. Parabolas are shaped like cups, as shown in the graph below.
A Concise Introduction to MATLAB®
Introduction to MATLAB 7
Polynomial Functions Objectives: Identify Polynomials and their Degree
Do Now from 1.2a Find the domain of the function algebraically and support your answer graphically. Find the range of the function.
Attributes of functions in their graph
Characteristics of Polynomials: Domain, Range, & Intercepts
2.2(b) Notes: Polynomial Functions of Higher Degree
Completing the Square and writing in Vertex Form
6.5/6.8 Analyze Graphs of Polynomial Functions
4.3 Derivatives and the shapes of graphs 4.5 Curve Sketching
College Algebra: Lesson 1
Warm-Up Find the x and y intercepts: 1. f(x) = (x-4)2-1
4.4 Analyzing Functions.
Chp3 Tutorial: Prob 3.15 Solution
Copyright © 2014, 2010, 2007 Pearson Education, Inc.
Let’s Review Functions
AP Calculus Chapter 1 Section 2
Chapter 7: Optimization
Copyright © 2014, 2010, 2007 Pearson Education, Inc.
4.3B Analyzing Functions.
Characteristics of Polynomials: Domain, Range, & Intercepts
Characteristics of Polynomials: Domain, Range, & Intercepts
Characteristics of Polynomials: Domain, Range, & Intercepts
Which of the following are polynomial functions?
Graphing Simple Rational Functions p 381
7.2 Graphing Polynomial Functions
Zero’s, Multiplicity, and End Behaviors
Copyright © 2014, 2010, 2007 Pearson Education, Inc.
More Properties of Functions
Warm-up: Determine the left and right-hand behavior of the graph of the polynomial function, then find the x-intercepts (zeros). y = x3 + 2x2 – 8x HW:
Characteristics of Polynomials: Domain, Range, & Intercepts
MATLAB 程式設計 Learning Loops and Logic
Function Handles UC Berkeley Fall 2004, E Copyright 2005, Andy Packard
Drill #17* List the relation (set of ordered pairs) and the domain and range of the following mapping: 1. Find the value of the following if f(x) = 2.
Characteristics of Polynomials: Domain, Range, & Intercepts
(3, 2) 2 -3 (-4, -3) -2 (5, -2) 1. a) Find: f(3) = ______
Characteristics of Polynomials: Domain, Range, & Intercepts
Part 2 Chapter 7 Optimization
Domain The set of all possible input values. Independent Variable X
More Nonlinear Functions and Equations
LOOPS For EE 201 C10-1 SPRING 2012.
f(x) g(x) x x (-8,5) (8,4) (8,3) (3,0) (-4,-1) (-7,-1) (3,-2) (0,-3)
Let’s Review Functions
- Derivatives and the shapes of graphs - Curve Sketching
Characteristics of Polynomials: Domain, Range, & Intercepts
Let’s Review Functions
Maximum and Minimum Values
Let’s Review Functions
Presentation transcript:

Applications of User Defined functions in MATLAB EE 201 C5-2 FALL 2012

Session Agenda Contact before work 5 min. Applications of user defined functions in MATLAB. 70 min. C5-2 FAll 2012

Class Learning Objectives Achieve Comprehension LOL of how to use functions in real engineering applications using Matlab. Demonstrate a willingness to respond to using functions in real engineering applications using Matlab. C5-2 FAll 2012

Contact before work Burning Questions C5-2 FAll 2012

Applications of User-Defined Functions Some Matlab commands act on functions. If the function of interest is no a simple function, it is more convenient to define the function in an M-file when using one of these commands. Finding the Zeros of a Function The Fzero function Minimizing a Function of One Variable The fminbnd function Minimizing a Function of Several Variables The fminsearch function. C5-2 FAll 2012

Finding Zeros of a Function You can use the fzero function to find the zero of a function of a single variable, which is denoted by x. One form of its syntax is fzero(’function’, x0) where function is a string containing the name of the function, and x0 is a user-supplied guess for the zero. The fzero function returns a value of x that is near x0. It identifies only points where the function crosses the x-axis, not points where the function just touches the axis. For example, fzero(’cos’,2)returns the value 1.5708. C5-2 FAll 2012

Using fzero with User-Defined Functions (continued …) To use the fzero function to find the zeros of more complicated functions, it is more convenient to define the function in a function file. For example, if : y =x +2e−x−3. define the following function file: function y = f1(x) y = x + 2*exp(-x) -3; end C5-2 FAll 2012

Plot of the function y =x +2e−x−3. There is a zero near x = -0.5 and one near x = 3. (continued …) C5-2 FAll 2012 Figure 3.2–1

Example (continued) To find a more precise value of the zero near x = -0.5, type: >>x = fzero(‘f1’,-0.5) The answer is x = -0.5881. More? See pages 156-157 C5-2 FAll 2012

Finding the Minimum of a Function The fminbnd function finds the minimum of a function of a single variable, which is denoted by x. One form of its syntax is fminbnd(’function’, x1, x2) where function is a string containing the name of the function. The fminbnd function returns a value of x that minimizes the function in the interval x1 ≤x ≤x2. For example, fminbnd(’cos’,0,4) returns the value 3.1416. C5-2 FAll 2012

When using fminbnd it is more convenient to define the function in a function file. For example, if y =1 −xe−x, define the following function file: function y = f2(x) y = 1-x.*exp(-x); To find the value of x that gives a minimum of y for 0 ≤x ≤5, type >> x = fminbnd(’f2’,0,5) The answer is x = 1. To find the minimum value of y, type >> y = f2(x). The result is y = 0.6321. C5-2 FAll 2012

Other forms of fminbnd function To find the maximum of a function , use the fminbnd function with the negative of the function of interest. For example, to find the maximum of y =x e-x over the interval 0 ≤ x ≤ 5, you must define the function file as follows: function y = f3 (x) y = -x . *exp(-x); C5-2 FAll 2012

A function can have one or more local minima and a global minimum. If the specified range of the independent variable does not enclose the global minimum, fminbnd will not find the global minimum. Fminbnd will find a minimum that occurs on a boundary. C5-2 FAll 2012

Plot of the function y = 0.025x 5−0.0625x 4−0.333x 3+x 2. This function has one local and one global minimum. On the interval [1, 4] the minimum is at the boundary, x = 2.8236 C5-2 FAll 2012 Figure 3.2–2

The fminsearch function To find the minimum of a function of more than one variable, use the fminsearch function. One form of its syntax is: fminsearch(’function’, x0) where function is a string containing the name of the function. The vector x0 is a guess that must be supplied by the user. C5-2 FAll 2012

To minimize the function f = xe−x2−y2 we first define it in an M-file, using the vector x whose elements are z(1) = x and z(2) = y. function f = f4(z) f = z(1).*exp(-z(1).^2-z(2).^2); Suppose we guess that the minimum is near x = y = 0. The session is >>fminsearch(’f4’,[0,0]) ans=-0.7071 0.000 Thus the minimum occurs at x = −0.7071, y = 0. C5-2 FAll 2012