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
Illustrations of if statement: illustrations of running this script: >> sqrtifexamp Please enter a number: -4.2 The sqrt of 4.2 is 2.0 >> sqrtifexamp Please ent

what are data collect this topic,how i can create algorithm in mat lab what language support easy to this topic

Ft. Loudoun and Watts Bar are two large hydroelectric dams, the former upstream of the latter. The level of Watts Bar Lake must be kept within limits for recreational purposes, and

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

Write a MATLAB program that calculates the arithmetic mean, the geometric mean, and the root-mean-square average for a given set of values. Your program must use 3 functions t

Problem of a projectile being launched at an angle of O at an initial velocity ofv. The equations for the height hand horizontallocation x as functions of time t are as follo


Creating row Vectors: There are many ways to generate row vector variables. The most important way is to put the values which you want in the vector in square brackets, separa

A band pass FIR filter is required to pass frequencies from 5KHz to 8KHz, using a sample rate of 40K i) Explain how this would map to normalization sampling frequencies in radia

Ant Colony Optimization for Optimization of Route path taken Ant Colony Algorithm is a potential candidate for coupled, 3D optimisation. Ant Colony Algorithm enjoys the overall