help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Corrections to 2 of 3 examples in manual 11.9.2 Anonymous Functions


From: Henry F. Mollet
Subject: Corrections to 2 of 3 examples in manual 11.9.2 Anonymous Functions
Date: Thu, 27 Sep 2007 13:39:27 -0700
User-agent: Microsoft-Entourage/11.1.0.040913

Corrections to 2 of 3 examples in manual 11.9.2 Anonymous Functions.
Henry

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 ##correct:
##octave-2.9.14:26> f = @(x) x.^2;
##octave-2.9.14:27> quad (f, 0, 10)
##ans =  333.33

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

     quad (@(x) sin (x), 0, pi)
         => 1.8391 ## not correct:
##octave-2.9.14:23> quad (@(x) sin (x), 0, pi)
##ans =  2

wraps another function, and

     a = 1;
     b = 2;
     quad (@(x) betainc (x, a, b), 0, 0.4)
         => 1.3867 ## not correct:
##octave-2.9.14:24> a=1; b=2;
##octave-2.9.14:25> quad (@(x) betainc (x, a, b), 0, 0.4)
ans =  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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]