Professional Documents
Culture Documents
edu
function[W]= myfun(x,y,z)
OR equivalently
function W = myfun(x,y,z)
c. For function with no output and 3 inputs
function[ ]= ellipse(L,S,theta)
OR equivalently
function = ellipse(L,S,theta)
This could be for a function that draws an ellipse with major & minor axes L and S and rotation theta
2.
Function Call
General: we have to give values for the inputs and use variable name that store the values of the outputs. Below are examples of how the above functions are called
a. [A,B,C] = yourfun(-5,4)
This means that input values are x=-5, y=4, and output values for A, B, and C, are calculated according to the function prescription
b. [M] = myfun(2,4,-3)
OR equivalently
M = myfun(2,4,-3) c. ellipse(10,5,pi/6)
3.
This command evaluates the values of the output variables for a function for given values of the inputs. For example we can find values for the outputs of yourfun for input values of x=-5 and y=4 using feval in the following manner:
[a,b,c] = feval(yourfun,-4,5)
or alternatively we can define a function handle for yourfun, call it func1 and use it with feval:
This command is used to generate a function in the command window or within a script file or a function file. For example for a function of 3 variables x, y, z we have
Distance=inline(sqrt(Ra.^2+Rb.^2... -2*Ra.*Rb.*cos(ab)),Ra,Rb,ab)
Note that because the statement was too long we used ... for continuation. In the command file the following will appear: