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