Define a function, MATLAB Programming

Assignment Help:

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;

 

 


Related Discussions:- Define a function

Creating row vectors, Creating row Vectors: There are many ways to gen...

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

Finite difference method, Finite Difference Method for An Elliptic Partial ...

Finite Difference Method for An Elliptic Partial Differential Equation   Problem  Use the finite difference method and MatLab code to solve the 2D steady-state heat equat

Calculate the velocity of groundwater, The characteristic properties of an ...

The characteristic properties of an aquifer can be used to calculate groundwater velocities, v groundwater (L/T), according to: where KH (L/T) is the hydraulic conductivit

Find and plot the magnitude of the dtft, An FIR filter has coefficients b =...

An FIR filter has coefficients b = [ 1.0000   -0.6387    1.0214    0.8210   -0.7470    1.0920 ] (a) Find H(z) for the filter and plot its frequency response (magnitude and phase

Program that perform k nearest neighbours algorithm, 1) Convert the table i...

1) Convert the table into format convenient for the processing with MATLAB. 2) Prepare a program that perform K Nearest Neighbours algorithm using Euclidian distance. (Your prog

ANFIS, How to design a FIR filter using ANFIS in MATLAB

How to design a FIR filter using ANFIS in MATLAB

Matlab cubic eqn, how can i model this eqn: solve n plot x vs v x^3-2x^2+x...

how can i model this eqn: solve n plot x vs v x^3-2x^2+x=v^2(.532*10^-3) by putting v=0 to 20 and find the change in x

A matlab program to produce a map of the route, Micro-mouse is an engineeri...

Micro-mouse is an engineering design competition created by IEEE in the late 1970s. Small robotic "mice" solve a 16x16 cell maze. The mice are completely autonomous and must find t

Real time color recognition, Hello my name is lalitkumar and I am a student...

Hello my name is lalitkumar and I am a student.I needed help in MATLAB for recognition of colour randomly using webcam realtime for RGB without external trigger.please mail the co

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd