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
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

if i have a 3x2 double.. how can i run a for loop for this matrix so tht it can subtracted values of he adjacent neighbors?

a. Develop and submit the simulation described above. b. Provide a screen shot of the outputs of the DispConfig and MCResults functions. c. Notes: • Include the PPConfig f

The purpose of this lab is to enhance the ECE311 student's understanding of filter behavior and filter design and to provide the student the opportunity to demonstrate skills in li

Need help with creating functions in matlab.

Looping Statements: Consider the problem of computing the area of a circle with radius of 0.3 centimeters-a MATLAB program certainly is not required to do that; you would use

Relational Expressions: The Conditions in if statements use expressions which are theoretically, or logically, either true or false. These expressions are termed as relational

clear clc %% DATA INPUT filename = input('Enter file name, including its extension: ', 's'); D = load(filename); %or load('Mphi.out'); %% %Trendline %Evaluates

A. Introduction The project consists of two parts. In the first part you are asked to perform some preliminary calculation and plotting, and to write the introduction for your

Simulation of a transmission system with a 4-fsk modulation scheme; using non-coherent detection method and an awgn channel. System description: 1. Input: A. Random binary