Functions with local variables, MATLAB Programming

Functions with Local Variables:

The functions we have seen faraway have been very easy. Though, in many situations the computations in a function are more complex, and may need the use of extra variables within the function; these are known as local variables.

For illustration, a closed cylinder is being constructed of a material which costs a dollar amount per square foot. We will write a function which will compute and return the cost of the material, rounded up to the nearby square foot, for a cylinder with a certain radius and a certain height. The total surface area for the closed cylinder is

SA = 2πrh + 2πr2

For illustration, for a cylinder with radius of 32 inches and height 73 inches, and the cost per square foot of material is $4.50, the computation would be given by the algorithm shown below:

(A) Compute the surface area SA = 2*π * 32 * 73 + 2 * π * 32 * 32 inches squared

(B) Compute the SA in square feet = SA/144

(C) Compute the total cost = SA in square feet * cost per square foot

The function involves local variables to store the intermediate results.

1712_Functions with local variables.png

Posted Date: 10/18/2012 7:24:52 AM | Location : United States







Related Discussions:- Functions with local variables, Assignment Help, Ask Question on Functions with local variables, Get Answer, Expert's Help, Functions with local variables Discussions

Write discussion on Functions with local variables
Your posts are moderated
Related Questions

Passing Multiple Arguments: In many situaion it is essential to pass more than one argument to the function. For illustration, the volume of a cone is given by here r

In the manufacturing of ball bearings, the components, such as the ball, are hardened through a process of heating and then rapid cooling or "quenching" by submersion in an oil or

Operators: There are in general two types of operators: unary operators that operate on a single value or operand; and binary operators, that operate on two values or operands

A filter described by the equation:    y(n) = x(n) + x(n-1) + 0.9 y(n-1) - 0.81 y(n-2) (a) Find the transfer function H(z) for the filter and find the poles and zeros of the fil

This problem is intended to demonstrate some problems that can arise from the finite precision of numerical calculations performed with computers.  We will do this by approximating

Example of Printing vectors: For vectors & matrices, even though formatting cannot be specified, the disp function may be simpler to use in common than fprintf as it displays

Problem: Consider a trapezoidal piece of polymer film as shown below. The parallel sides of the trapezoid are insulated and the temperature of the bottom and diagonal sides are f

A three degree of freedom system is shown in Figure.  The three masses are each 1 kg and are constrained to move in the directions shown.   The three stiffnesses are   5 kN/m, 50 k

I need a source code for hand detection in matlab please ....