2339
|
1 <!doctype html public "-//IETF//DTD HTML Strict//EN"> |
|
2 <html> |
|
3 <head> |
|
4 <title> Octave -- a high-level language for numerical computations </title> |
|
5 </head> |
|
6 |
2591
|
7 <h1>A Brief Introduction to Octave</h1> |
2339
|
8 |
2591
|
9 <ul> |
|
10 <li><a href="readme.html#Overview">Overview</a></li> |
|
11 <li><a href="readme.html#Language Features">Language Features</a></li> |
|
12 <li><a href="readme.html#Distribution Terms">Distribution Terms</a></li> |
|
13 <li><a href="readme.html#Availability">Availability</a></li> |
|
14 <li><a href="readme.html#Installation and Bugs">Installation and Bugs</a></li> |
|
15 <li><a href="readme.html#Documentation">Documentation</a></li> |
2595
|
16 <li><a href="readme.html#Implementation">Implementation</a></li> |
2591
|
17 </ul> |
|
18 <hr> |
|
19 |
|
20 <h2><a name="Overview">Overview</a></h2> |
2339
|
21 <p> |
|
22 Octave is a high-level language, primarily intended for numerical |
|
23 computations. It provides a convenient command line interface for |
2591
|
24 solving linear and nonlinear problems numerically, and for performing |
|
25 other numerical experiments. It may also be used as a batch-oriented |
|
26 language. |
2339
|
27 </p> |
|
28 |
2591
|
29 <h2><a name="Language Features">Language Features</a></h2> |
2594
|
30 <p> |
|
31 The best way to introduce Octave's language is probably to show a few |
|
32 simple examples. |
|
33 </p> |
|
34 |
|
35 <p> |
|
36 If you are new to Octave, I recommend that you try these examples to |
|
37 begin learning Octave by using it. Lines marked with |
|
38 <tt>octave:13></tt> are lines you type, ending each with a carriage |
|
39 return. Octave will respond with an answer, or by displaying a graph. |
|
40 </p> |
|
41 |
|
42 <h3>Creating a Matrix</h3> |
|
43 |
|
44 <p> |
|
45 To create a new matrix and store it in a variable so that it you can |
|
46 refer to it later, type the command |
|
47 |
|
48 <pre> |
|
49 octave:1> a = [ 1, 1, 2; 3, 5, 8; 13, 21, 34 ] |
|
50 </pre> |
|
51 |
|
52 Octave will respond by printing the matrix in neatly aligned columns. |
|
53 Ending a command with a semicolon tells Octave to not print the result |
|
54 of a command. For example |
|
55 |
|
56 <pre> |
|
57 octave:2> b = rand (3, 2); |
|
58 </pre> |
|
59 |
|
60 will create a 3 row, 2 column matrix with each element set to a random |
|
61 value between zero and one. |
|
62 </p> |
|
63 |
|
64 <p> |
|
65 To display the value of any variable, simply type the name of the |
|
66 variable. For example, to display the value stored in the matrix |
|
67 <tt>b</tt>, type the command |
|
68 |
|
69 <pre> |
|
70 octave:3> b |
|
71 </pre> |
|
72 |
|
73 <h3>Matrix Arithmetic</h3> |
|
74 |
|
75 <p> |
|
76 Octave has a convenient operator notation for performing matrix |
|
77 arithmetic. For example, to multiply the matrix <tt>a</tt> by a |
|
78 scalar value, type the command |
|
79 |
|
80 <pre> |
|
81 octave:4> 2 * a |
|
82 </pre> |
|
83 |
|
84 <p> |
|
85 To multiply the two matrices <tt>a</tt> and <tt>b</tt>, type the |
|
86 command |
|
87 |
|
88 <pre> |
|
89 octave:5> a * b |
|
90 </pre> |
|
91 |
|
92 <p> |
|
93 To form the matrix product <tt>transpose (a) * a</tt>, type the command |
|
94 |
|
95 <pre> |
|
96 octave:6> a' * a |
|
97 </pre> |
|
98 </p> |
|
99 |
|
100 <h3>Solving Linear Equations</h3> |
|
101 |
|
102 <p> |
|
103 To solve the set of linear equations <tt>Ax = b</tt> use the left |
|
104 division operator, <tt>\</tt>: |
|
105 |
|
106 <pre> |
|
107 octave:7> a \ b |
|
108 </pre> |
|
109 |
|
110 This is conceptually equivalent to <tt>inv (A) * b</tt>, but avoids |
|
111 computing the inverse of a matrix directly. |
|
112 </p> |
|
113 |
|
114 <p> |
|
115 If the coefficient matrix is singular, Octave will print a warning |
|
116 message and compute a minimum norm solution. |
|
117 </p> |
|
118 |
|
119 <h3>Integrating Differential Equations</h3> |
|
120 |
|
121 <p> |
|
122 Octave has built-in functions for solving nonlinear differential |
|
123 equations of the form |
|
124 |
|
125 <pre> |
|
126 dx |
|
127 -- = f (x, t) |
|
128 dt |
|
129 </pre> |
|
130 |
|
131 with the initial condition |
|
132 |
|
133 <pre> |
|
134 x(t = t0) = x0 |
|
135 </pre> |
|
136 </p> |
|
137 |
|
138 <p> |
|
139 For Octave to integrate equations of this form, you must first provide a |
|
140 definition of the function <tt> f (x, t)</tt>. This is |
|
141 straightforward, and may be accomplished by entering the function body |
|
142 directly on the command line. For example, the following commands |
|
143 define the right hand side function for an interesting pair of |
|
144 nonlinear differential equations. Note that while you are entering a |
|
145 function, Octave responds with a different prompt, to indicate that it |
|
146 is waiting for you to complete your input. |
|
147 |
|
148 <pre> |
|
149 octave:8> function xdot = f (x, t) |
|
150 > |
|
151 > r = 0.25; |
|
152 > k = 1.4; |
|
153 > a = 1.5; |
|
154 > b = 0.16; |
|
155 > c = 0.9; |
|
156 > d = 0.8; |
|
157 > |
|
158 > xdot(1) = r*x(1)*(1 - x(1)/k) - a*x(1)*x(2)/(1 + b*x(1)); |
|
159 > xdot(2) = c*a*x(1)*x(2)/(1 + b*x(1)) - d*x(2); |
|
160 > |
|
161 > endfunction |
|
162 </pre> |
|
163 </p> |
|
164 |
|
165 <p> |
|
166 Given the initial condition |
|
167 |
|
168 <pre> |
|
169 x0 = [1; 2]; |
|
170 </pre> |
|
171 |
|
172 and the set of output times as a column vector (note that the first |
|
173 output time corresponds to the initial condition given above) |
|
174 |
|
175 <pre> |
|
176 t = linspace (0, 50, 200)'; |
|
177 </pre> |
|
178 |
|
179 it is easy to integrate the set of differential equations: |
|
180 |
|
181 <pre> |
|
182 x = lsode ("f", x0, t); |
|
183 </pre> |
|
184 |
|
185 <p> |
|
186 The function <tt>lsode</tt> uses the Livermore Solver for Ordinary |
|
187 Differential Equations, described in A. C. Hindmarsh, <em>ODEPACK, a |
|
188 Systematized Collection of ODE Solvers</em>, in: Scientific Computing, |
|
189 R. S. Stepleman et al. (Eds.), North-Holland, Amsterdam, 1983, pages |
|
190 55-64. |
|
191 </p> |
|
192 |
|
193 <h3>Producing Graphical Output</h3> |
|
194 |
|
195 <p> |
|
196 To display the solution of the previous example graphically, use the |
|
197 command |
|
198 |
|
199 <pre> |
|
200 plot (t, x) |
|
201 </pre> |
|
202 </p> |
|
203 |
|
204 <p> |
|
205 If you are using the X Window System, Octave will automatically create |
|
206 a separate window to display the plot. If you are using a terminal that |
|
207 supports some other graphics commands, you will need to tell Octave what |
|
208 kind of terminal you have. Type the command |
|
209 </p> |
|
210 |
|
211 <pre> |
|
212 gset term |
|
213 </pre> |
|
214 |
|
215 to see a list of the supported terminal types. Octave uses |
|
216 <tt>gnuplot</tt> to display graphics, and can display graphics on any |
|
217 terminal that is supported by <tt>gnuplot</tt>. |
|
218 |
|
219 <p> |
|
220 To capture the output of the plot command in a file rather than sending |
|
221 the output directly to your terminal, you can use a set of commands like |
|
222 this |
|
223 |
|
224 <pre> |
|
225 gset term postscript |
|
226 gset output "foo.ps" |
|
227 replot |
|
228 </pre> |
|
229 |
|
230 This will work for other types of output devices as well. Octave's |
|
231 <tt>gset</tt> command is really just piped to the <tt>gnuplot</tt> |
|
232 subprocess, so that once you have a plot on the screen that you like, |
|
233 you should be able to do something like this to create an output file |
|
234 suitable for your graphics printer. |
|
235 </p> |
|
236 |
|
237 <p> |
|
238 Or, you can eliminate the intermediate file by using commands like this |
|
239 |
|
240 <pre> |
|
241 gset term postscript |
|
242 gset output "|lpr -Pname_of_your_graphics_printer" |
|
243 replot |
|
244 </pre> |
|
245 |
|
246 <h3>Editing What You Have Typed</h3> |
|
247 |
|
248 <p> |
|
249 At the Octave prompt, you can recall, edit, and reissue previous |
|
250 commands using Emacs- or vi-style editing commands. The default |
|
251 keybindings use Emacs-style commands. |
|
252 </p> |
|
253 |
|
254 <h3>Getting Help</h3> |
|
255 |
|
256 <p> |
|
257 Octave has an extensive help facility. The same documentation that is |
|
258 available in printed form is also available from the Octave prompt, |
|
259 because both forms of the documentation are created from the same input |
|
260 file. |
|
261 </p> |
|
262 |
|
263 <p> |
|
264 In order to get good help you first need to know the name of the command |
|
265 that you want to use. This name of the function may not always be |
|
266 obvious, but a good place to start is to just type <tt>help</tt>. |
|
267 This will show you all the operators, reserved words, functions, |
|
268 built-in variables, and function files. You can then get more |
|
269 help on anything that is listed by simply including the name as an |
|
270 argument to help. For example, |
|
271 |
|
272 <pre> |
|
273 help plot |
|
274 </pre> |
|
275 |
|
276 will display the help text for the <tt>plot</tt> function. |
|
277 </p> |
|
278 |
|
279 <p> |
|
280 The complete text of the manual is availabe from Octave's command line |
|
281 using the command <tt>help -i</tt>. Because it is written in Texinfo, |
|
282 it is also possible to put |
|
283 <a href="http://www.che.wisc.edu/cgi-bin/info2www?(octave)">the manual |
|
284 on the WWW</a>. |
|
285 </p> |
2591
|
286 |
|
287 <h2><a name="Distribution Terms">Distribution Terms</a></h2> |
2339
|
288 <p> |
|
289 Octave is free software; you can redistribute it and/or modify it |
2591
|
290 under the terms of the |
|
291 <a href="http://www.che.wisc.edu/cgi-bin/info2www?(octave)Copying">GNU |
|
292 General Public License</a> as published by the Free Software |
|
293 Foundation; either version 2, or (at your option) any later version. |
2339
|
294 </p> |
|
295 |
|
296 <p> |
|
297 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
298 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
299 FITNESS FOR A PARTICULAR PURPOSE. See the file COPYING for more |
|
300 details. |
|
301 </p> |
|
302 |
2591
|
303 <h2><a name="Availability">Availability</a></h2> |
2339
|
304 <p> |
|
305 The latest released version of Octave is always available via |
2591
|
306 anonymous ftp from |
|
307 <a href="ftp://ftp.che.wisc.edu/pub/octave">ftp://ftp.che.wisc.edu/pub/octave</a>. |
|
308 Complete source and binaries for several popular systems are available. |
2339
|
309 </p> |
|
310 |
2591
|
311 <h2><a name="Installation and Bugs">Installation and Bugs</a></h2> |
2339
|
312 <p> |
2591
|
313 Octave requires approximately 125MB of disk storage to unpack and |
|
314 compile from source (significantly less if you don't compile with |
|
315 debugging symbols or create shared libraries). Once installed, Octave |
|
316 requires approximately 65MB of disk space (again, considerably less if |
|
317 you don't build shared libraries or the binaries and libraries do not |
|
318 include debugging symbols). |
2339
|
319 </p> |
|
320 |
2591
|
321 <p> |
|
322 In order to build Octave, you will need a current version of g++, |
|
323 libg++, and GNU make. Recommended versions are g++ 2.7.2 or 2.7.2.1, |
|
324 libg++ 2.7.1 or 2.7.2, and make 3.75. |
|
325 </p> |
|
326 |
|
327 <p> |
|
328 <b>You must have GNU Make to compile Octave</b>. Octave's Makefiles |
|
329 use features of GNU Make that are not present in other versions of |
|
330 make. GNU Make is very portable and easy to install. |
|
331 </p> |
2339
|
332 |
|
333 <p> |
|
334 See the notes in the files INSTALL and INSTALL.OCTAVE for more |
|
335 specific installation instructions, including directions for |
|
336 installing Octave from a binary distribution. |
|
337 </p> |
|
338 |
|
339 <p> |
|
340 The file BUGS contains a recommended procedure for reporting bugs, as |
2591
|
341 well as a list of known problems and possible fixes. |
2339
|
342 </p> |
|
343 |
2591
|
344 <h2><a name="Documentation">Documentation</a></h2> |
|
345 |
2339
|
346 <p> |
2591
|
347 Octave's manual has been revised for version 2.0, but it is lagging a |
|
348 bit behind the development of the software. In particular, there is |
|
349 currently no complete documentation of the C++ class libraries or the |
|
350 support for dynamic linking and user-defined data types. If you |
|
351 notice ommissions or inconsistencies, please report them as bugs to |
|
352 bug-octave@bevo.che.wisc.edu. Specific suggestions for ways to |
|
353 improve Octave and its documentation are always welcome. |
2339
|
354 </p> |
|
355 |
2885
|
356 <h2><a name="Implementation">Implementation</a></h2> |
2339
|
357 <p> |
|
358 Octave is being developed with the Free Software Foundation's make, |
|
359 bison (a replacement for YACC), flex (a replacement for lex), gcc/g++, |
|
360 and libg++ on a SPARCstation II and a DECstation 5000/240. It should |
|
361 be possible to install it on any machine that runs GCC/G++. It may |
|
362 also be possible to install it using other implementations of these |
|
363 tools, but it will most certainly require much more work. Do yourself |
|
364 a favor and get the GNU development tools, either via anonymous ftp |
|
365 from prep.ai.mit.edu or by writing the Free Software Foundation, 675 |
|
366 Mass Ave, Cambridge, MA 02139, USA. |
|
367 </p> |
|
368 |
|
369 <p> |
|
370 The underlying numerical solvers are currently standard Fortran ones |
|
371 like Lapack, Linpack, Odepack, the Blas, etc., packaged in a library |
|
372 of C++ classes (see the files in the libcruft and liboctave |
|
373 subdirectories). If possible, the Fortran subroutines are compiled |
|
374 with the system's Fortran compiler, and called directly from the C++ |
|
375 functions. If that's not possible, they are translated with f2c and |
|
376 compiled with a C compiler. Better performance is usually achieved if |
|
377 the intermediate translation to C is avoided. |
|
378 </p> |
|
379 |
|
380 <p> |
|
381 The library of C++ classes may also be useful by itself. |
|
382 </p> |
|
383 |
2591
|
384 <hr> |
|
385 <p> |
2607
|
386 Back to the <a href="http://www.che.wisc.edu/octave">Octave home page</a>. |
2591
|
387 </p> |
|
388 <hr> |
2339
|
389 <p> |
|
390 <a href="http://www.che.wisc.edu/~jwe">John W. Eaton</a><br> |
|
391 <a href="mailto:jwe@bevo.che.wisc.edu"><i>jwe@bevo.che.wisc.edu</i></a><br> |
|
392 University of Wisconsin<br> |
|
393 Department of Chemical Engineering<br> |
|
394 Madison WI 53719 |
2591
|
395 </p> |
2339
|
396 </body> |
|
397 </html> |