1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
|
<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> x.a = 1; x.b = [1, 2; 3, 4]; x.c = "string";
octave:2> x.a
x.a = 1
octave:3> x.b
x.b =
1 2
3 4
octave:4> x.c
x.c = string
</PRE>
<LI>Structures may be copied.
<PRE>
octave:1> 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> x.b.d = 3
x.b.d = 3
octave:2> x.b
ans =
{
d = 3
}
octave:3> x.b.d
ans = 3
</PRE>
<LI>Functions can return structures.
<PRE>
octave:1> function y = f (x)
> y.re = real (x);
> y.im = imag (x);
> endfunction
octave:2> 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> [x.u, x.s(2:3,2:3), x.v] = svd ([1, 2; 3, 4]);
octave:2> 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>`&&'</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>`&'</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>
|