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

Digging the dirt - autonomous mining robots , Digging the Dirt: Autonomous...

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

What is matlab, MATLAB is a high-performance language for technical computi...

MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions

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

Write the iterative newton root fi nding function, Write the iterative Newt...

Write the iterative Newton root nding function from lecture to be recursive. The function declaration should be root = newtonRec(f,df,x,tol). The inputs to the function are: ?

Find the value of delta equation, Solve the optimality condition for each P...

Solve the optimality condition for each P equation against M according to the following relation: Condition for Optimality:         ∇ M = λ ∇ P      with respect to C and T.

Operator precedence rules, Operator Precedence Rules: A few operators ...

Operator Precedence Rules: A few operators have precedence over the others. For illustration, in the expression 4 + 5 * 3, the multiplication takes the precedence over additio

Determine the ball temperature , In the manufacturing of ball bearings, the...

In the manufacturing of ball bearings, the components, such as the ball, are hardened through a process of heating and then rapid cooling or "quenching" by submersion in an oil or

Temperature dependence of vacancy concentrations, write a computer program ...

write a computer program that will provide a user with the equilibrium concentration of vacancies in a metallic element as a function of temperature.Temperature range should be men

Passing multiple arguments, Passing Multiple Arguments: In many situai...

Passing Multiple Arguments: In many situaion it is essential to pass more than one argument to the function. For illustration, the volume of a cone is given by here r

Control system, 1. Design a suitable phase-lead controller. You should expl...

1. Design a suitable phase-lead controller. You should explain in detail how your design has been developed. Your solution should include Bode plots constructed both manually and

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