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
Illustrations of calling the function: Here are illustrations of calling the function: >> cylcost(32,73,4.50) ans = 661.5000 >> fprintf('The cost would be $%.2f\n'

Scripts to Produce and Customize the Simple Plots: The MATLAB has many graphing capabilities. In most cases, customizing plots are desired and this is the simplest to accompli

First order differential equations: Euler's method Finally, we consider ?nding the numerical solution for a ?rst order differential equation given an initial value. We consider


how to find absolute value of a number

Solve for unknowns 'x' and 'y' from Equations (1) and (2) using MATLAB. (However, if MATLAB is not the appropriate software to solve these two simultaneous equations, please sugges

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

how to reverse the digits of positive number by using mod function?

How to make EMG analysis by Matlab?

The Plot Function: We will begin with a very simple graph of one point using the plot function. The script, plotonepoint, below plots only one point. To do this, at first the