MATH 2370 Lecture Notes - Lecture 5: Generic Function, Entire Function, Matlab

19 views2 pages

Document Summary

>>out =@(x,y)sin(x)/(exp(y); %x and y are local inputs. Equivalent to: function z = out(x,y) z = sin(x)/exp(y) end. Another use: function functions ex: we want to compute the secant slope in a function for any math function we might want to pass to it function s=secslope(x1,x2,func) y1=func(x1) y2=func(x2) s=(y2-y1)/(x2-x1) end function y=sinexp(x) y=sin(x)/exp(x); end. Note: function definitions could be done in same script or separate m-file. Using an anonymous function as input ex: >> sinexp=@(x) sin(x)/exp(x); %definition. ^don"t need an @ symbol because we already "turned" it into a variable before. ^make it a function handle because built in are not anonymous. Note: the "generic" function name (in the input) and the function (handle) replacing it must have the same input/output structure ex: function y=mainfunc(a,n,func) b=a/2; x=3*ones(n,1) Intro to programming with matlab page 1 x=3*ones(n,1) [u1,v1,w1]=func(a,b,x) %meant to have a, b as scalars and x as a vector, output is 3 vectors b=2*a y=x/2.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related textbook solutions

Related Documents