- publishing free software manuals
GNU Octave Manual Version 3
by John W. Eaton, David Bateman, Søren Hauberg
Paperback (6"x9"), 568 pages
ISBN 095461206X
RRP £24.95 ($39.95)

Get a printed copy>>>

11.9.2 Anonymous Functions

Anonymous functions are defined using the syntax

@(argument-list) expression

Any variables that are not found in the argument list are inherited from the enclosing scope. Anonymous functions are useful for creating simple unnamed functions from expressions or for wrapping calls to other functions to adapt them for use by functions like quad. For example,

f = @(x) x.^2;
quad (f, 0, 10)
    => 333.33

creates a simple unnamed function from the expression x.^2 and passes it to quad,

quad (@(x) sin (x), 0, pi)
    => 2

wraps another function, and

a = 1;
b = 2;
quad (@(x) betainc (x, a, b), 0, 0.4)
    => 0.13867

adapts a function with several parameters to the form required by quad. In this example, the values of a and b that are passed to betainc are inherited from the current environment.

ISBN 095461206XGNU Octave Manual Version 3See the print edition