Function functions, MATLAB Programming

Assignment Help:

Function Functions:

The one reason for using function handles is to be able to pass functions to the other functions-these are known as function functions.

For illustration, let's say we have a function which generates an x vector. The y vector is generated by computing a function at each of the x points, and then such points are plotted.

 

1114_Function Functions.png

What we want is to be able to pass the function to be the value of funh, such as sin, cos, tan, and so forth. It doesn't work to merely pass the name of the function:

>> fnfnexamp(sin)

??? Error using ==> sin

Not enough input arguments.

 

Rather than, we have to pass the handle of the function:

>> fnfnexamp(@sin)

which generates the y vector as sin(x) and then brings up the plot as shown in figure.

 

753_Function Functions1.png

Passing rather the handle to the cos function would graph cosine rather than of sine:

>> fnfnexamp(@cos)

We can also pass the handle of any user-defined or anonymous function to the fnfnexamp function.

The other way of doing this is to use the built-in function str2func which will convert a string into a function handle:

 

2434_Function Functions2.png

This would also be called by passing a string to the function, and again would generate the similar plot:

>> fnstrfn2('sin')

There is also a function func2str which will convert a function handle into a string. This can be used to put the name of the function in the plot as shown in above figure.

Though these techniques also work, it seems easier and cleaner to merely pass the function handle to the function.

The MATLAB has few built-in function functions. The one built-in function is fplot that plots a function between the limits which are specified. The format of the call for fplot is:

fplot(fnhandle, [xmin xmax])


Related Discussions:- Function functions

Plot the input and the output of the filter on a single plot, An FIR filter...

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

Find and compute the natural frequencies, An electric overhead traveling cr...

An electric overhead traveling crane, consisting of a girder, trolley, and wire rope, is shown in figure. The girder has a flexural rigidity (EI) of 6x10 12 lb.in 2 and a span (L

Printing - matrices, Printing - matrices: For matrices, the MATLAB unw...

Printing - matrices: For matrices, the MATLAB unwinds the matrix column by column. For illustration, consider the random 2 × 3 matrix as shown below: >> mat = randint(2,3,[

planar pantograph-based leg, The diagram shown on the next page represents...

The diagram shown on the next page represents a planar pantograph-based leg for a walking robot. This model utilizes only one DOF to generate the walking gait at the foot link 'n

Plot the poles and zeros of the filter using zplane, A filter described by ...

A filter described by the equation:    y(n) = x(n) + x(n-1) + 0.9 y(n-1) - 0.81 y(n-2) (a) Find the transfer function H(z) for the filter and find the poles and zeros of the fil

Produce a random real number, Produce a random real number: To produce...

Produce a random real number: To produce a random real number in the range from low to high, at first create the variables low and high. And then, use the expression rand*(hig

#title.the number of pixels related to the actual phase, #question.i want t...

#question.i want to know the number of pixels related to the actual phase value and want to separate the zero phase valued pixels from the image..

Programming concept, The Programming Concept: In most of the programmi...

The Programming Concept: In most of the programming languages, random function returns a real number; therefore the real number would then have to be rounded to produce a rand

Illustration of variable number of input arguments, Illustration of Variabl...

Illustration of Variable number of input arguments: In this situation, it was supposed that the radius will always be passed to the function. The function header can hence be

Simulation of a pn junction, would you please send the programing code simu...

would you please send the programing code simulation.

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