Mercurial > hg > octave-lyh
annotate doc/faq/Octave-FAQ.texi @ 8128:9e4a09b35cdb
Update the FAQ
author | David Bateman <dbateman@free.fr> |
---|---|
date | Mon, 22 Sep 2008 13:36:01 -0400 |
parents | fb66330b2608 |
children | de8b07e95d1b |
rev | line source |
---|---|
7018 | 1 % Copyright (C) 1997, 1998, 1999, 2001, 2003, 2004, 2005, 2007 John W. Eaton |
2 % | |
3 % This file is part of Octave. | |
4 % | |
5 % Octave is free software; you can redistribute it and/or modify it | |
6 % under the terms of the GNU General Public License as published by the | |
7 % Free Software Foundation; either version 3 of the License, or (at | |
8 % your option) any later version. | |
9 % | |
10 % Octave is distributed in the hope that it will be useful, but WITHOUT | |
11 % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 % FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 % for more details. | |
14 % | |
15 % You should have received a copy of the GNU General Public License | |
16 % along with Octave; see the file COPYING. If not, see | |
17 % <http://www.gnu.org/licenses/>. | |
18 | |
2866 | 19 \input texinfo.tex @c -*-texinfo-*- |
20 | |
3030 | 21 @setfilename Octave-FAQ.info |
2866 | 22 @settitle Frequently asked questions about Octave (with answers) |
23 | |
24 @setchapternewpage off | |
5099 | 25 @direntry |
6584 | 26 * Octave-FAQ: (Octave-FAQ). Frequently asked questions about Octave |
5099 | 27 @end direntry |
2866 | 28 @titlepage |
29 @title Octave FAQ | |
30 @subtitle Frequently asked questions about Octave | |
8128 | 31 @subtitle September 2008 |
2866 | 32 @sp 1 |
6900 | 33 @author John W. Eaton and David Bateman |
2866 | 34 @page |
35 @end titlepage | |
36 | |
5423 | 37 @ifnottex |
4830 | 38 @node Top |
2866 | 39 @top |
40 @unnumbered Preface | |
41 @cindex FAQ for Octave, latest version | |
5423 | 42 @end ifnottex |
2866 | 43 |
44 This is a list of frequently asked questions (FAQ) for Octave users. | |
45 | |
6584 | 46 We are always looking for new questions (@emph{with} answers), better |
47 answers, or both. Please send suggestions to @email{bug@@octave.org}. | |
48 If you have general questions about Octave, or need help for something | |
49 that is not covered by the Octave manual or the FAQ, please use the | |
50 @email{help@@octave.org} mailing list. | |
2866 | 51 |
52 This FAQ is intended to supplement, not replace, the Octave manual. | |
6584 | 53 Before posting a question to the @email{help@@octave.org} mailing list, |
54 you should first check to see if the topic is covered in the manual. | |
2866 | 55 |
56 @menu | |
6583 | 57 * What is Octave?:: |
58 * How can I cite Octave?:: | |
8128 | 59 * Series 3.0.N:: |
6583 | 60 * Octave Features:: |
61 * Learning more about Octave:: | |
62 * Getting Octave:: | |
63 * Installation:: | |
2866 | 64 * Common problems:: |
6584 | 65 * How do I ...?:: |
6583 | 66 * MATLAB compatibility:: |
2866 | 67 * Index:: |
68 @end menu | |
69 | |
4830 | 70 @node What is Octave? |
2866 | 71 @chapter What is Octave? |
72 | |
73 Octave is a high-level interactive language, primarily intended for | |
74 numerical computations that is mostly compatible with | |
75 @sc{Matlab}.@footnote{@sc{Matlab} is a registered trademark of The MathWorks, | |
6583 | 76 Inc.} |
2866 | 77 |
6583 | 78 Octave can do arithmetic for real, complex or integer-valued scalars |
79 and matrices, solve sets of nonlinear algebraic equations, integrate | |
80 functions over finite and infinite intervals, and integrate systems of | |
81 ordinary differential and differential-algebraic equations. | |
2866 | 82 |
83 Octave uses the GNU readline library to handle reading and editing | |
84 input. By default, the line editing commands are similar to the | |
85 cursor movement commands used by GNU Emacs, and a vi-style line | |
86 editing interface is also available. At the end of each session, the | |
87 command history is saved, so that commands entered during previous | |
88 sessions are not lost. | |
89 | |
6879 | 90 The Octave distribution includes a 590+ page Texinfo manual. Access |
2866 | 91 to the complete text of the manual is available via the help command |
6583 | 92 @c really, the *complete* text? |
2866 | 93 at the Octave prompt. |
94 | |
6583 | 95 @menu |
96 * Who develops Octave?:: | |
6584 | 97 * Why GNU Octave?:: |
6583 | 98 * What version should I use?:: |
99 * On what platforms does Octave run?:: | |
100 @end menu | |
101 | |
102 @node Who develops Octave? | |
103 @section Who develops Octave? | |
104 | |
6584 | 105 Discussions about writing the software that would eventually become |
106 Octave started in about 1988 with James B. Rawlings and John W. Eaton at | |
107 the University of Texas. John W. Eaton was the original author of | |
108 Octave, starting full-time development in February 1992. He is still | |
109 the primary maintainer. The community | |
110 of users/developers has in addition contributed some code and fuels the | |
111 discussion on the mailing lists @email{help@@octave.org} (user forum), | |
112 @email{bug@@octave.org} (bug reports), @email{maintainers@@octave.org} | |
113 (development issues), and @email{octave-dev@@lists.sourceforge.net} (all | |
114 things related to the Octave Forge repository of user-contributed | |
115 functions). | |
6583 | 116 |
6584 | 117 @node Why GNU Octave? |
118 @section Why GNU Octave? | |
6583 | 119 |
6584 | 120 The GNU Project was launched in 1984 to develop a complete Unix-like |
121 operating system which is free software: the GNU system. | |
122 | |
123 GNU is a recursive acronym for ``GNU's Not Unix''; it is pronounced | |
124 guh-noo, approximately like canoe. | |
6583 | 125 |
6584 | 126 The Free Software Foundation (FSF) is the principal organizational |
127 sponsor of the GNU Project. | |
128 | |
129 Octave became GNU Octave in 1997 (beginning with version 2.0.6). This | |
130 meant agreeing to consider Octave a part of the GNU Project and support | |
131 the efforts of the FSF. However, Octave is not and has never been | |
132 developed by the FSF. | |
133 | |
134 For more information about the GNU project, see @url{www.gnu.org}. | |
6583 | 135 |
136 @cindex FSF [Free Software Foundation] | |
137 @cindex GNU [GNU's not unix] | |
138 | |
139 @node What version should I use? | |
140 @section What version should I use? | |
141 | |
142 In general, you will find the latest version on | |
6584 | 143 @url{http://www.octave.org/download.html}. It is |
6583 | 144 recommended to use the ``testing'' version of octave for general use, |
145 and the ``development'' version if you want the latest features. | |
146 | |
147 A list of user-visible changes since the last release is available in | |
148 the file @file{NEWS}. The file @file{ChangeLog} in the source | |
149 distribution contains a more detailed record of changes made since the | |
150 last release. | |
151 | |
152 @node On what platforms does Octave run? | |
153 @section On what platforms does Octave run? | |
154 | |
6584 | 155 Octave runs on various Unices---at least Linux and Solaris, Mac OS X, |
156 Windows and anything you can compile it on. Binary distributions exist | |
6583 | 157 at least for Debian, Suse, Fedora and RedHat Linuxes (Intel and AMD |
158 CPUs, at least), for Mac Os X and Windows' 98, 2000 and XP. | |
159 | |
2866 | 160 Two and three dimensional plotting is fully supported using gnuplot. |
161 | |
162 The underlying numerical solvers are currently standard Fortran ones | |
163 like Lapack, Linpack, Odepack, the Blas, etc., packaged in a library | |
164 of C++ classes. If possible, the Fortran subroutines are compiled | |
165 with the system's Fortran compiler, and called directly from the C++ | |
166 functions. If that's not possible, you can still compile Octave if | |
167 you have the free Fortran to C translator f2c. | |
168 | |
169 Octave is also free software; you can redistribute it and/or modify it | |
170 under the terms of the GNU General Public License as published by the | |
171 Free Software Foundation. | |
172 | |
4830 | 173 @node How can I cite Octave? |
174 @chapter How can I cite Octave? | |
4831 | 175 |
176 Pointing to @url{http://www.octave.org} is good, because that gives | |
177 people a direct way to find out more. If citation of a URL is not | |
178 allowed by a publisher, or if you also want to point to a traditional | |
179 reference, then you can cite the Octave manual: | |
4830 | 180 |
181 @example | |
182 @group | |
6584 | 183 @@BOOK@{eaton:2002, |
184 author = "John W. Eaton", | |
185 title = "GNU Octave Manual", | |
186 publisher = "Network Theory Limited", | |
187 year = "2002", | |
188 isbn = "0-9541617-2-6" | |
189 @} | |
4830 | 190 @end group |
191 @end example | |
192 | |
8128 | 193 @node Series 3.0.N |
194 @chapter What's new in version series 3.0.N and 3.1.N of Octave | |
6583 | 195 |
8128 | 196 The 3.0.N series has enough new features to justify a major version |
197 number change. The 3.0.N series brings | |
6583 | 198 |
199 @itemize @bullet | |
200 | |
201 @item integer types | |
202 | |
203 @item fixed point arithmetic | |
204 | |
205 @item sparse matrices | |
206 | |
207 @item Linear programming code based on GLPK | |
208 | |
209 @item 64-bit compilation support | |
210 | |
211 @item gzipped files and stream and consequently support of matlab v7 files | |
2866 | 212 |
6583 | 213 @item better support for both msvc and mingw |
214 | |
7116 | 215 @item a fully compatible MEX interface |
6583 | 216 |
6606 | 217 @item many many other minor features and compatibility changes |
6583 | 218 |
219 @end itemize | |
220 | |
6735 | 221 Here are some features that have been around since 2.1.N |
6583 | 222 |
223 @itemize @bullet | |
2866 | 224 |
6583 | 225 @item NDarrays |
226 | |
227 @item cells | |
228 | |
229 @end itemize | |
230 | |
8128 | 231 The 3.1.N series is the current development release and will become a |
232 3.2.N release in the future. This series brings the new features | |
233 | |
234 @itemize | |
235 @item OpenGL backend | |
236 | |
237 An experimental OpenGL graphics backend to replace the gnuplot | |
238 | |
239 @item Object Orient Programming | |
240 | |
241 @item Block comments | |
242 | |
243 @item imwrite and imread | |
244 | |
245 The functions are based on the GraphicsMagick library. | |
246 | |
247 @item Lazy transpose | |
248 | |
249 Special treatment in the parser of things like "a' * b", where the | |
250 transpose is never explicitly formed but a flag is rather passed to the | |
251 underlying LAPACK code. | |
252 | |
253 @item Single precision type | |
254 @end itemize | |
255 | |
256 | |
4830 | 257 @node Octave Features |
2866 | 258 @chapter What features are unique to Octave? |
259 | |
260 @menu | |
6583 | 261 * Functions defined on the command-line:: |
262 * Comments with #:: | |
263 * Strings delimitted by double quotes ":: | |
264 * Line continuation by backslash:: | |
265 * Informative block closing:: | |
266 * Coherent syntax:: | |
267 * Exclamation mark as not operator:: | |
2866 | 268 * Increment and decrement operators:: |
269 * Unwind-protect:: | |
6583 | 270 * Built-in ODE and DAE solvers:: |
2866 | 271 @end menu |
272 | |
8128 | 273 This section refers to Matlab R2008b and Octave 2.1.51. |
2866 | 274 |
6583 | 275 @node Functions defined on the command-line |
276 @section Functions defined on the command-line | |
2866 | 277 |
6583 | 278 Functions can be defined by entering code on the command line, a |
6584 | 279 feature not supported by the other leading brand. For example, you may |
6583 | 280 type: |
2866 | 281 |
282 @example | |
283 @group | |
6583 | 284 octave:1> function s = hello_string (to_who) |
285 > ## Say hello | |
286 > if nargin<1, to_who = "World"; end | |
287 > s = ["Hello ",\ | |
288 > to_who]; | |
289 > endfunction | |
290 octave:2> hello_string ("Moon") | |
291 ans = Hello Moon | |
2866 | 292 @end group |
293 @end example | |
294 | |
6583 | 295 @node Comments with # |
296 @section Comments with # | |
297 | |
6584 | 298 The pound character, @samp{#}, may be used to start comments, in addition |
299 to @samp{%}. See the previous example. The major advantage of this is | |
300 that as @samp{#} is also a comment character for unix script files, any | |
301 file that starts with a string like @samp{#! /usr/bin/octave -q} will be | |
302 treated as an octave script and be executed by octave. | |
2866 | 303 |
6583 | 304 @node Strings delimitted by double quotes " |
305 @section Strings delimitted by double quotes " | |
6584 | 306 The double quote, @samp{"}, may be used to delimit strings, in addition to |
307 the single quote @samp{'}. See the previous example. Also, double-quoted | |
308 strings include backslash interpretation (like C++, C, and Perl) while | |
309 single quoted are uninterpreted (like Matlab and Perl). | |
6583 | 310 |
311 @node Line continuation by backslash | |
312 @section Line continuation by backslash | |
313 | |
6584 | 314 Lines can be continued with a backslash, @samp{\}, in addition to three |
315 points @samp{@dots{}}. See the previous example. | |
6583 | 316 |
317 @node Informative block closing | |
318 @section Informative block closing | |
319 | |
6584 | 320 You may close @code{function}, @code{for}, @code{while}, @code{if}, |
321 @dots{} blocks with @code{endfunction}, @code{endfor}, @code{endwhile}, | |
322 @dots{} keywords in addition to using @code{end}. As with Matlab, the | |
323 @code{end} (or @code{endfunction}) keyword that marks the end of a | |
324 function defined in a @file{.m} file is optional. | |
2866 | 325 |
6583 | 326 @node Coherent syntax |
327 @section Coherent syntax | |
328 | |
329 Indexing other things than variables is possible, as in: | |
330 @example | |
331 @group | |
332 octave:1> [3 1 4 1 5 9](3) | |
333 ans = 4 | |
334 octave:2> cos([0 pi pi/4 7])(3) | |
335 ans = 0.70711 | |
336 @end group | |
337 @end example | |
338 | |
339 @node Exclamation mark as not operator | |
340 @section Exclamation mark as not operator | |
341 | |
342 The exclamation mark '!' (aka ``Bang!'') is a negation operator, just | |
343 like the tilde '~': | |
2866 | 344 |
345 @example | |
346 @group | |
6583 | 347 octave:1> if ! strcmp (program_name, "octave"), |
348 > "It's an error" | |
349 > else | |
350 > "It works!" | |
351 > end | |
352 ans = It works! | |
2866 | 353 @end group |
354 @end example | |
355 | |
4830 | 356 @node Increment and decrement operators |
2866 | 357 @section Increment and decrement operators |
358 | |
359 @cindex Increment operators | |
360 @cindex Decrement operators | |
361 @cindex Operators, increment | |
362 @cindex Operators, decrement | |
363 | |
6584 | 364 If you like the @samp{++}, @samp{+=} etc operators, rejoice! |
2866 | 365 Octave includes the C-like increment and decrement operators @samp{++} |
6583 | 366 and @samp{--} in both their prefix and postfix forms, in addition to |
367 @samp{+=}, @samp{-=}, @samp{*=}, @samp{/=}, @samp{^=}, @samp{.*=}, | |
368 @samp{./=}, and @samp{.^=}. | |
2866 | 369 |
370 For example, to pre-increment the variable @var{x}, you would write | |
371 @code{++@var{x}}. This would add one to @var{x} and then return the new | |
372 value of @var{x} as the result of the expression. It is exactly the | |
373 same as the expression @code{@var{x} = @var{x} + 1}. | |
374 | |
6584 | 375 To post-increment a variable @var{x}, you would write @code{x++}. |
2866 | 376 This adds one to the variable @var{x}, but returns the value that |
377 @var{x} had prior to incrementing it. For example, if @var{x} is equal | |
6584 | 378 to 2, the result of the expression @code{x++} is 2, and the new |
2866 | 379 value of @var{x} is 3. |
380 | |
381 For matrix and vector arguments, the increment and decrement operators | |
382 work on each element of the operand. | |
383 | |
384 | |
4830 | 385 @node Unwind-protect |
2866 | 386 @section Unwind-protect |
387 | |
388 @cindex Unwind-protect | |
389 | |
390 Octave supports a limited form of exception handling modelled after the | |
391 unwind-protect form of Lisp. The general form of an | |
392 @code{unwind_protect} block looks like this: | |
393 | |
394 @example | |
395 @group | |
396 unwind_protect | |
397 @var{body} | |
398 unwind_protect_cleanup | |
399 @var{cleanup} | |
400 end_unwind_protect | |
401 @end group | |
402 @end example | |
403 | |
404 @noindent | |
405 Where @var{body} and @var{cleanup} are both optional and may contain any | |
406 Octave expressions or commands. The statements in @var{cleanup} are | |
407 guaranteed to be executed regardless of how control exits @var{body}. | |
408 | |
409 The @code{unwind_protect} statement is often used to reliably restore | |
410 the values of global variables that need to be temporarily changed. | |
411 | |
8128 | 412 Matlab can be made to do something similar with their @code{OnCleanUp} |
413 function that was introduced in 2008a. | |
414 | |
4830 | 415 @node Built-in ODE and DAE solvers |
2866 | 416 @section Built-in ODE and DAE solvers |
417 | |
418 @cindex DASSL | |
419 @cindex LSODE | |
420 | |
421 Octave includes LSODE and DASSL for solving systems of stiff ordinary | |
422 differential and differential-algebraic equations. These functions are | |
423 built in to the interpreter. | |
424 | |
6583 | 425 @node Learning more about Octave |
426 @chapter What documentation exists for Octave? | |
427 | |
428 @menu | |
429 * Documentation:: | |
430 * Getting additional help:: | |
431 * User community:: | |
432 * Bug reports:: | |
433 @end menu | |
434 | |
435 | |
4830 | 436 @node Documentation |
6583 | 437 @section What documentation exists for Octave? |
2866 | 438 |
439 @cindex Octave, documentation | |
440 | |
6879 | 441 The Octave distribution includes a 590+ page manual that is also |
2866 | 442 distributed under the terms of the GNU GPL. |
6583 | 443 It is available on the web at |
444 @url{http://www.octave.org/docs.html} and you will also | |
445 find there instructions on how to order a paper version. | |
446 | |
447 The complete text of the Octave manual is also available using the GNU | |
448 Info system via the GNU Emacs, info, or xinfo programs, or by using | |
449 the @samp{help -i} command to start the GNU info browser directly from | |
450 the Octave prompt. | |
451 | |
452 If you have problems using this documentation, or find that some topic | |
453 is not adequately explained, indexed, or cross-referenced, please send | |
6584 | 454 a bug report to @email{bug@@octave.org}. |
6583 | 455 |
2866 | 456 |
6583 | 457 @node Getting additional help |
458 @section Getting additional help | |
459 | |
460 @cindex Additional help | |
461 @cindex Mailing lists, help-octave | |
462 | |
6584 | 463 If you can't find an answer to your question, the |
464 @email{help@@octave.org} mailing list is available for questions related | |
465 to using, installing, and porting Octave that are not adequately | |
466 answered by the Octave manual or by this document. | |
6583 | 467 |
468 @node User community | |
469 @section User community | |
470 | |
6584 | 471 To subscribe to the list, go to @url{www.octave.org/archive.html} and |
472 follow the link to the subscription page for the list. | |
2866 | 473 |
6653 | 474 @strong{Please do not} send requests to be added or removed from the |
6583 | 475 mailing list, or other administrative trivia to the list itself. |
476 | |
477 An archive of old postings to the help-octave mailing list is maintained | |
478 on @url{http://www.octave.org/archive.html}. | |
479 | |
6584 | 480 You will also find some user advice and code spread over the web. Good |
6583 | 481 starting points are the Octave Wiki @url{http://wiki.octave.org} and |
7483
fb66330b2608
don't special case SH_LD for FreeBSD and OpenBSD
John W. Eaton <jwe@octave.org>
parents:
7116
diff
changeset
|
482 Octave-Forge @url{http://octave.sourceforge.net} |
6583 | 483 |
484 @node Bug reports | |
485 @section I think I have found a bug in Octave. | |
486 | |
487 @cindex Bug in Octave, newly found | |
488 | |
489 ``I think I have found a bug in Octave, but I'm not sure. How do I know, | |
490 and who should I tell?'' | |
2866 | 491 |
6583 | 492 @cindex Manual, for Octave |
493 | |
494 First, see the section on bugs and bug reports in the Octave manual. | |
495 When you report a bug, make sure to describe the type of computer you | |
496 are using, the version of the operating system it is running, and the | |
497 version of Octave that you are using. Also provide enough code so that | |
498 the Octave maintainers can duplicate your bug. | |
499 | |
500 If you have Octave working at all, the easiest way to do this is to use | |
501 the Octave function @code{bug_report}. When you execute this function, | |
502 Octave will prompt you for a subject and then invoke the editor on a | |
503 file that already contains all the configuration information. When you | |
504 exit the editor, Octave will mail the bug report for you (in a unix-like | |
505 operating system). | |
506 | |
507 @cindex Octave bug report | |
508 @cindex Mailing lists, bug-octave | |
509 | |
510 If for some reason you cannot use Octave's @code{bug_report} function, | |
6584 | 511 mail your bug report to @email{bug@@octave.org}. Your message needs to |
6583 | 512 include enough information to allow the maintainers of Octave to fix the |
513 bug. Please read the section on bugs and bug reports in the Octave | |
514 manual for a list of things that should be included in every bug report. | |
515 | |
2866 | 516 |
4830 | 517 @node Getting Octave |
6583 | 518 @chapter Getting Octave |
2866 | 519 |
520 @menu | |
6583 | 521 * Source code:: |
522 * Pre-compiled binary packages:: | |
523 * Octave for other platforms:: | |
2866 | 524 @end menu |
525 | |
6583 | 526 @node Source code |
527 @section Source code | |
528 @cindex Source code | |
2866 | 529 |
6583 | 530 Source code is available on the Octave development site, where you are |
531 sure to get the latest version. | |
2866 | 532 |
6583 | 533 @itemize @bullet |
534 @item @url{http://www.octave.org/download.html} | |
535 @item @url{ftp://ftp.octave.org/pub/octave/} | |
536 @end itemize | |
2866 | 537 |
6583 | 538 Since Octave is distrubted under the terms of the GPL, you can get |
539 Octave from a friend who has a copy, by anonymous FTP, or by ordering | |
540 a tape or CD-ROM from the Free Software Foundation (FSF). | |
2866 | 541 |
6583 | 542 @node Pre-compiled binary packages |
543 @section Pre-compiled binary packages | |
544 @cindex Pre-compiled binary packages | |
545 @cindex Binaries | |
2866 | 546 |
6584 | 547 The Octave project does not distribute binary packages, but other |
548 projects do. For an up-to-date listing of packagers, see: | |
2866 | 549 |
6583 | 550 @itemize @bullet |
551 @item @url{http://www.octave.org/download.html} | |
552 @item @url{http://wiki.octave.org/wiki.pl?CategoryInstall} | |
553 @end itemize | |
2866 | 554 |
6583 | 555 As of today, Octave binaries are available at least on Debian, RedHat, |
556 Suse and Fedora Linuxes, Mac OS X, Windows' 98, 2000 and XP. | |
2866 | 557 |
4830 | 558 @node Octave for other platforms |
2866 | 559 @section How do I get a copy of Octave for (some other platform)? |
560 | |
561 @cindex VMS support | |
562 @cindex VAX | |
563 @cindex MS-DOS support | |
3154 | 564 @cindex Windows support |
2866 | 565 @cindex DJGPP |
566 @cindex EMX | |
567 @cindex OS/2 support | |
568 | |
6879 | 569 Octave currently runs on Unix-like systems, Mac OS X, and Windows. |
570 It should be possible to make Octave work on other systems as well. | |
571 If you are interested in porting Octave to other systems, please contact | |
6584 | 572 @email{bug@@octave.org}. |
2866 | 573 |
6583 | 574 @c @menu |
575 @c * Octave for Unix:: | |
576 @c * Octave for other platforms:: | |
577 @c * latest versions:: | |
578 @c @end menu | |
2866 | 579 |
6583 | 580 @c @cindex Octave, ordering |
581 @c @cindex Octave, getting a copy | |
2866 | 582 |
4830 | 583 @node Installation |
2866 | 584 @chapter Installation Issues and Problems |
585 | |
586 @cindex Octave, building | |
587 | |
8128 | 588 Octave 3.2 require approximately 800MB of disk storage to unpack |
6584 | 589 and compile from source (considerably less if you don't compile with |
590 debugging symbols). Once installed, Octave requires approximately 200MB | |
591 of disk space (again, considerably less if you don't compile with | |
592 debugging symbols). | |
2866 | 593 |
594 @menu | |
595 * What else do I need?:: | |
596 * Other C++ compilers?:: | |
597 @end menu | |
598 | |
4830 | 599 @node What else do I need? |
2866 | 600 @section What else do I need? |
601 | |
602 @cindex GNU gcc | |
603 @cindex GNU g++ | |
604 @cindex libg++ | |
605 @cindex GNU Make | |
606 @cindex Flex | |
607 @cindex GNU Bison | |
608 | |
3154 | 609 To compile Octave, you will need a recent version of GNU Make. You |
6584 | 610 will also need GCC 3.3 or later, although GCC 4.1 or later is |
611 recommended. | |
3154 | 612 |
6584 | 613 @strong{You must have GNU Make to compile octave}. Octave's Makefiles |
3154 | 614 use features of GNU Make that are not present in other versions of make. |
615 GNU Make is very portable and easy to install. | |
2866 | 616 |
4830 | 617 @node Other C++ compilers? |
2866 | 618 @section Can I compile Octave with another C++ compiler? |
619 | |
6584 | 620 Yes, but development is done primarily with GCC, so you may hit some |
621 incompatibilities. Octave is intended to be portable to any standard | |
622 conforming compiler. If you have difficulties that you think are bugs, | |
623 please report them to the @email{bug@@octave.org} mailing list, or ask | |
624 for help on the @email{help@@octave.org} mailing list. | |
2866 | 625 |
4830 | 626 @node Common problems |
2866 | 627 @chapter Common problems |
628 | |
629 This list is probably far too short. Feel free to suggest additional | |
630 questions (preferably with answers!) | |
631 | |
632 @itemize @bullet | |
633 @item | |
634 Octave takes a long time to find symbols. | |
635 | |
6606 | 636 Octave uses the @code{genpath} function to recursively add directories |
6900 | 637 to the list of directories searched for function files. Check the list |
6606 | 638 of directories with the @code{path} command. If the path list is very |
639 long check your use of the @code{genpath} function. | |
6735 | 640 |
641 @item | |
6900 | 642 When plotting Octave occasionally gives me errors like @samp{gnuplot> 9 0.735604 |
643 line 26317: invalid command}. | |
6735 | 644 |
645 There is a known bug in gnuplot 4.2 that can cause an off by one error | |
646 while piping data to gnuplot. The relevant gnuplot bug report can be | |
647 found at @url{http://sourceforge.net/tracker/index.php?func=detail&aid=1716556&group_id=2055&atid=102055} | |
648 | |
649 If you have obtained your copy of Octave from a distribution please file | |
650 a bug report requesting that the fix reported in the above bug report be | |
651 included. | |
2866 | 652 @end itemize |
653 | |
6584 | 654 @node How do I ...? |
655 @chapter How do I ...? | |
2866 | 656 |
6583 | 657 @menu |
658 * How do I set the number of displayed decimals?:: | |
659 @end menu | |
2866 | 660 |
6583 | 661 @cindex Tips and tricks |
6584 | 662 @cindex How do I @dots{} ? |
2866 | 663 |
6583 | 664 @node How do I set the number of displayed decimals? |
665 @section How do I set the number of displayed decimals? | |
2866 | 666 |
667 @example | |
668 @group | |
6583 | 669 octave:1> format long |
670 octave:2> pi | |
671 pi = 3.14159265358979 | |
672 octave:3> format short | |
673 octave:4> pi | |
674 pi = 3.1416 | |
2866 | 675 @end group |
676 @end example | |
677 | |
4830 | 678 @node MATLAB compatibility |
2866 | 679 @chapter Porting programs from @sc{Matlab} to Octave |
680 | |
681 @cindex @sc{Matlab} compatibility | |
682 @cindex Compatibility with @sc{Matlab} | |
683 | |
6612 | 684 People often ask |
685 | |
2866 | 686 ``I wrote some code for @sc{Matlab}, and I want to get it running under |
687 Octave. Is there anything I should watch out for?'' | |
688 | |
6612 | 689 or alternatively |
690 | |
691 ``I wrote some code in Octave, and want to share it with @sc{Matlab} | |
6900 | 692 users. Is there anything I should watch out for?'' |
6612 | 693 |
6900 | 694 which is not quite the same thing. There are still a number of |
6612 | 695 differences between Octave and @sc{Matlab}, however in general |
696 differences between the two are considered as bugs. Octave might | |
697 consider that the bug is in @sc{Matlab} and do nothing about it, but | |
698 generally functionality is almost identical. If you find a difference | |
699 between Octave behavior and @sc{Matlab}, then you should send a | |
700 description of this difference (with code illustrating the difference, | |
701 if possible) to @email{bug@@octave.org}. | |
702 | |
703 Furthermore, Octave adds a few syntactical extensions to Matlab that | |
704 might cause some issues when exchanging files between Matlab and Octave | |
705 users. As both Octave and @sc{Matlab} are under constant development the | |
706 information in this section is subject to change at anytime. | |
707 | |
708 You should also look at the page | |
709 @url{http://octave.sourceforge.net/packages.html} and | |
710 @url{http://octave.sourceforge.net/doc/} that has a function reference | |
711 that is up to date. You can use this function reference to see the | |
712 number of octave function that are available and their @sc{Matlab} | |
713 compatibility. | |
714 | |
8128 | 715 The major differences between Octave 3.2.N and @sc{Matlab} R2008a are: |
6612 | 716 |
717 @itemize @bullet | |
718 @item Nested Functions | |
719 | |
6900 | 720 Octave doesn't yet have nested functions. That is |
2866 | 721 |
6612 | 722 @example |
723 @group | |
724 function y = foo (x) | |
6900 | 725 y = bar(x) |
726 function y = bar (x) | |
727 y = @dots{}; | |
728 end | |
6612 | 729 end |
730 @end group | |
731 @end example | |
732 | |
733 There was discussion in Octave of having these even prior to @sc{Matlab}, | |
734 and the decision was made not to have these in Octave at the time for | |
6900 | 735 compatibility. The above written with sub-functions functions would be |
6612 | 736 |
737 @example | |
738 @group | |
739 function y = foo (x) | |
740 y = bar(x) | |
741 end | |
742 function y = bar (x) | |
743 y = @dots{}; | |
744 end | |
745 @end group | |
746 @end example | |
747 | |
748 Now that @sc{Matlab} has recently introduced nested functions, Octave will | |
6900 | 749 probably have them soon as well. Until then nested functions in Octave |
6612 | 750 are treated as sub-functions with the same scoping rules as |
751 sub-functions. | |
752 | |
753 The authors of Octave consider the nested function scoping rules of | |
754 Matlab to be more problems than they are worth as they introduce | |
755 diffiult to find bugs as inadvertantly modifying a variable in a | |
756 nested function that is also used in the parent is particularly easy. | |
757 | |
758 @item Differences in core syntax | |
759 There a few core @sc{Matlab} syntaxes that are not accepted by Octave, | |
760 these being | |
761 | |
762 @itemize @bullet | |
2866 | 763 @item |
6612 | 764 Some limitations on the use of function handles. The major difference is |
6879 | 765 related to nested function scoping rules (as above) and their use with |
6612 | 766 function handles. |
2866 | 767 |
768 @item | |
6612 | 769 Some limitations of variable argument lists on the LHS of an expression, |
770 though the most common types are accepted. | |
771 | |
2866 | 772 @item |
8128 | 773 @sc{Matlab} classdef object oriented programming is not yet supportted, |
774 though work is underway and when development more on to Octave 3.3 this | |
775 will be included in teh development tree. | |
6612 | 776 @end itemize |
777 | |
778 @item Differences in core functions | |
779 A large number of the @sc{Matlab} core functions (ie those that are in | |
780 the core and not a toolbox) are implemented, and certainly all of the | |
781 commonly used ones. There are a few functions that aren't implemented, | |
6879 | 782 for example @code{condest} or to do with specific missing Octave functionality |
6612 | 783 (gui, dll, java, activex, dde, web, and serial functions). Some of the |
784 core functions have limitations that aren't in the @sc{Matlab} | |
6900 | 785 version. For example the @code{sprandn} function can not force a |
6735 | 786 particular condition number for the matrix like @sc{Matlab} can. |
6612 | 787 |
788 @item Just-In-Time compiler | |
789 @sc{Matlab} includes a "Just-In-Time" compiler. This compiler allows the | |
790 acceleration of for-loops in @sc{Matlab} to almost native performance with | |
791 certain restrictions. The JIT must know the return type of all functions | |
792 called in the loops and so you can't include user functions in the loop | |
6900 | 793 of JIT optimized loops. Octave doesn't have a JIT and so to some might |
794 seem slower than @sc{Matlab}. For this reason you must vectorize your code as | |
795 much as possible. The MathWorks themselves have a good document | |
796 discussing vectorization at | |
6612 | 797 @url{http://www.mathworks.com/support/tech-notes/1100/1109.html}. |
798 | |
799 @item Compiler | |
800 On a related point, there is no Octave compiler, and so you can't | |
801 convert your Octave code into a binary for additional speed or | |
6900 | 802 distribution. There is an example of how to do this at |
6612 | 803 @url{http://www.stud.tu-ilmenau.de/~rueckn/}, but this is a very early |
804 example code and would need lots of work to complete it. | |
805 | |
806 @item Graphic Handles | |
807 Up to Octave 2.9.9 there was no support for graphic handles in Octave | |
8128 | 808 itself. In the 3.2.N versions of Octave the support for graphics |
809 handles is converging towards full compatibility. The @code{patch} | |
810 function is currently limited to 2-D patches, due to an underlying | |
811 limitation in gnuplot. | |
6612 | 812 |
813 @item GUI | |
6900 | 814 There are no @sc{Matlab} compatible GUI functions. There are a number of |
815 bindings from Octave to Tcl/Tk, Vtk and zenity included in the | |
816 Octave Forge project (@url{http://octave.sourceforge.net}) for example | |
6612 | 817 that can be used for a GUI, but these are not @sc{Matlab} |
7116 | 818 compatible. Work on a matlab compatible GUI is in an alpha stage in the |
6879 | 819 JHandles package (@url{http://octave.sourceforge.net/jhandles/index.html}). |
820 This might be an issue if you intend to exchange Octave code with | |
821 @sc{Matlab} users. | |
6612 | 822 |
823 @item Simulink | |
824 Octave itself includes no Simulink support. Typically the simulink | |
825 models lag research and are less flexible, so shouldn't really be used | |
6900 | 826 in a research environment. However, some @sc{Matlab} users that try to |
827 use Octave complain about this lack. There is a similar package to | |
828 simulink for the Octave and R projects available at | |
829 @url{http://www.scicraft.org/} | |
6612 | 830 |
831 @item Mex-Files | |
832 Octave includes an API to the matlab MEX interface. However, as MEX is | |
6900 | 833 an API to the internals of @sc{Matlab} and the internals of Octave |
834 differ from @sc{Matlab}, there is necessarily a manipulation of the data | |
835 to convert from a MEX interface to the Octave equivalent. This is | |
836 notable for all complex matrices, where @sc{Matlab} stores complex | |
837 arrays as real and imaginary parts, whereas Octave respects the C99/C++ | |
838 standards of co-locating the real/imag parts in memory. Also due to the | |
839 way @sc{Matlab} allows access to the arrays passed through a pointer, | |
840 the MEX interface might require copies of arrays (even non complex | |
8128 | 841 ones). |
6612 | 842 |
843 @item Block comments | |
8128 | 844 Block comments denoted by "%@{" and "%@}" markers are supported by |
845 Octave with some limitations. The major limitation is that block | |
846 comments are not supported with [] or {}. | |
6612 | 847 |
848 @item Mat-File format | |
849 There are some differences in the mat v5 file format accepted by | |
850 Octave. @sc{Matlab} recently introduced the "-V7.3" save option which is | |
6900 | 851 an HDF5 format which is particularly useful for 64-bit platforms where |
6612 | 852 the standard matlab format can not correctly save variables.. Octave |
6900 | 853 accepts HDF5 files, but is not yet compatible with the "-v7.3" versions |
6612 | 854 produced by @sc{Matlab}. |
855 | |
8128 | 856 Although Octave can load inline abd function handles saved by |
857 @sc{Matlab}, it can not yet save them. | |
6612 | 858 |
859 Finally, Some multi-byte unicode characters aren't yet treated in | |
860 mat-files. | |
861 | |
862 @item Profiler | |
863 Octave doesn't have a profiler. Though there is a patch for a flat | |
864 profiler, that might become a real profiler sometime in the future. see | |
865 the thread | |
866 | |
867 @url{http://www.cae.wisc.edu/pipermail/octave-maintainers/2007-January/001685.html} | |
868 | |
869 for more details | |
870 | |
871 @item Toolboxes | |
872 Octave is a community project and so the toolboxes that exist are | |
6900 | 873 donated by those interested in them through the Octave Forge website |
6612 | 874 (@url{http://octave.sourceforge.net}). These might be lacking in certain |
875 functionality relative to the @sc{Matlab} toolboxes, and might not | |
876 exactly duplicate the matlab functionality or interface. | |
877 | |
878 @item Short-circuit & and | operators | |
6900 | 879 The @code{&} and @code{|} operators in @sc{Matlab} short-circuit when |
880 included in an if statemant and not otherwise. In Octave only the | |
881 @code{&&} and @code{||} short circuit. Note that this means that | |
6612 | 882 |
883 @example | |
884 @group | |
885 if (a | b) | |
886 @dots{} | |
887 end | |
888 @end group | |
889 @end example | |
890 | |
891 and | |
892 | |
893 @example | |
894 @group | |
895 t = a | b; | |
896 if t | |
897 @dots{} | |
898 end | |
899 @end group | |
900 @end example | |
901 | |
6900 | 902 @noindent |
6612 | 903 are different in @sc{Matlab}. This is really a @sc{Matlab} bug, but |
904 there is too much code out there that relies on this behavior to change | |
905 it. Prefer the || and && operators in if statements if possible. | |
2866 | 906 |
6612 | 907 Note that the difference is also significant when either argument is a |
908 function with side effects or if the first argument is a scalar and the | |
909 second argument is an empty matrix. For example, note the difference | |
910 between | |
911 | |
912 @example | |
913 @group | |
914 t = 1 | []; ## results in [], so... | |
915 if (t) 1, end ## in if ([]), this is false. | |
916 @end group | |
917 @end example | |
918 | |
919 and | |
920 | |
921 @example | |
922 if (1 | []) 1, end ## short circuits so condition is true. | |
923 @end example | |
924 | |
925 Another case that is documented in the @sc{Matlab} manuals is that | |
926 | |
927 @example | |
928 @group | |
929 t = [1, 1] | [1, 2, 3]; ## error | |
930 if ([1, 1] | [1, 2, 3]) 1, end ## OK | |
931 @end group | |
932 @end example | |
933 | |
934 Also @sc{Matlab} requires the operands of && and || to be scalar values but | |
935 Octave does not (it just applies the rule that for an operand to be | |
936 considered true, every element of the object must be nonzero or | |
937 logically true). | |
938 | |
939 Finally, note the inconsistence of thinking of the condition of an if | |
940 statement as being equivalent to @code{all(X(:))} when @var{X} is a | |
941 matrix. This is true for all cases EXCEPT empty matrices: | |
942 | |
943 @example | |
944 @group | |
945 if ([0, 1]) == if (all ([0, 1])) ==> i.e., condition is false. | |
946 if ([1, 1]) == if (all ([1, 1])) ==> i.e., condition is true. | |
947 @end group | |
948 @end example | |
949 | |
950 However, | |
951 | |
952 @example | |
953 if ([]) != if (all ([])) | |
954 @end example | |
955 | |
6900 | 956 because @code{samp ([]) == 1} (because, despite the name, it is really |
6612 | 957 returning true if none of the elements of the matrix are zero, and since |
958 there are no elements, well, none of them are zero). But, somewhere | |
959 along the line, someone decided that if @code{([])} should be false. | |
960 Mathworks probably thought it just looks wrong to have @code{[]} be true | |
961 in this context even if you can use logical gymnastics to convince | |
962 yourself that "all" the elements of a matrix that doesn't actually have | |
963 any elements are nonzero. Octave however duplicates this behavior for if | |
964 statements containing empty matrices. | |
965 | |
966 @item Octave extensions | |
967 The extensions in Octave over @sc{Matlab} syntax are | |
968 very useful, but might cause issues when sharing with @sc{Matlab} users. | |
969 A list of the major extensions that should be avoided to be compatible | |
970 with @sc{Matlab} are | |
971 | |
972 @itemize @bullet | |
973 @item | |
6900 | 974 Comments in octave can be marked with @samp{#}. This allows POSIX |
975 systems to have the first line as @samp{#! octave -q} and mark the script | |
6653 | 976 itself executable. @sc{Matlab} doesn't have this feature due to the |
6900 | 977 absence of comments starting with @samp{#}". |
2866 | 978 |
6612 | 979 @item |
980 Code blocks like if, for, while, etc can be terminated with block | |
981 specific terminations like "endif". @sc{Matlab} doesn't have this and | |
982 all blocks must be terminated with "end" | |
983 | |
984 @item | |
985 Octave has a lisp like unwind_protect block that allows blocks of | |
986 code that terminate in an error to ensure that the variables that | |
987 are touched are restored. You can do something similar with | |
6900 | 988 @code{try}/@code{catch} combined with @samp{rethrow (lasterror ())} in |
989 @sc{Matlab}, however rethrow and lasterror are only available in Octave 2.9.10 and later. | |
6612 | 990 |
6900 | 991 Note that using @code{try}/@code{catch} combined with @samp{rethrow |
992 (lasterror ())} can not guarentee that global variables will be | |
993 correctly reset, as it won't catch user interrupts with Ctrl-C. For | |
994 example | |
6612 | 995 |
996 @example | |
997 @group | |
998 global a | |
999 a = 1; | |
1000 try | |
1001 _a = a; | |
1002 a = 2 | |
1003 while true | |
1004 end | |
1005 catch | |
1006 fprintf ('caught interrupt\n'); | |
1007 a = _a; | |
1008 rethrow (lasterror()); | |
1009 end | |
1010 @end group | |
1011 @end example | |
1012 | |
1013 @noindent | |
1014 compared to | |
1015 | |
1016 @example | |
1017 @group | |
1018 global a | |
1019 a = 1; | |
1020 unwind_protect | |
1021 _a = a; | |
1022 a = 2 | |
1023 while true | |
1024 end | |
1025 unwind_protect_cleanup | |
1026 fprintf ('caught interrupt\n'); | |
1027 a = _a; | |
1028 end | |
1029 @end group | |
1030 @end example | |
1031 | |
1032 Typing Ctrl-C in the first case returns the user directly to the | |
6879 | 1033 prompt, and the variable "a" is not reset to the saved value. In the |
6900 | 1034 second case the variable "a" is reset correctly. Therefore @sc{Matlab} |
6612 | 1035 gives no save way of temporarily changing global variables. |
1036 | |
1037 @item | |
1038 Indexing can be applied to all objects in Octave and not just | |
1039 variable. Therefore @code{sin(x)(1:10);} for example is perfectly valid | |
1040 in Octave but not @sc{Matlab}. To do the same in @sc{Matlab} you must do | |
1041 @code{y = sin(x); y = y([1:10]);} | |
1042 | |
1043 @item | |
6900 | 1044 Octave has the operators "++", "--", "-=", "+=", "*=", etc. As |
6612 | 1045 @sc{Matlab} doesn't, if you are sharing code these should be avoided. |
1046 | |
1047 @item | |
6900 | 1048 Character strings in Octave can be denoted with double or single |
1049 quotes. There is a subtle difference between the two in that escaped | |
1050 characters like @code{\n} (newline), @code{\t} (tab), etc are | |
1051 interpreted in double quoted strings but not single quoted strings. This | |
1052 difference is important on Windows platforms where the "\" character is | |
1053 used in path names, and so single quoted strings should be used in | |
1054 paths. @sc{Matlab} doesn't have double quoted strings and so they should | |
1055 be avoided if the code will be transfered to a @sc{Matlab} user. | |
6612 | 1056 @end itemize |
1057 | |
1058 @end itemize | |
2866 | 1059 |
4830 | 1060 @node Index |
2866 | 1061 @appendix Concept Index |
1062 | |
1063 @printindex cp | |
1064 | |
1065 @page | |
1066 @contents | |
1067 @bye |