Mercurial > hg > octave-lyh
annotate doc/interpreter/intro.txi @ 11463:ae96756561d0
fixing bug #32074
author | Konstantinos Poulios <logari81@googlemail.com> |
---|---|
date | Sat, 08 Jan 2011 00:13:29 +0100 |
parents | 322f43e0e170 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
8920 | 1 @c Copyright (C) 1996, 1997, 2007, 2008, 2009 John W. Eaton |
7018 | 2 @c |
3 @c This file is part of Octave. | |
4 @c | |
5 @c Octave is free software; you can redistribute it and/or modify it | |
6 @c under the terms of the GNU General Public License as published by the | |
7 @c Free Software Foundation; either version 3 of the License, or (at | |
8 @c your option) any later version. | |
9 @c | |
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT | |
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 @c for more details. | |
14 @c | |
15 @c You should have received a copy of the GNU General Public License | |
16 @c along with Octave; see the file COPYING. If not, see | |
17 @c <http://www.gnu.org/licenses/>. | |
3294 | 18 |
4167 | 19 @node Introduction |
3294 | 20 @chapter A Brief Introduction to Octave |
21 @cindex introduction | |
22 | |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
23 GNU Octave is a high-level language, primarily intended for numerical |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
24 computations. It provides a convenient interactive command line |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
25 interface for solving linear and nonlinear problems numerically, and |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
26 for performing other numerical experiments. It may also be used as a |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
27 batch-oriented language for data processing. |
3294 | 28 |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
29 GNU Octave is freely redistributable software. You may redistribute |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
30 it and/or modify it under the terms of the GNU General Public License |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
31 as published by the Free Software Foundation. The GPL is included in |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
32 this manual in @ref{Copying}. |
3294 | 33 |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
34 This manual provides comprehensive documentation on how to install, |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
35 run, use, and extend GNU Octave. Additional chapters describe how |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
36 to report bugs and help contribute code. |
3294 | 37 |
38 This document corresponds to Octave version @value{VERSION}. | |
39 | |
40 @menu | |
41 * Running Octave:: | |
42 * Simple Examples:: | |
43 * Conventions:: | |
44 @end menu | |
45 | |
4167 | 46 @node Running Octave |
3294 | 47 @section Running Octave |
48 | |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
49 On most systems, Octave is started with the shell command |
3294 | 50 @samp{octave}. Octave displays an initial message and then a prompt |
51 indicating it is ready to accept input. You can begin typing Octave | |
52 commands immediately afterward. | |
53 | |
54 If you get into trouble, you can usually interrupt Octave by typing | |
9033
c7d60ac7a3e6
Documentation cleanup of preface and intro
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
55 @kbd{Control-C} (written @kbd{C-c} for short). @kbd{C-c} gets |
3294 | 56 its name from the fact that you type it by holding down @key{CTRL} and |
57 then pressing @key{c}. Doing this will normally return you to Octave's | |
58 prompt. | |
59 | |
60 @cindex exiting octave | |
61 @cindex quitting octave | |
62 To exit Octave, type @kbd{quit}, or @kbd{exit} at the Octave prompt. | |
63 | |
64 On systems that support job control, you can suspend Octave by sending | |
65 it a @code{SIGTSTP} signal, usually by typing @kbd{C-z}. | |
66 | |
4167 | 67 @node Simple Examples |
3294 | 68 @section Simple Examples |
69 | |
70 The following chapters describe all of Octave's features in detail, but | |
71 before doing that, it might be helpful to give a sampling of some of its | |
72 capabilities. | |
73 | |
74 If you are new to Octave, I recommend that you try these examples to | |
10719
e54152088b0a
Clarify documentation wording. Bug #30165.
Rik <octave@nomad.inbox5.com>
parents:
10668
diff
changeset
|
75 begin learning Octave by using it. Lines marked like so, @samp{octave:13>}, |
3294 | 76 are lines you type, ending each with a carriage return. Octave will |
77 respond with an answer, or by displaying a graph. | |
78 | |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
79 @subsection Elementary Calculations |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
80 |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
81 Octave can easily be used for basic numerical calculations. Octave |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
82 knows about arithmetic operations (+,-,*,/), exponentiation (^), |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
83 natural logarithms/exponents (log, exp), and the trigonometric |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
84 functions (sin, cos, @dots{}). Moreover, Octave calculations work |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
85 on real or imaginary numbers (i,j). In addition, some mathematical |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
86 constants such as the base of the natural logarithm (e) and the ratio |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
87 of a circle's circumference to its diameter (pi) are pre-defined. |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
88 |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
89 @noindent |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
90 For example, to verify Euler's Identity, |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
91 @tex |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
92 $$e^{\imath\pi} = -1$$ |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
93 @end tex |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
94 @ifnottex |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
95 @display |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
96 |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
97 i*pi |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
98 e = -1 |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
99 @end display |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
100 @end ifnottex |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
101 |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
102 @noindent |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
103 type the following which will evaluate to @code{-1} within the |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
104 tolerance of the calculation. |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
105 |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
106 @example |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
107 octave:1> exp(i*pi) |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
108 @end example |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
109 |
6623 | 110 @subsection Creating a Matrix |
3294 | 111 |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
112 Vectors and matrices are the basic building blocks for numerical analysis. |
9033
c7d60ac7a3e6
Documentation cleanup of preface and intro
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
113 To create a new matrix and store it in a variable so that you can |
3294 | 114 refer to it later, type the command |
115 | |
116 @example | |
6620 | 117 octave:1> A = [ 1, 1, 2; 3, 5, 8; 13, 21, 34 ] |
3294 | 118 @end example |
119 | |
120 @noindent | |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
121 Octave will respond by printing the matrix in neatly aligned columns. |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
122 Octave uses a comma or space to separate entries in a row, and a |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
123 semicolon or carriage return to separate one row from the next. |
9033
c7d60ac7a3e6
Documentation cleanup of preface and intro
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
124 Ending a command with a semicolon tells Octave not to print the result |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
125 of the command. For example, |
3294 | 126 |
127 @example | |
6620 | 128 octave:2> B = rand (3, 2); |
3294 | 129 @end example |
130 | |
131 @noindent | |
132 will create a 3 row, 2 column matrix with each element set to a random | |
133 value between zero and one. | |
134 | |
9033
c7d60ac7a3e6
Documentation cleanup of preface and intro
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
135 To display the value of a variable, simply type the name of the |
c7d60ac7a3e6
Documentation cleanup of preface and intro
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
136 variable at the prompt. For example, to display the value stored in the |
c7d60ac7a3e6
Documentation cleanup of preface and intro
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
137 matrix @code{B}, type the command |
3294 | 138 |
139 @example | |
6620 | 140 octave:3> B |
3294 | 141 @end example |
142 | |
6623 | 143 @subsection Matrix Arithmetic |
3294 | 144 |
145 Octave has a convenient operator notation for performing matrix | |
8476
4998c6c78632
[docs] fix case to match example
Brian Gough <bjg@gnu.org>
parents:
7490
diff
changeset
|
146 arithmetic. For example, to multiply the matrix @code{A} by a scalar |
3294 | 147 value, type the command |
148 | |
149 @example | |
6620 | 150 octave:4> 2 * A |
3294 | 151 @end example |
152 | |
6620 | 153 @noindent |
8476
4998c6c78632
[docs] fix case to match example
Brian Gough <bjg@gnu.org>
parents:
7490
diff
changeset
|
154 To multiply the two matrices @code{A} and @code{B}, type the command |
3294 | 155 |
156 @example | |
6620 | 157 octave:5> A * B |
3294 | 158 @end example |
159 | |
6620 | 160 @noindent |
161 and to form the matrix product | |
3294 | 162 @tex |
6620 | 163 $@code{A}^T@code{A}$, |
3294 | 164 @end tex |
6620 | 165 @ifnottex |
166 @code{transpose (A) * A}, | |
167 @end ifnottex | |
3294 | 168 type the command |
169 | |
170 @example | |
6620 | 171 octave:6> A' * A |
3294 | 172 @end example |
173 | |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
174 @subsection Solving Systems of Linear Equations |
3294 | 175 |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
176 Systems of linear equations are ubiquitous in numerical analysis. |
6620 | 177 To solve the set of linear equations @code{A@var{x} = b}, |
3294 | 178 use the left division operator, @samp{\}: |
179 | |
180 @example | |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
181 @var{x} = A \ b |
3294 | 182 @end example |
183 | |
184 @noindent | |
185 This is conceptually equivalent to | |
186 @tex | |
6620 | 187 $@code{A}^{-1}@code{b}$, |
3294 | 188 @end tex |
6620 | 189 @ifnottex |
3294 | 190 @code{inv (a) * b}, |
6620 | 191 @end ifnottex |
3294 | 192 but avoids computing the inverse of a matrix directly. |
193 | |
194 If the coefficient matrix is singular, Octave will print a warning | |
195 message and compute a minimum norm solution. | |
196 | |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
197 A simple example comes from chemistry and the need to obtain balanced |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
198 chemical equations. Consider the burning of hydrogen and oxygen to |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
199 produce water. |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
200 @tex |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
201 $$ {\rm H_{2}} + {\rm O_{2}} \rightarrow {\rm H_{2}O} $$ |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
202 @end tex |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
203 @ifnottex |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10719
diff
changeset
|
204 |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
205 @example |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
206 H2 + O2 --> H2O |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
207 @end example |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10719
diff
changeset
|
208 |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
209 @end ifnottex |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
210 @noindent |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
211 The equation above is not accurate. The Law of Conservation of Mass requires |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
212 that the number of molecules of each type balance on the left- and right-hand |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
213 sides of the equation. Writing the variable overall reaction with |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
214 individual equations for hydrogen and oxygen one finds: |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
215 @tex |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
216 \vbox{ |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
217 $$ x_{1}{\rm H_{2}} + x_{2}{\rm O_{2}} \rightarrow {\rm H_{2}O} $$ |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
218 $$ {\rm H:}\quad 2x_{1} + 0x_{2} \rightarrow 2 $$ |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
219 $$ {\rm O:}\quad 0x_{1} + 2x_{2} \rightarrow 1 $$ |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
220 } |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
221 @end tex |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
222 @ifnottex |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10719
diff
changeset
|
223 |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
224 @example |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
225 @group |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
226 x1*H2 + x2*O2 --> H2O |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
227 H: 2*x1 + 0*x2 --> 2 |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
228 O: 0*x1 + 2*x2 --> 1 |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
229 @end group |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
230 @end example |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10719
diff
changeset
|
231 |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
232 @end ifnottex |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
233 @noindent |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
234 The solution in Octave is found in just three steps. |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
235 |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
236 @example |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
237 @group |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
238 octave:1> A = [ 2, 0; 0, 2 ]; |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
239 octave:2> b = [ 2; 1 ]; |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
240 octave:3> x = A \ b |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
241 @end group |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
242 @end example |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
243 |
6623 | 244 @subsection Integrating Differential Equations |
3294 | 245 |
246 Octave has built-in functions for solving nonlinear differential | |
247 equations of the form | |
248 @tex | |
249 $$ | |
250 {dx \over dt} = f(x,t), \qquad x(t=t_0) = x_0 | |
251 $$ | |
252 @end tex | |
6620 | 253 @ifnottex |
3294 | 254 |
255 @example | |
256 @group | |
257 dx | |
258 -- = f (x, t) | |
259 dt | |
260 @end group | |
261 @end example | |
262 | |
263 @noindent | |
264 with the initial condition | |
265 | |
266 @example | |
267 x(t = t0) = x0 | |
268 @end example | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10719
diff
changeset
|
269 |
6620 | 270 @end ifnottex |
3294 | 271 @noindent |
272 For Octave to integrate equations of this form, you must first provide a | |
273 definition of the function | |
274 @tex | |
275 $f (x, t)$. | |
276 @end tex | |
6620 | 277 @ifnottex |
3294 | 278 @code{f(x,t)}. |
6620 | 279 @end ifnottex |
3294 | 280 This is straightforward, and may be accomplished by entering the |
281 function body directly on the command line. For example, the following | |
9033
c7d60ac7a3e6
Documentation cleanup of preface and intro
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
282 commands define the right-hand side function for an interesting pair of |
3294 | 283 nonlinear differential equations. Note that while you are entering a |
284 function, Octave responds with a different prompt, to indicate that it | |
285 is waiting for you to complete your input. | |
286 | |
287 @example | |
288 @group | |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
289 octave:1> function xdot = f (x, t) |
3294 | 290 > |
291 > r = 0.25; | |
292 > k = 1.4; | |
293 > a = 1.5; | |
294 > b = 0.16; | |
295 > c = 0.9; | |
296 > d = 0.8; | |
297 > | |
298 > xdot(1) = r*x(1)*(1 - x(1)/k) - a*x(1)*x(2)/(1 + b*x(1)); | |
299 > xdot(2) = c*a*x(1)*x(2)/(1 + b*x(1)) - d*x(2); | |
300 > | |
301 > endfunction | |
302 @end group | |
303 @end example | |
304 | |
305 @noindent | |
306 Given the initial condition | |
307 | |
308 @example | |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
309 octave:2> x0 = [1; 2]; |
3294 | 310 @end example |
311 | |
312 @noindent | |
313 and the set of output times as a column vector (note that the first | |
314 output time corresponds to the initial condition given above) | |
315 | |
316 @example | |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
317 octave:3> t = linspace (0, 50, 200)'; |
3294 | 318 @end example |
319 | |
320 @noindent | |
321 it is easy to integrate the set of differential equations: | |
322 | |
323 @example | |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
324 octave:4> x = lsode ("f", x0, t); |
3294 | 325 @end example |
326 | |
327 @noindent | |
328 The function @code{lsode} uses the Livermore Solver for Ordinary | |
329 Differential Equations, described in A. C. Hindmarsh, @cite{ODEPACK, a | |
330 Systematized Collection of ODE Solvers}, in: Scientific Computing, R. S. | |
331 Stepleman et al. (Eds.), North-Holland, Amsterdam, 1983, pages 55--64. | |
332 | |
6623 | 333 @subsection Producing Graphical Output |
3294 | 334 |
335 To display the solution of the previous example graphically, use the | |
336 command | |
337 | |
338 @example | |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
339 octave:1> plot (t, x) |
3294 | 340 @end example |
341 | |
6620 | 342 @noindent |
343 If you are using a graphical user interface, Octave will automatically create | |
6331 | 344 a separate window to display the plot. |
345 | |
6620 | 346 To save a plot once it has been displayed on the screen, use the print |
6331 | 347 command. For example, |
3294 | 348 |
349 @example | |
6331 | 350 print -deps foo.eps |
3294 | 351 @end example |
352 | |
353 @noindent | |
7001 | 354 will create a file called @file{foo.eps} that contains a rendering of |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
355 the current plot in Encapsulated PostScript format. The command |
3294 | 356 |
357 @example | |
6331 | 358 help print |
3294 | 359 @end example |
360 | |
361 @noindent | |
6331 | 362 explains more options for the @code{print} command and provides a list |
6620 | 363 of additional output file formats. |
3294 | 364 |
6623 | 365 @subsection Editing What You Have Typed |
3294 | 366 |
367 At the Octave prompt, you can recall, edit, and reissue previous | |
368 commands using Emacs- or vi-style editing commands. The default | |
369 keybindings use Emacs-style commands. For example, to recall the | |
9033
c7d60ac7a3e6
Documentation cleanup of preface and intro
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
370 previous command, press @kbd{Control-p} (written @kbd{C-p} for |
c7d60ac7a3e6
Documentation cleanup of preface and intro
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
371 short). Doing this will normally bring back the previous line of input. |
6620 | 372 @kbd{C-n} will bring up the next line of input, @kbd{C-b} will move |
373 the cursor backward on the line, @kbd{C-f} will move the cursor forward | |
374 on the line, etc. | |
3294 | 375 |
376 A complete description of the command line editing capability is given | |
377 in this manual in @ref{Command Line Editing}. | |
378 | |
6623 | 379 @subsection Help and Documentation |
3294 | 380 |
381 Octave has an extensive help facility. The same documentation that is | |
382 available in printed form is also available from the Octave prompt, | |
383 because both forms of the documentation are created from the same input | |
384 file. | |
385 | |
386 In order to get good help you first need to know the name of the command | |
387 that you want to use. This name of the function may not always be | |
388 obvious, but a good place to start is to just type @code{help}. | |
389 This will show you all the operators, reserved words, functions, | |
9033
c7d60ac7a3e6
Documentation cleanup of preface and intro
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
390 built-in variables, and function files. An alternative is to search the |
c7d60ac7a3e6
Documentation cleanup of preface and intro
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
391 documentation using the @code{lookfor} function. This function is |
6620 | 392 described in @ref{Getting Help}. |
393 | |
394 Once you know the name of the function you wish to use, you can get more | |
395 help on the function by simply including the name as an argument to help. | |
396 For example, | |
3294 | 397 |
398 @example | |
399 help plot | |
400 @end example | |
401 | |
402 @noindent | |
403 will display the help text for the @code{plot} function. | |
404 | |
405 Octave sends output that is too long to fit on one screen through a | |
406 pager like @code{less} or @code{more}. Type a @key{RET} to advance one | |
407 line, a @key{SPC} to advance one page, and @key{q} to exit the pager. | |
408 | |
409 The part of Octave's help facility that allows you to read the complete | |
410 text of the printed manual from within Octave normally uses a separate | |
411 program called Info. When you invoke Info you will be put into a menu | |
412 driven program that contains the entire Octave manual. Help for using | |
413 Info is provided in this manual in @ref{Getting Help}. | |
414 | |
4167 | 415 @node Conventions |
3294 | 416 @section Conventions |
417 | |
418 This section explains the notational conventions that are used in this | |
419 manual. You may want to skip this section and refer back to it later. | |
420 | |
421 @menu | |
422 * Fonts:: | |
423 * Evaluation Notation:: | |
424 * Printing Notation:: | |
425 * Error Messages:: | |
426 * Format of Descriptions:: | |
427 @end menu | |
428 | |
4167 | 429 @node Fonts |
3294 | 430 @subsection Fonts |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
431 @cindex documentation fonts |
3294 | 432 |
433 Examples of Octave code appear in this font or form: @code{svd (a)}. | |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
434 Names that represent variables or function arguments appear |
3294 | 435 in this font or form: @var{first-number}. Commands that you type at the |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
436 shell prompt appear in this font or form: @samp{octave --no-init-file}. |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
437 Commands that you type at the Octave prompt sometimes appear in this font |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
438 or form: @kbd{foo --bar --baz}. Specific keys on your keyboard appear |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
439 in this font or form: @key{ANY}. |
3294 | 440 |
4167 | 441 @node Evaluation Notation |
3294 | 442 @subsection Evaluation Notation |
443 @cindex evaluation notation | |
444 @cindex documentation notation | |
445 | |
446 In the examples in this manual, results from expressions that you | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10719
diff
changeset
|
447 evaluate are indicated with @samp{@result{}}. For example: |
3294 | 448 |
449 @example | |
450 @group | |
451 sqrt (2) | |
452 @result{} 1.4142 | |
453 @end group | |
454 @end example | |
455 | |
456 @noindent | |
457 You can read this as ``@code{sqrt (2)} evaluates to 1.4142''. | |
458 | |
459 In some cases, matrix values that are returned by expressions are | |
460 displayed like this | |
461 | |
462 @example | |
463 @group | |
464 [1, 2; 3, 4] == [1, 3; 2, 4] | |
465 @result{} [ 1, 0; 0, 1 ] | |
466 @end group | |
467 @end example | |
468 | |
469 @noindent | |
470 and in other cases, they are displayed like this | |
471 | |
472 @example | |
473 @group | |
474 eye (3) | |
475 @result{} 1 0 0 | |
476 0 1 0 | |
477 0 0 1 | |
478 @end group | |
479 @end example | |
480 | |
481 @noindent | |
482 in order to clearly show the structure of the result. | |
483 | |
484 Sometimes to help describe one expression, another expression is | |
485 shown that produces identical results. The exact equivalence of | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10719
diff
changeset
|
486 expressions is indicated with @samp{@equiv{}}. For example: |
3294 | 487 |
488 @example | |
489 @group | |
490 rot90 ([1, 2; 3, 4], -1) | |
491 @equiv{} | |
492 rot90 ([1, 2; 3, 4], 3) | |
493 @equiv{} | |
494 rot90 ([1, 2; 3, 4], 7) | |
495 @end group | |
496 @end example | |
497 | |
4167 | 498 @node Printing Notation |
3294 | 499 @subsection Printing Notation |
500 @cindex printing notation | |
501 | |
502 Many of the examples in this manual print text when they are | |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
503 evaluated. In this manual the printed text resulting from an example |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
504 is indicated by @samp{@print{}}. The value that is returned by |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
505 evaluating the expression is displayed with @samp{@result{}} |
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
506 (@code{1} in the next example) and follows on a separate line. |
3294 | 507 |
508 @example | |
509 @group | |
510 printf ("foo %s\n", "bar") | |
511 @print{} foo bar | |
512 @result{} 1 | |
513 @end group | |
514 @end example | |
515 | |
4167 | 516 @node Error Messages |
3294 | 517 @subsection Error Messages |
518 @cindex error message notation | |
519 | |
520 Some examples signal errors. This normally displays an error message | |
9089
0b08eaf77dd6
Detailed review of intro.texi
Rik <rdrider0-list@yahoo.com>
parents:
9033
diff
changeset
|
521 on your terminal. Error messages are shown on a line beginning with |
3294 | 522 @code{error:}. |
523 | |
524 @example | |
525 @group | |
7490 | 526 fieldnames ([1, 2; 3, 4]) |
527 error: fieldnames: wrong type argument `matrix' | |
3294 | 528 @end group |
529 @end example | |
530 | |
4167 | 531 @node Format of Descriptions |
3294 | 532 @subsection Format of Descriptions |
533 @cindex description format | |
534 | |
535 Functions, commands, and variables are described in this manual in a | |
536 uniform format. The first line of a description contains the name of | |
537 the item followed by its arguments, if any. | |
10668
72585f1ca7a2
Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents:
9209
diff
changeset
|
538 @ifnottex |
3294 | 539 The category---function, variable, or whatever---appears at the |
540 beginning of the line. | |
10668
72585f1ca7a2
Replace @ifinfo with @ifnottex.
Rik <octave@nomad.inbox5.com>
parents:
9209
diff
changeset
|
541 @end ifnottex |
3294 | 542 @iftex |
543 The category---function, variable, or whatever---is printed next to the | |
544 right margin. | |
545 @end iftex | |
546 The description follows on succeeding lines, sometimes with examples. | |
547 | |
548 @menu | |
549 * A Sample Function Description:: | |
550 * A Sample Command Description:: | |
551 * A Sample Variable Description:: | |
552 @end menu | |
553 | |
4167 | 554 @node A Sample Function Description |
3294 | 555 @subsubsection A Sample Function Description |
556 @cindex function descriptions | |
557 | |
558 In a function description, the name of the function being described | |
559 appears first. It is followed on the same line by a list of parameters. | |
560 The names used for the parameters are also used in the body of the | |
561 description. | |
562 | |
563 Here is a description of an imaginary function @code{foo}: | |
564 | |
565 @deftypefn {Function} {} foo (@var{x}, @var{y}, @dots{}) | |
566 The function @code{foo} subtracts @var{x} from @var{y}, then adds the | |
567 remaining arguments to the result. If @var{y} is not supplied, then the | |
568 number 19 is used by default. | |
569 | |
570 @example | |
571 @group | |
572 foo (1, [3, 5], 3, 9) | |
573 @result{} [ 14, 16 ] | |
574 foo (5) | |
575 @result{} 14 | |
576 @end group | |
577 @end example | |
578 | |
579 More generally, | |
580 | |
581 @example | |
582 @group | |
583 foo (@var{w}, @var{x}, @var{y}, @dots{}) | |
584 @equiv{} | |
585 @var{x} - @var{w} + @var{y} + @dots{} | |
586 @end group | |
587 @end example | |
588 @end deftypefn | |
589 | |
590 Any parameter whose name contains the name of a type (e.g., | |
9033
c7d60ac7a3e6
Documentation cleanup of preface and intro
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
591 @var{integer} or @var{matrix}) is expected to be of that |
3294 | 592 type. Parameters named @var{object} may be of any type. Parameters |
593 with other sorts of names (e.g., @var{new_file}) are discussed | |
594 specifically in the description of the function. In some sections, | |
595 features common to parameters of several functions are described at the | |
596 beginning. | |
597 | |
598 Functions in Octave may be defined in several different ways. The | |
7001 | 599 category name for functions may include another name that indicates the |
3294 | 600 way that the function is defined. These additional tags include |
601 | |
602 @table @asis | |
6620 | 603 @item Function File |
604 @cindex function file | |
605 The function described is defined using Octave commands stored in a text | |
606 file. @xref{Function Files}. | |
607 | |
3294 | 608 @item Built-in Function |
609 @cindex built-in function | |
610 The function described is written in a language like C++, C, or Fortran, | |
611 and is part of the compiled Octave binary. | |
612 | |
613 @item Loadable Function | |
614 @cindex loadable function | |
615 The function described is written in a language like C++, C, or Fortran. | |
616 On systems that support dynamic linking of user-supplied functions, it | |
617 may be automatically linked while Octave is running, but only if it is | |
618 needed. @xref{Dynamically Linked Functions}. | |
619 | |
620 @item Mapping Function | |
621 @cindex mapping function | |
622 The function described works element-by-element for matrix and vector | |
623 arguments. | |
624 @end table | |
625 | |
4167 | 626 @node A Sample Command Description |
3294 | 627 @subsubsection A Sample Command Description |
628 @cindex command descriptions | |
629 | |
630 Command descriptions have a format similar to function descriptions, | |
9033
c7d60ac7a3e6
Documentation cleanup of preface and intro
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
631 except that the word `Function' is replaced by `Command'. Commands are |
7001 | 632 functions that may be called without surrounding their arguments in |
3294 | 633 parentheses. For example, here is the description for Octave's |
634 @code{cd} command: | |
635 | |
636 @deffn {Command} cd dir | |
637 @deffnx {Command} chdir dir | |
638 Change the current working directory to @var{dir}. For example, | |
639 @kbd{cd ~/octave} changes the current working directory to | |
640 @file{~/octave}. If the directory does not exist, an error message is | |
641 printed and the working directory is not changed. | |
642 @end deffn | |
643 | |
4167 | 644 @node A Sample Variable Description |
3294 | 645 @subsubsection A Sample Variable Description |
646 @cindex variable descriptions | |
647 | |
648 A @dfn{variable} is a name that can hold a value. Although any variable | |
649 can be set by the user, @dfn{built-in variables} typically exist | |
650 specifically so that users can change them to alter the way Octave | |
651 behaves (built-in variables are also sometimes called @dfn{user | |
652 options}). Ordinary variables and built-in variables are described | |
653 using a format like that for functions except that there are no | |
654 arguments. | |
655 | |
656 Here is a description of the imaginary variable | |
657 @code{do_what_i_mean_not_what_i_say}. | |
658 | |
659 @defvr {Built-in Variable} do_what_i_mean_not_what_i_say | |
660 If the value of this variable is nonzero, Octave will do what you | |
661 actually wanted, even if you have typed a completely different and | |
662 meaningless list of commands. | |
663 @end defvr | |
664 | |
665 Other variable descriptions have the same format, but `Built-in | |
666 Variable' is replaced by `Variable', for ordinary variables, or | |
667 `Constant' for symbolic constants whose values cannot be changed. |