Sophie

Sophie

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

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

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

<h2 class="chapter">9 Evaluation</h2>

<p>Normally, you evaluate expressions simply by typing them at the Octave
prompt, or by asking Octave to interpret commands that you have saved in
a file.

   <p>Sometimes, you may find it necessary to evaluate an expression that has
been computed and stored in a string, which is exactly what the
<code>eval</code> function lets you do.

<!-- parse.cc -->
   <p><a name="doc_002deval"></a>

<div class="defun">
&mdash; Built-in Function:  <b>eval</b> (<var>try, catch</var>)<var><a name="index-eval-546"></a></var><br>
<blockquote><p>Parse the string <var>try</var> and evaluate it as if it were an Octave
program.  If that fails, evaluate the optional string <var>catch</var>. 
The string <var>try</var> is evaluated in the current context,
so any results remain available after <code>eval</code> returns.

        <p>The following example makes the variable <var>a</var> with the approximate
value 3.1416 available.

     <pre class="example">          eval("a = acos(-1);");
</pre>
        <p>If an error occurs during the evaluation of <var>try</var> the <var>catch</var>
string is evaluated, as the following example shows:

     <pre class="example">          eval ('error ("This is a bad example");',
                'printf ("This error occurred:\n%s\n", lasterr ());');
               -| This error occurred:
                  This is a bad example
</pre>
        </blockquote></div>

<ul class="menu">
<li><a accesskey="1" href="Calling-a-Function-by-its-Name.html#Calling-a-Function-by-its-Name">Calling a Function by its Name</a>
<li><a accesskey="2" href="Evaluation-in-a-Different-Context.html#Evaluation-in-a-Different-Context">Evaluation in a Different Context</a>
</ul>

   </body></html>