Mathematics    

Representing Functions in MATLAB

MATLAB can represent mathematical functions by expressing them as MATLAB functions in M-files or as inline objects. For example, consider the function

This function can be used as input to any of the function functions.

As MATLAB Functions

You can find the function above in the M-file named humps.m.

To evaluate the function humps at 2.0, use @ to obtain a function handle for humps, and then pass the function handle to feval.

As Inline Objects

A second way to represent a mathematical function at the command line is by creating an inline object from a string expression. For example, you can create an inline object of the humps function

You can then evaluate f at 2.0.

You can also create functions of more than one argument with inline by specifying the names of the input arguments along with the string expression. For example, the following function has two input arguments x and y.


  Function Summary Plotting Mathematical Functions