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