Define a function, MATLAB Programming

Define a function:

The radius of a circle is passed to the function to input argument  rad; the function computes the area of this circle and stores it in the output argument area. In the function header, we have reserved word function, then an output argument area followed by an assignment operator =, then the name of the function (similar as the name of the M-file), and then the input argument  rad, that is the radius. As there is an output argument in the function header, anywhere in the body of the function we should assign a value to this output argument. This is how the value is returned from a function. In this situation, the function is easy and all we have to do is assign to the output argument area the value of the built-in constant pi multiplied by the square of the input argument rad.

The function can be exhibited in the Command Window by using the  type command.

>> type calcarea

function area = calcarea(rad)

% This computes the area of a circle

area = pi * rad * rad;

 

 

Posted Date: 10/18/2012 7:17:04 AM | Location : United States







Related Discussions:- Define a function, Assignment Help, Ask Question on Define a function, Get Answer, Expert's Help, Define a function Discussions

Write discussion on Define a function
Your posts are moderated
Related Questions
Input Function: The Input statements read in values from the default or standard input device. In most of the systems, the default input device is the keyboard; therefore the

Function char: The function char does the opposite; it converts from any number type to the type char: >> char(numequiv) ans = a As the letters of the alphabet are

How do you write a programme that asks the user for a number between 1 and 1000 and calculates the sum of its digits?

Hold and legend function: hold: is a toggle which freezes the present graph in the figure window, so that the new plots will be superimposed on the present one. Just hold

construct a matlab program to calculate and to plot the electron and hole concentration as a function of the Fermi-level in an energy gab of Si at a Given temperature and the carri

Run the MATLAB script sum = single(0); term = single(1); n=1; while sum + term > sum sum = sum+term; n=n+1; term = 1/n; end n Explain what you think it is trying to do. What wou

coding of sep protocol


Digging the Dirt: Autonomous Mining Robots   Mining is a multi-billion dollar industry and a critical part of the Australian economy. Much of the day-to-day work on mining sites

Using numerical techniques, plot the intensity distribution for LP 01 and LP 11 modes. Vary the value of V (reduce it to 1.5) and plot several of the intensity plots (of LP 01 )