Userdefined functions Lec12 Practical matters We assume that

  • Slides: 25
Download presentation
User-defined functions Lec-12

User-defined functions Lec-12

Practical matters We assume that scripts and other functions are stored in the directory

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

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

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

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

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

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

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.