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

Linear Programming, Ft. Loudoun and Watts Bar are two large hydroelectric d...

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

Reading from a file, Reading from a File: A file has been once created...

Reading from a File: A file has been once created; it can be read into a matrix variable. When the file is a data file, the load function will read from the file filename.ext

Function [x, please show me how this is coded in MATLAB

please show me how this is coded in MATLAB

Earth''s magnetic field, to plot Earth''s magnetic field on world map in ma...

to plot Earth''s magnetic field on world map in matlab

Design and implement binary digital modulation, Design and implement Binary...

Design and implement Binary digital modulation for a specific input signal frequency, sampling frequency and signal level for binary frequency shift keying (BFSK) by applying MATLA

Linspace function, Linspace function: Likewise, the linspace function ...

Linspace function: Likewise, the linspace function generates a linearly spaced vector; linspace(x,y,n) generates a vector with n values in the inclusive range from x to y. For

Example of printing vectors, Example of Printing vectors: For vectors ...

Example of Printing vectors: For vectors & matrices, even though formatting cannot be specified, the disp function may be simpler to use in common than fprintf as it displays

College algebra, #question how to solve radicals exponents..

#question how to solve radicals exponents..

Write a computer program using matlab, From A to B the inlet valve is open ...

From A to B the inlet valve is open and the steam pressure increases linearly from 0.1000 MPa absolute to 15.00 MPa absolute, 1000°C. The inlet valve closes and from B to C the

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