MoreFunctions_handle_v2

# MoreFunctions_handle_v2 - More Functions in MATLAB...

This preview shows pages 1–11. Sign up to view the full content.

More Functions in MATLAB

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

View Full Document
Functions that operate on other functions A function F() can take another function G() as an argument by using a special @ notation: F(@G,…) F() takes G() as an argument Matlab documentation refers to these as function functions The operator @ produces what is called a “handle” to the function whose name follows the symbol. Although the text discusses 3 other “methods” for passing a function in an argument list to another function, the only method acceptable in this course is the function handle .
Functions that operate on other functions Let's look at three useful Matlab functions: fzero(…) - finds a zero of a function fminbnd(…) - finds a minimum of a function quad(…) - numerically evaluates a definite integral over a function

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

View Full Document
fzero() - Finds a zero of a function of one variable (solves Fname(x)=0) x = fzero(@Fname,x0) Fname: a function name x0: either a single x value starting point or [xL xR] x value range with Fname(xL)being opposite in sign from Fname(xR)
humps(x) - example function 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 -20 0 20 40 60 80 100

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

View Full Document
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 -20 0 20 40 60 80 100 x = fzero(@Fname,x0) % finds x near 1 so humps(x)=0 >> fzero(@humps,1) ans = 1.2995 % finds x between 0 and 2 so humps(x) = 0 >> fzero(@humps,[0,2]) ans = 1.2995
x 2 - 2 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2

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

View Full Document
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 x = fzero(@Fname,x0) First define G(x) in a file G.m: function [y] = G(x) y = x^2 - 2; Then: >> x = fzero(@G,[0,2]) x = 1.4142 >> x = fzero(@G,[-2,0]) x = -1.4142
fzero() - Additional input variables x = fzero(@Fname,x0,[],P1,P2,. ..) P1,P2,. ..: These are additional input variables (or parameters) required by Fname after the first parameters needed by fzero.

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

View Full Document
fzero() - Additional input variables x = fzero(@Fname,x0,[],P1,P2,. ..) P1,P2,. ..: These are additional input variables (or parameters) required by Fname after the first parameters needed by fzero. This is a placeholder.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 40

MoreFunctions_handle_v2 - More Functions in MATLAB...

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

View Full Document
Ask a homework question - tutors are online