Sophie

Sophie

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

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

<html lang="en">
<head>
<title>Calling 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="Expressions.html#Expressions" title="Expressions">
<link rel="prev" href="Index-Expressions.html#Index-Expressions" title="Index Expressions">
<link rel="next" href="Arithmetic-Ops.html#Arithmetic-Ops" title="Arithmetic Ops">
<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="Calling-Functions"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Arithmetic-Ops.html#Arithmetic-Ops">Arithmetic Ops</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Index-Expressions.html#Index-Expressions">Index Expressions</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Expressions.html#Expressions">Expressions</a>
<hr>
</div>

<h3 class="section">8.2 Calling Functions</h3>

<p>A <dfn>function</dfn> is a name for a particular calculation.  Because it has
a name, you can ask for it by name at any point in the program.  For
example, the function <code>sqrt</code> computes the square root of a number.

   <p>A fixed set of functions are <dfn>built-in</dfn>, which means they are
available in every Octave program.  The <code>sqrt</code> function is one of
these.  In addition, you can define your own functions. 
See <a href="Functions-and-Scripts.html#Functions-and-Scripts">Functions and Scripts</a>, for information about how to do this.

   <p><a name="index-arguments-in-function-call-453"></a>The way to use a function is with a <dfn>function call</dfn> expression,
which consists of the function name followed by a list of
<dfn>arguments</dfn> in parentheses.  The arguments are expressions which give
the raw materials for the calculation that the function will do.  When
there is more than one argument, they are separated by commas.  If there
are no arguments, you can omit the parentheses, but it is a good idea to
include them anyway, to clearly indicate that a function call was
intended.  Here are some examples:

<pre class="example">     sqrt (x^2 + y^2)      # <span class="roman">One argument</span>
     ones (n, m)           # <span class="roman">Two arguments</span>
     rand ()               # <span class="roman">No arguments</span>
</pre>
   <p>Each function expects a particular number of arguments.  For example, the
<code>sqrt</code> function must be called with a single argument, the number
to take the square root of:

<pre class="example">     sqrt (<var>argument</var>)
</pre>
   <p>Some of the built-in functions take a variable number of arguments,
depending on the particular usage, and their behavior is different
depending on the number of arguments supplied.

   <p>Like every other expression, the function call has a value, which is
computed by the function based on the arguments you give it.  In this
example, the value of <code>sqrt (</code><var>argument</var><code>)</code> is the square root of
the argument.  A function can also have side effects, such as assigning
the values of certain variables or doing input or output operations.

   <p>Unlike most languages, functions in Octave may return multiple values. 
For example, the following statement

<pre class="example">     [u, s, v] = svd (a)
</pre>
   <p class="noindent">computes the singular value decomposition of the matrix <code>a</code> and
assigns the three result matrices to <code>u</code>, <code>s</code>, and <code>v</code>.

   <p>The left side of a multiple assignment expression is itself a list of
expressions, and is allowed to be a list of variable names or index
expressions.  See also <a href="Index-Expressions.html#Index-Expressions">Index Expressions</a>, and <a href="Assignment-Ops.html#Assignment-Ops">Assignment Ops</a>.

<ul class="menu">
<li><a accesskey="1" href="Call-by-Value.html#Call-by-Value">Call by Value</a>
<li><a accesskey="2" href="Recursion.html#Recursion">Recursion</a>
</ul>

   </body></html>