/usr/share/doc/octave/octave.html/Matrices.html is in octave-doc 4.2.2-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Matrices (GNU Octave)</title>
<meta name="description" content="Matrices (GNU Octave)">
<meta name="keywords" content="Matrices (GNU Octave)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Numeric-Data-Types.html#Numeric-Data-Types" rel="up" title="Numeric Data Types">
<link href="Empty-Matrices.html#Empty-Matrices" rel="next" title="Empty Matrices">
<link href="Numeric-Data-Types.html#Numeric-Data-Types" rel="prev" title="Numeric Data Types">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">
</head>
<body lang="en">
<a name="Matrices"></a>
<div class="header">
<p>
Next: <a href="Ranges.html#Ranges" accesskey="n" rel="next">Ranges</a>, Up: <a href="Numeric-Data-Types.html#Numeric-Data-Types" accesskey="u" rel="up">Numeric Data Types</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Matrices-1"></a>
<h3 class="section">4.1 Matrices</h3>
<a name="index-matrices"></a>
<a name="index-_005b"></a>
<a name="index-_005d"></a>
<a name="index-_003b"></a>
<a name="index-_002c"></a>
<p>It is easy to define a matrix of values in Octave. The size of the
matrix is determined automatically, so it is not necessary to explicitly
state the dimensions. The expression
</p>
<div class="example">
<pre class="example">a = [1, 2; 3, 4]
</pre></div>
<p>results in the matrix
</p>
<div class="example">
<pre class="example">
/ \
| 1 2 |
a = | |
| 3 4 |
\ /
</pre></div>
<p>Elements of a matrix may be arbitrary expressions, provided that the
dimensions all make sense when combining the various pieces. For
example, given the above matrix, the expression
</p>
<div class="example">
<pre class="example">[ a, a ]
</pre></div>
<p>produces the matrix
</p>
<div class="example">
<pre class="example">ans =
1 2 1 2
3 4 3 4
</pre></div>
<p>but the expression
</p>
<div class="example">
<pre class="example">[ a, 1 ]
</pre></div>
<p>produces the error
</p>
<div class="example">
<pre class="example">error: number of rows must match (1 != 2) near line 13, column 6
</pre></div>
<p>(assuming that this expression was entered as the first thing on line
13, of course).
</p>
<p>Inside the square brackets that delimit a matrix expression, Octave
looks at the surrounding context to determine whether spaces and newline
characters should be converted into element and row separators, or
simply ignored, so an expression like
</p>
<div class="example">
<pre class="example">a = [ 1 2
3 4 ]
</pre></div>
<p>will work. However, some possible sources of confusion remain. For
example, in the expression
</p>
<div class="example">
<pre class="example">[ 1 - 1 ]
</pre></div>
<p>the ‘<samp>-</samp>’ is treated as a binary operator and the result is the
scalar 0, but in the expression
</p>
<div class="example">
<pre class="example">[ 1 -1 ]
</pre></div>
<p>the ‘<samp>-</samp>’ is treated as a unary operator and the result is the
vector <code>[ 1, -1 ]</code>. Similarly, the expression
</p>
<div class="example">
<pre class="example">[ sin (pi) ]
</pre></div>
<p>will be parsed as
</p>
<div class="example">
<pre class="example">[ sin, (pi) ]
</pre></div>
<p>and will result in an error since the <code>sin</code> function will be
called with no arguments. To get around this, you must omit the space
between <code>sin</code> and the opening parenthesis, or enclose the
expression in a set of parentheses:
</p>
<div class="example">
<pre class="example">[ (sin (pi)) ]
</pre></div>
<p>Whitespace surrounding the single quote character (‘<samp>'</samp>’, used as a
transpose operator and for delimiting character strings) can also cause
confusion. Given <code>a = 1</code>, the expression
</p>
<div class="example">
<pre class="example">[ 1 a' ]
</pre></div>
<p>results in the single quote character being treated as a
transpose operator and the result is the vector <code>[ 1, 1 ]</code>, but the
expression
</p>
<div class="example">
<pre class="example">[ 1 a ' ]
</pre></div>
<p>produces the error message
</p>
<div class="example">
<pre class="example">parse error:
syntax error
>>> [ 1 a ' ]
^
</pre></div>
<p>because not doing so would cause trouble when parsing the valid expression
</p>
<div class="example">
<pre class="example">[ a 'foo' ]
</pre></div>
<p>For clarity, it is probably best to always use commas and semicolons to
separate matrix elements and rows.
</p>
<p>The maximum number of elements in a matrix is fixed when Octave is compiled.
The allowable number can be queried with the function <code>sizemax</code>. Note
that other factors, such as the amount of memory available on your machine,
may limit the maximum size of matrices to something smaller.
</p>
<a name="XREFsizemax"></a><dl>
<dt><a name="index-sizemax"></a>: <em></em> <strong>sizemax</strong> <em>()</em></dt>
<dd><p>Return the largest value allowed for the size of an array.
</p>
<p>If Octave is compiled with 64-bit indexing, the result is of class int64,
otherwise it is of class int32. The maximum array size is slightly
smaller than the maximum value allowable for the relevant class as reported
by <code>intmax</code>.
</p>
<p><strong>See also:</strong> <a href="Integer-Data-Types.html#XREFintmax">intmax</a>.
</p></dd></dl>
<p>When you type a matrix or the name of a variable whose value is a
matrix, Octave responds by printing the matrix in with neatly aligned
rows and columns. If the rows of the matrix are too large to fit on the
screen, Octave splits the matrix and displays a header before each
section to indicate which columns are being displayed. You can use the
following variables to control the format of the output.
</p>
<a name="XREFoutput_005fmax_005ffield_005fwidth"></a><dl>
<dt><a name="index-output_005fmax_005ffield_005fwidth"></a>: <em><var>val</var> =</em> <strong>output_max_field_width</strong> <em>()</em></dt>
<dt><a name="index-output_005fmax_005ffield_005fwidth-1"></a>: <em><var>old_val</var> =</em> <strong>output_max_field_width</strong> <em>(<var>new_val</var>)</em></dt>
<dt><a name="index-output_005fmax_005ffield_005fwidth-2"></a>: <em></em> <strong>output_max_field_width</strong> <em>(<var>new_val</var>, "local")</em></dt>
<dd><p>Query or set the internal variable that specifies the maximum width
of a numeric output field.
</p>
<p>When called from inside a function with the <code>"local"</code> option, the
variable is changed locally for the function and any subroutines it calls.
The original variable value is restored when exiting the function.
</p>
<p><strong>See also:</strong> <a href="Terminal-Output.html#XREFformat">format</a>, <a href="#XREFfixed_005fpoint_005fformat">fixed_point_format</a>, <a href="#XREFoutput_005fprecision">output_precision</a>.
</p></dd></dl>
<a name="XREFoutput_005fprecision"></a><dl>
<dt><a name="index-output_005fprecision"></a>: <em><var>val</var> =</em> <strong>output_precision</strong> <em>()</em></dt>
<dt><a name="index-output_005fprecision-1"></a>: <em><var>old_val</var> =</em> <strong>output_precision</strong> <em>(<var>new_val</var>)</em></dt>
<dt><a name="index-output_005fprecision-2"></a>: <em></em> <strong>output_precision</strong> <em>(<var>new_val</var>, "local")</em></dt>
<dd><p>Query or set the internal variable that specifies the minimum number of
significant figures to display for numeric output.
</p>
<p>When called from inside a function with the <code>"local"</code> option, the
variable is changed locally for the function and any subroutines it calls.
The original variable value is restored when exiting the function.
</p>
<p><strong>See also:</strong> <a href="Terminal-Output.html#XREFformat">format</a>, <a href="#XREFfixed_005fpoint_005fformat">fixed_point_format</a>, <a href="#XREFoutput_005fmax_005ffield_005fwidth">output_max_field_width</a>.
</p></dd></dl>
<p>It is possible to achieve a wide range of output styles by using
different values of <code>output_precision</code> and
<code>output_max_field_width</code>. Reasonable combinations can be set using
the <code>format</code> function. See <a href="Basic-Input-and-Output.html#Basic-Input-and-Output">Basic Input and Output</a>.
</p>
<a name="XREFsplit_005flong_005frows"></a><dl>
<dt><a name="index-split_005flong_005frows"></a>: <em><var>val</var> =</em> <strong>split_long_rows</strong> <em>()</em></dt>
<dt><a name="index-split_005flong_005frows-1"></a>: <em><var>old_val</var> =</em> <strong>split_long_rows</strong> <em>(<var>new_val</var>)</em></dt>
<dt><a name="index-split_005flong_005frows-2"></a>: <em></em> <strong>split_long_rows</strong> <em>(<var>new_val</var>, "local")</em></dt>
<dd><p>Query or set the internal variable that controls whether rows of a matrix
may be split when displayed to a terminal window.
</p>
<p>If the rows are split, Octave will display the matrix in a series of smaller
pieces, each of which can fit within the limits of your terminal width and
each set of rows is labeled so that you can easily see which columns are
currently being displayed. For example:
</p>
<div class="example">
<pre class="example">octave:13> rand (2,10)
ans =
Columns 1 through 6:
0.75883 0.93290 0.40064 0.43818 0.94958 0.16467
0.75697 0.51942 0.40031 0.61784 0.92309 0.40201
Columns 7 through 10:
0.90174 0.11854 0.72313 0.73326
0.44672 0.94303 0.56564 0.82150
</pre></div>
<p>When called from inside a function with the <code>"local"</code> option, the
variable is changed locally for the function and any subroutines it calls.
The original variable value is restored when exiting the function.
</p>
<p><strong>See also:</strong> <a href="Terminal-Output.html#XREFformat">format</a>.
</p></dd></dl>
<p>Octave automatically switches to scientific notation when values become
very large or very small. This guarantees that you will see several
significant figures for every value in a matrix. If you would prefer to
see all values in a matrix printed in a fixed point format, you can set
the built-in variable <code>fixed_point_format</code> to a nonzero value. But
doing so is not recommended, because it can produce output that can
easily be misinterpreted.
</p>
<a name="XREFfixed_005fpoint_005fformat"></a><dl>
<dt><a name="index-fixed_005fpoint_005fformat"></a>: <em><var>val</var> =</em> <strong>fixed_point_format</strong> <em>()</em></dt>
<dt><a name="index-fixed_005fpoint_005fformat-1"></a>: <em><var>old_val</var> =</em> <strong>fixed_point_format</strong> <em>(<var>new_val</var>)</em></dt>
<dt><a name="index-fixed_005fpoint_005fformat-2"></a>: <em></em> <strong>fixed_point_format</strong> <em>(<var>new_val</var>, "local")</em></dt>
<dd><p>Query or set the internal variable that controls whether Octave will
use a scaled format to print matrix values.
</p>
<p>The scaled format prints a scaling factor on the first line of output chosen
such that the largest matrix element can be written with a single leading
digit. For example:
</p>
<div class="example">
<pre class="example">logspace (1, 7, 5)'
ans =
1.0e+07 *
0.00000
0.00003
0.00100
0.03162
1.00000
</pre></div>
<p>Notice that the first value appears to be 0 when it is actually 1. Because
of the possibility for confusion you should be careful about enabling
<code>fixed_point_format</code>.
</p>
<p>When called from inside a function with the <code>"local"</code> option, the
variable is changed locally for the function and any subroutines it calls.
The original variable value is restored when exiting the function.
</p>
<p><strong>See also:</strong> <a href="Terminal-Output.html#XREFformat">format</a>, <a href="#XREFoutput_005fmax_005ffield_005fwidth">output_max_field_width</a>, <a href="#XREFoutput_005fprecision">output_precision</a>.
</p></dd></dl>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="Empty-Matrices.html#Empty-Matrices" accesskey="1">Empty Matrices</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<div class="header">
<p>
Next: <a href="Ranges.html#Ranges" accesskey="n" rel="next">Ranges</a>, Up: <a href="Numeric-Data-Types.html#Numeric-Data-Types" accesskey="u" rel="up">Numeric Data Types</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|