Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 3e60ff9d4d6f58c8fbd17208f14089fa > files > 49

octave-doc-3.2.3-3mdv2010.0.i586.rpm

<html lang="en">
<head>
<title>Anonymous Functions - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Function-Handles-Inline-Functions-and-Anonymous-Functions.html#Function-Handles-Inline-Functions-and-Anonymous-Functions" title="Function Handles Inline Functions and Anonymous Functions">
<link rel="prev" href="Function-Handles.html#Function-Handles" title="Function Handles">
<link rel="next" href="Inline-Functions.html#Inline-Functions" title="Inline Functions">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<a name="Anonymous-Functions"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Inline-Functions.html#Inline-Functions">Inline Functions</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Function-Handles.html#Function-Handles">Function Handles</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Function-Handles-Inline-Functions-and-Anonymous-Functions.html#Function-Handles-Inline-Functions-and-Anonymous-Functions">Function Handles Inline Functions and Anonymous Functions</a>
<hr>
</div>

<h4 class="subsection">11.9.2 Anonymous Functions</h4>

<p>Anonymous functions are defined using the syntax

<pre class="example">     @(<var>argument-list</var>) <var>expression</var>
</pre>
   <p class="noindent">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 <code>quad</code>.  For
example,

<pre class="example">     f = @(x) x.^2;
     quad (f, 0, 10)
         &rArr; 333.33
</pre>
   <p class="noindent">creates a simple unnamed function from the expression <code>x.^2</code> and
passes it to <code>quad</code>,

<pre class="example">     quad (@(x) sin (x), 0, pi)
         &rArr; 2
</pre>
   <p class="noindent">wraps another function, and

<pre class="example">     a = 1;
     b = 2;
     quad (@(x) betainc (x, a, b), 0, 0.4)
         &rArr; 0.13867
</pre>
   <p class="noindent">adapts a function with several parameters to the form required by
<code>quad</code>.  In this example, the values of <var>a</var> and <var>b</var> that
are passed to <code>betainc</code> are inherited from the current
environment.

   </body></html>