Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > by-pkgid > c50fd783f0fa860cebb2522ba56bd22c > files > 344

octave-2.0.16-11mdk.i586.rpm

<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.51
     from ./Octave-FAQ.texi on 9 October 1998 -->

<TITLE>Frequently asked questions about Octave (with answers) - What features are unique to Octave?</TITLE>
</HEAD>
<BODY>
Go to the <A HREF="Octave-FAQ_1.html">first</A>, <A HREF="Octave-FAQ_2.html">previous</A>, <A HREF="Octave-FAQ_4.html">next</A>, <A HREF="Octave-FAQ_11.html">last</A> section, <A HREF="Octave-FAQ_toc.html">table of contents</A>.
<P><HR><P>


<H1><A NAME="SEC3" HREF="Octave-FAQ_toc.html#TOC3">What features are unique to Octave?</A></H1>



<H2><A NAME="SEC4" HREF="Octave-FAQ_toc.html#TOC4">Command and variable name completion</A></H2>

<P>
<A NAME="IDX1"></A>
<A NAME="IDX2"></A>
<A NAME="IDX3"></A>
<A NAME="IDX4"></A>

</P>
<P>
Typing a TAB character (ASCII code 9) on the command line causes Octave
to attempt to complete variable, function, and file names.  Octave uses
the text before the cursor as the initial portion of the name to
complete.

</P>
<P>
For example, if you type <SAMP>`fu'</SAMP> followed by TAB at the Octave prompt,
Octave will complete the rest of the name <SAMP>`function'</SAMP> on the command
line (unless you have other variables or functions defined that begin
with the characters <SAMP>`fu'</SAMP>).  If there is more than one possible
completion, Octave will ring the terminal bell to let you know that your
initial sequence of characters is not enough to specify a unique name.
To complete the name, you may either edit the initial character sequence
(usually adding more characters until completion is possible) or type
another TAB to cause Octave to display the list of possible completions.

</P>


<H2><A NAME="SEC5" HREF="Octave-FAQ_toc.html#TOC5">Command history</A></H2>

<P>
<A NAME="IDX5"></A>
<A NAME="IDX6"></A>

</P>
<P>
When running interactively, Octave saves the commands you type in an
internal buffer so that you can recall and edit them.  Emacs and vi
editing modes are available with Emacs keybindings enabled by default.

</P>
<P>
When Octave exits, the current command history is saved to the file
<TT>`~/.octave_hist'</TT>, and each time Octave starts, it inserts the
contents of the <TT>`~/.octave_hist'</TT> file in the history list so that
it is easy to begin working where you left off.

</P>


<H2><A NAME="SEC6" HREF="Octave-FAQ_toc.html#TOC6">Data structures</A></H2>

<P>
<A NAME="IDX7"></A>
<A NAME="IDX8"></A>

</P>
<P>
Octave includes a limited amount of support for organizing data in
structures.  The current implementation uses an associative array
with indices limited to strings, but the syntax is more like C-style
structures.  Here are some examples of using data structures in Octave.

</P>

<UL>
<LI>Elements of structures can be of any value type.


<PRE>
octave:1&#62; x.a = 1; x.b = [1, 2; 3, 4]; x.c = "string";
octave:2&#62; x.a
x.a = 1
octave:3&#62; x.b
x.b =

  1  2
  3  4

octave:4&#62; x.c
x.c = string
</PRE>

<LI>Structures may be copied.


<PRE>
octave:1&#62; y = x
y =
{
  a = 1
  b =

    1  2
    3  4

  c = string
  s =

    0.00000  0.00000  0.00000
    0.00000  5.46499  0.00000
    0.00000  0.00000  0.36597

  u =

    -0.40455  -0.91451
    -0.91451   0.40455

  v =

    -0.57605   0.81742
    -0.81742  -0.57605
}
</PRE>

<LI>Structure elements may reference other structures.


<PRE>
octave:1&#62; x.b.d = 3
x.b.d = 3
octave:2&#62; x.b
ans =
{
  d = 3
}
octave:3&#62; x.b.d
ans = 3
</PRE>

<LI>Functions can return structures.


<PRE>
octave:1&#62; function y = f (x)
&#62; y.re = real (x);
&#62; y.im = imag (x);
&#62; endfunction

octave:2&#62; f (rand + rand*I);
ans =
{
  im = 0.18033
  re = 0.19069
}
</PRE>

<LI>Function return lists can include structure elements, and they may

be indexed like any other variable.


<PRE>
octave:1&#62; [x.u, x.s(2:3,2:3), x.v] = svd ([1, 2; 3, 4]);
octave:2&#62; x
x =
{
  s =

    0.00000  0.00000  0.00000
    0.00000  5.46499  0.00000
    0.00000  0.00000  0.36597

  u =

    -0.40455  -0.91451
    -0.91451   0.40455

  v =

    -0.57605   0.81742
    -0.81742  -0.57605
}
</PRE>

<LI>You can also use the function <CODE>is_struct</CODE> to determine

whether a given value is a data structure.  For example


<PRE>
is_struct (x)
</PRE>

returns 1 if the value of the variable <VAR>x</VAR> is a data structure.
</UL>

<P>
This feature should be considered experimental, but you should expect it
to work.  Suggestions for ways to improve it are welcome.

</P>


<H2><A NAME="SEC7" HREF="Octave-FAQ_toc.html#TOC7">Short-circuit boolean operators</A></H2>

<P>
<A NAME="IDX9"></A>
<A NAME="IDX10"></A>
<A NAME="IDX11"></A>
<A NAME="IDX12"></A>

</P>
<P>
Octave's <SAMP>`&#38;&#38;'</SAMP> and <SAMP>`||'</SAMP> logical operators are evaluated in
a short-circuit fashion (like the corresponding operators in the C
language) and work differently than the element by element operators
<SAMP>`&#38;'</SAMP> and <SAMP>`|'</SAMP>.

</P>


<H2><A NAME="SEC8" HREF="Octave-FAQ_toc.html#TOC8">Increment and decrement operators</A></H2>

<P>
<A NAME="IDX13"></A>
<A NAME="IDX14"></A>
<A NAME="IDX15"></A>
<A NAME="IDX16"></A>

</P>
<P>
Octave includes the C-like increment and decrement operators <SAMP>`++'</SAMP>
and <SAMP>`--'</SAMP> in both their prefix and postfix forms.

</P>
<P>
For example, to pre-increment the variable <VAR>x</VAR>, you would write
<CODE>++<VAR>x</VAR></CODE>.  This would add one to <VAR>x</VAR> and then return the new
value of <VAR>x</VAR> as the result of the expression.  It is exactly the
same as the expression <CODE><VAR>x</VAR> = <VAR>x</VAR> + 1</CODE>.

</P>
<P>
To post-increment a variable <VAR>x</VAR>, you would write <CODE><VAR>x</VAR>++</CODE>.
This adds one to the variable <VAR>x</VAR>, but returns the value that
<VAR>x</VAR> had prior to incrementing it.  For example, if <VAR>x</VAR> is equal
to 2, the result of the expression <CODE><VAR>x</VAR>++</CODE> is 2, and the new
value of <VAR>x</VAR> is 3.

</P>
<P>
For matrix and vector arguments, the increment and decrement operators
work on each element of the operand.

</P>
<P>
It is not currently possible to increment index expressions.  For
example, you might expect that the expression <CODE><VAR>v</VAR>(4)++</CODE> would
increment the fourth element of the vector <VAR>v</VAR>, but instead it
results in a parse error.  This problem may be fixed in a future
release of Octave.

</P>


<H2><A NAME="SEC9" HREF="Octave-FAQ_toc.html#TOC9">Unwind-protect</A></H2>

<P>
<A NAME="IDX17"></A>

</P>
<P>
Octave supports a limited form of exception handling modelled after the
unwind-protect form of Lisp.  The general form of an
<CODE>unwind_protect</CODE> block looks like this:

</P>

<PRE>
unwind_protect
  <VAR>body</VAR>
unwind_protect_cleanup
  <VAR>cleanup</VAR>
end_unwind_protect
</PRE>

<P>
Where <VAR>body</VAR> and <VAR>cleanup</VAR> are both optional and may contain any
Octave expressions or commands.  The statements in <VAR>cleanup</VAR> are 
guaranteed to be executed regardless of how control exits <VAR>body</VAR>.

</P>
<P>
The <CODE>unwind_protect</CODE> statement is often used to reliably restore
the values of global variables that need to be temporarily changed.

</P>


<H2><A NAME="SEC10" HREF="Octave-FAQ_toc.html#TOC10">Variable-length argument lists</A></H2>

<P>
<A NAME="IDX18"></A>
<A NAME="IDX19"></A>

</P>
<P>
Octave has a real mechanism for handling functions that take an
unspecified number of arguments, so it is no longer necessary to place
an upper bound on the number of optional arguments that a function can
accept.

</P>
<P>
Here is an example of a function that uses the new syntax to print a
header followed by an unspecified number of values:

</P>

<PRE>
function foo (heading, ...)
  disp (heading);
  va_start ();
  while (--nargin)
    disp (va_arg ());
  endwhile
endfunction
</PRE>

<P>
Calling <CODE>va_start()</CODE> positions an internal pointer to the first
unnamed argument and allows you to cycle through the arguments more than
once.  It is not necessary to call <CODE>va_start()</CODE> if you do not plan
to cycle through the arguments more than once.

</P>
<P>
The function <CODE>va_arg()</CODE> returns the value of the next available
argument and moves the internal pointer to the next argument.  It is an
error to call <CODE>va_arg()</CODE> when there are no more arguments
available.

</P>
<P>
It is also possible to use the keyword <VAR>all_va_args</VAR> to pass all
unnamed arguments to another function.

</P>


<H2><A NAME="SEC11" HREF="Octave-FAQ_toc.html#TOC11">Variable-length return lists</A></H2>

<P>
<A NAME="IDX20"></A>
<A NAME="IDX21"></A>

</P>
<P>
Octave also has a real mechanism for handling functions that return an
unspecified number of values, so it is no longer necessary to place an
upper bound on the number of outputs that a function can produce.

</P>
<P>
Here is an example of a function that uses the new syntax to produce
<SAMP>`N'</SAMP> values:

</P>

<PRE>
function [...] = foo (n)
  for i = 1:n
    vr_val (i);
  endfor
endfunction
</PRE>



<H2><A NAME="SEC12" HREF="Octave-FAQ_toc.html#TOC12">Built-in ODE and DAE solvers</A></H2>

<P>
<A NAME="IDX22"></A>
<A NAME="IDX23"></A>

</P>
<P>
Octave includes LSODE and DASSL for solving systems of stiff ordinary
differential and differential-algebraic equations.  These functions are
built in to the interpreter.

</P>
<P><HR><P>
Go to the <A HREF="Octave-FAQ_1.html">first</A>, <A HREF="Octave-FAQ_2.html">previous</A>, <A HREF="Octave-FAQ_4.html">next</A>, <A HREF="Octave-FAQ_11.html">last</A> section, <A HREF="Octave-FAQ_toc.html">table of contents</A>.
</BODY>
</HTML>