MoreFunctions_handle_v2

MoreFunctions_handle_v2 - More Functions in MATLAB...

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

View Full Document Right Arrow Icon
More Functions in MATLAB
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 .
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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)
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
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
Background image of page 7

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

View Full DocumentRight Arrow Icon
-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
Background image of page 8
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.
Background image of page 9

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

View Full DocumentRight Arrow Icon
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.
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online