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

Built-In Functions and help: There are lots of built-in functions in a MATLAB. The help command is used to find out what functions MATLAB has, and how to use them. For illustr

Write a pseudo-code showing the list of steps to take for solving the given problem. In this process, you should identify the functions that are to be used in the program. Develop

Diary Files: Before doing this assignment, please read the document Notes on Matlab Assignments (available from the course web page). It describes how to record the results of your

Consider the function: f(x) = 7 - 28x + 42x 2 - 28x 3 + 7x 4 : Write a script findPolyRoot.m to nd, as accurately as you can, the root of f(x) near x = 2. Your script mu

how to write the national log (ln(x)) in matlap ?

Consider the analytic solution of the projectile problem described. Write a MATLAB script that will prompt the user to enter the launch speed and angle, and will compute the peak h

Solve the optimality condition for each P equation against M according to the following relation: Condition for Optimality:         ∇ M = λ ∇ P      with respect to C and T.

the basic equation of modeling radioactive decay is where the amount of the radioactive substance is at time and is the decay rate. Some radioactive substances decay into other rad

what are the steps we need to write in the script to get themedian for X values