This preview shows pages 1–8. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Aduvanced use of quad Numerical differentiation Numerical Differentiation Dhavide Aruliah UOIT MATH 2070U c D. Aruliah (UOIT) Numerical Differentiation MATH 2070U 1 / 34 Aduvanced use of quad Numerical differentiation Numerical Differentiation 1 More advanced application of quad Functions and function functions Integrals with parameters 2 Numerical differentiation (finitedifference) formulas Numerical derivative approximations from Taylor’s theorem Numerical differentiation of numerical data Numerical differentiation in MATLAB: diff and gradient c D. Aruliah (UOIT) Numerical Differentiation MATH 2070U 2 / 34 Aduvanced use of quad Numerical differentiation Functions and function functions Reminder about functions y = f ( x ) The distinction between x , y , and f is important! x is the value of independent variable/input y is the value of dependent variable/output f is the function itself c D. Aruliah (UOIT) Numerical Differentiation MATH 2070U 4 / 34 Aduvanced use of quad Numerical differentiation Functions and function functions Function mfiles Traditional MATLAB way to define a function foo.m function y = foo(x) y = x.^3 .*exp(2*x) + cos(x).^2./(1+x.^4); Identifiers foo and y should be distinct Output variable y must be assigned somewhere in mfile Function mfiles can have many input/output variables Other variables created are local to function workspace [Input variables generally passed by value] [Also possible to have subfunctions, nested functions, etc.] c D. Aruliah (UOIT) Numerical Differentiation MATH 2070U 5 / 34 Aduvanced use of quad Numerical differentiation Functions and function functions Anonymous functions Anonymous function defined at command line foo = @(x) x.^3 .*exp(2*x) + cos(x).^2./(1+x.^4); Anonymous functions do not require creating mfile to use Anonymous functions can return only one output variable Anonymous functions must be short (oneline statement) Anonymous functions cannot use control flow (loops) Anonymous functions can use vectorised operators c D. Aruliah (UOIT) Numerical Differentiation MATH 2070U 6 / 34 Aduvanced use of quad Numerical differentiation Functions and function functions Function functions Fundamental requirement for scientific computing: functions that accept other functions as input e.g., to find a zero x * such that f ( x * ) = 0 given f e.g., to compute integral R b a f ( x ) dx given f , a , b Function handle : data type (denoted @ ) for functions (like pointer) Function function : a function that operates on another function (i.e., accepts a function handle as an input argument) We have seen numerous function functions (e.g., fzero , quad ) f = @(z) zcos(z); % Create anonymous function x = fzero(f,[0,1]) % Find zero of function f in [0,1] I = quad(f,0,1) % Compute integral of f on [0,1] c D. Aruliah (UOIT) Numerical Differentiation MATH 2070U 7 / 34 Aduvanced use of quad Numerical differentiation Functions and function functions Important: syntax of function functions When passing a function...
View
Full
Document
This note was uploaded on 06/20/2011 for the course MATH 2070 taught by Professor Aruliahdhavidhe during the Winter '10 term at UOIT.
 Winter '10
 aruliahdhavidhe
 Math

Click to edit the document details