Practical matters We assume that scripts and other functions are stored in the directory H: Directory H: Script 1. m Script 2. m Script 3. m cylinder. m other. F. m
Understanding Function Calls • There is a substitution mechanism • Local variables are used to carry out the computations
Let us execute the script line-by-line and see what happens during the call to function f.
x, y, z serve as local variables during the process. X is referred to as an input parameter.
Repeat to Stress the distinction between local variables and variables in the calling program
Back to function Draw. Rect(a, b, L, W, c) % Adds rectangle to the current window. % Assume hold is on. (a, b) is the center of the rectangle, and % L is the length and W is the breadth. Vertices of the % rectangle are: % (a-L/2, b-W/2), (a+L/2, b+W/2), (a-L/2, b+W/2). % The fill color c is one of ‘r’, ‘g’, ‘y’, ‘b’, ‘w’, ‘k’, ‘c’, or ‘m’. The specification is given in the form of comments just after the header statement
Back to function Draw. Rect(a, b, L, W, c) % Adds rectangle to the current window. % Assume hold is on. (a, b) is the center of the rectangle, and % L is the length and W is the breadth. Vertices of the % rectangle are: % (a-L/2, b-W/2), (a+L/2, b+W/2), (a-L/2, b+W/2). % The fill color c is one of ‘r’, ‘g’, ‘y’, ‘b’, ‘w’, ‘k’, ‘c’, or ‘m’. It must be clear, complete and concise.