home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / maths / rlab / docs / RLEF41~1 < prev    next >
Encoding:
Text File  |  1997-03-09  |  107.6 KB  |  3,846 lines

  1. <HTML>
  2. <HEAD>
  3. <TITLE> Rlab2 Reference Manual: Builtin Functions</TITLE>
  4. </HEAD>
  5. <BODY>
  6. <A HREF="rlab-ref-6.html"><IMG SRC="prev.gif" ALT="Previous"></A>
  7. <A HREF="rlab-ref-8.html"><IMG SRC="next.gif" ALT="Next"></A>
  8. <A HREF="rlab-ref.html#toc7"><IMG SRC="toc.gif" ALT="Contents"></A>
  9. <HR>
  10. <H2><A NAME="s7">7. Builtin Functions</A></H2>
  11.  
  12.  
  13. <P>This chapter covers the built-in functions. Normally, no distinction
  14. is made between the built-in, and the user-functions. However, they
  15. are documented separately because custom installations, and program
  16. execution options make it possible for Rlab to run with many of the
  17. user-functions missing.</P>
  18. <P>The documentation for each built-in function is nearly the same as
  19. the online help. In fact, the printed documentation is the source of
  20. the online help files.</P>
  21.  
  22.  
  23.  
  24. <H2><A NAME="ss7.1">7.1 abs </A></H2>
  25.  
  26. <P>
  27. <DL>
  28. <DT><B> Synopsis </B><DD><P>Compute the absolute value. </P>
  29. <DT><B> Syntax </B><DD><P>abs ( <EM> A </EM> )</P>
  30. <DT><B> Description </B><DD><P>abs returns the absolute value of it's input,
  31. <EM>A</EM>. abs is a scalar function.</P>
  32. <P>For complex values abs returns the square root of the
  33. sum of the squares of the real and imaginary parts.</P>
  34.  
  35. </DL>
  36. </P>
  37.  
  38. <H2><A NAME="ss7.2">7.2 acos </A></H2>
  39.  
  40. <P>
  41. <DL>
  42. <DT><B> Synopsis </B><DD><P>Compute the arc-cosine. </P>
  43. <DT><B> Syntax </B><DD><P>acos ( <EM>A</EM> ) </P>
  44. <DT><B> Description </B><DD><P>The trigonometric functions are scalars functions.  The return
  45. value is the result of the trigonometric operation performed
  46. on the input, element-by-element.</P>
  47. <P>All the trigonometric functions use the C language math
  48. library functions, so details about the ranges and error
  49. conditions can be found by examining the appropriate man pages
  50. on your system.</P>
  51.  
  52. </DL>
  53. </P>
  54.  
  55. <H2><A NAME="ss7.3">7.3 all </A></H2>
  56.  
  57. <P>
  58. <DL>
  59. <DT><B> Synopsis </B><DD><P>Check if <EM>all</EM> elements are non-zero. </P>
  60. <DT><B> Syntax </B><DD><P>all ( <EM>A</EM> )</P>
  61. <DT><B> Description </B><DD><P>When <EM>A</EM> is a vector (row or column):
  62. <BLOCKQUOTE>
  63. all returns TRUE (1) if all of the elements of <EM>A</EM> are non-zero.
  64. all returns zero otherwise.
  65. </BLOCKQUOTE>
  66. </P>
  67. <P>When <EM>A</EM> is a matrix:
  68. <BLOCKQUOTE>
  69. all operates on the columns of <EM>A</EM>, returning a row-vector of
  70. ones and zeros.
  71. </BLOCKQUOTE>
  72. </P>
  73.  
  74. <DT><B>See Also</B><DD><P>any</P>
  75.  
  76.  
  77. </DL>
  78. </P>
  79.  
  80. <H2><A NAME="ss7.4">7.4 any </A></H2>
  81.  
  82. <P>
  83. <DL>
  84. <DT><B> Synopsis </B><DD><P>Check if <EM>any</EM> elements are non-zero. </P>
  85. <DT><B> Syntax </B><DD><P>any ( <EM>A</EM> ) </P>
  86. <DT><B> Description </B><DD><P>When <EM>A</EM> is a vector (row or column):
  87. <BLOCKQUOTE>
  88. any returns TRUE (1) if any of the elements of <EM>A</EM> are non-zero.
  89. any returns FALSE (0) otherwise.
  90. </BLOCKQUOTE>
  91. </P>
  92. <P>When <EM>A</EM> is a matrix:
  93. <BLOCKQUOTE>
  94. any operates on the columns of <EM>A</EM>, returning a row-vector of
  95. ones and zeros.
  96. </BLOCKQUOTE>
  97. </P>
  98.  
  99. <DT><B>See Also</B><DD><P>all</P>
  100.  
  101.  
  102. </DL>
  103. </P>
  104.  
  105. <H2><A NAME="ss7.5">7.5 asin </A></H2>
  106.  
  107. <P>
  108. <DL>
  109. <DT><B> Synopsis </B><DD><P>Compute the arc-sin. </P>
  110. <DT><B> Syntax </B><DD><P>asin ( <EM>A</EM> ) </P>
  111. <DT><B> Description </B><DD><P>RLaB trigonometric functions are designed to take scalars, and
  112. matrices as arguments. The return value is the input argument
  113. with the trigonometric operation performed element by element.</P>
  114. <P>The trigonometric functions use the C language math library
  115. functions, so details about the ranges and error conditions
  116. can be found by examining the appropriate man pages on your
  117. system.</P>
  118.  
  119. </DL>
  120. </P>
  121.  
  122. <H2><A NAME="ss7.6">7.6 atan </A></H2>
  123.  
  124. <P>
  125. <DL>
  126. <DT><B> Synopsis </B><DD><P>Compute the arc-tangent. </P>
  127. <DT><B> Syntax </B><DD><P>atan ( <EM>A</EM> ) </P>
  128. <DT><B> Description </B><DD><P>RLaB trigonometric functions are designed to take scalars, and
  129. matrices as arguments. The return value is the input argument
  130. with the trigonometric operation performed element by element.</P>
  131. <P>The trigonometric functions use the C language math library
  132. functions, so details about the ranges and error conditions
  133. can be found by examining the appropriate man pages on your
  134. system.</P>
  135.  
  136. </DL>
  137. </P>
  138.  
  139. <H2><A NAME="ss7.7">7.7 atan2 </A></H2>
  140.  
  141. <P>
  142. <DL>
  143. <DT><B> Synopsis </B><DD><P>Compute the arc-tangent. </P>
  144. <DT><B> Syntax </B><DD><P>atan2 ( <EM>y</EM> , <EM>x</EM> )</P>
  145. <DT><B> Description </B><DD><P>RLaB trigonometric functions are designed to take scalars, and
  146. matrices as arguments. The return value is the input argument
  147. with the trigonometric operation performed element by element.</P>
  148. <P>atan2 takes two arguments, which are the y, and x values
  149. used to form the tangent. All the trigonometric functions use
  150. the C language math library functions, so details about the
  151. ranges and error conditions can be found by examining the
  152. appropriate man pages on your system.</P>
  153. <P>Atan2 does not operate on complex arguments.</P>
  154.  
  155. </DL>
  156. </P>
  157.  
  158. <H2><A NAME="ss7.8">7.8 backsub </A></H2>
  159.  
  160. <P>
  161. <DL>
  162. <DT><B> Synopsis </B><DD><P>Solution of <CODE>Ax = B</CODE> by backsubstitution. </P>
  163. <DT><B> Syntax </B><DD><P>backsub ( <EM>LIST</EM>, <EM>B</EM> )</P>
  164. <DT><B> Description </B><DD><P>The backsub function computes the solution to the set of
  165. linear equations described by:</P>
  166. <P>
  167. <BLOCKQUOTE>
  168. A * X = B 
  169. </BLOCKQUOTE>
  170. </P>
  171. <P>The 1st argument to backsub (<EM>LIST</EM>) is the result from
  172. `factor(A)'. The second argument to backsub is the matrix
  173. <EM>B</EM>.  <EM>B</EM> can contain multiple right hand sides.</P>
  174. <P>Backsub returns a matrix <EM>X</EM> which contains the solution(s) to
  175. the aforementioned equations.</P>
  176. <P>Backsub utilizes the LAPACK subroutines DGETRS or ZGETRS if
  177. <EM>LIST</EM> contains LU factors or LAPACK subroutins DSYTRS or ZHETRS
  178. if <EM>LIST</EM> contains the LDL factors.</P>
  179. <P>Example:
  180. <BLOCKQUOTE><CODE>
  181. <PRE>
  182. > A = [1,2,3;4,5,6;7,8,0]
  183.         1          2          3  
  184.         4          5          6  
  185.         7          8          0  
  186. > B = [1;2;3]
  187.         1  
  188.         2  
  189.         3  
  190. > X = backsub(factor(A), B)
  191.    -0.333  
  192.     0.667  
  193. -3.52e-18  
  194. > A*X - B
  195.         0  
  196.         0  
  197.         0  
  198. </PRE>
  199. </CODE></BLOCKQUOTE>
  200. </P>
  201.  
  202. <DT><B>See Also</B><DD><P>factor, inv, lu, solve</P>
  203.  
  204.  
  205. </DL>
  206. </P>
  207.  
  208. <H2><A NAME="ss7.9">7.9 balance </A></H2>
  209.  
  210. <P>
  211. <DL>
  212. <DT><B> Synopsis </B><DD><P>Balance a matrix for equal row and column norms. </P>
  213. <DT><B> Syntax </B><DD><P>balance ( <EM>A</EM> )</P>
  214. <DT><B> Description </B><DD><P>Balance uses the LAPACK subroutines DGEBAL and ZGEBAL to
  215. balance the input matrix so that the row and column norms are
  216. approximately equal.</P>
  217. <P>balance returns a list with elements <EM>t</EM> and <EM>ab</EM>.</P>
  218. <P>Example:
  219. <BLOCKQUOTE><CODE>
  220. <PRE>
  221. > a
  222.         0          0          1          0  
  223.         0          0          0          1  
  224.        11         10          0          0  
  225.        10         11          0          0  
  226. > </ ab ; t /> = balance(a);
  227. > inv(t)*a*t - ab
  228.         0          0          0          0  
  229.         0          0          0          0  
  230.         0          0          0          0  
  231.         0          0          0          0  
  232. </PRE>
  233. </CODE></BLOCKQUOTE>
  234. </P>
  235. <P>Only square matrices are allowed.</P>
  236.  
  237. </DL>
  238. </P>
  239.  
  240. <H2><A NAME="ss7.10">7.10 ceil </A></H2>
  241.  
  242. <P>
  243. <DL>
  244. <DT><B> Synopsis </B><DD><P>Smallest integer not less than argument. </P>
  245. <DT><B> Syntax </B><DD><P>ceil ( <EM>a</EM> )</P>
  246. <DT><B> Description </B><DD><P>Ceil returns the smallest integer not less than the argument.
  247. If the argument is a MATRIX then the ceil operation is
  248. performed on an element-by-element basis.</P>
  249.  
  250. <DT><B>See Also</B><DD><P>floor, int</P>
  251.  
  252. </DL>
  253. </P>
  254.  
  255. <H2><A NAME="ss7.11">7.11 chol </A></H2>
  256.  
  257. <P>
  258. <DL>
  259. <DT><B> Synopsis </B><DD><P>Cholesky factorization. </P>
  260. <DT><B> Syntax </B><DD><P>chol( <EM>A</EM> )</P>
  261. <DT><B> Description </B><DD><P>Chol computes the Cholesky factorization of the input matrix.
  262. The input matrix must be real symmetric positive definite, or
  263. complex Hermitian positive definite.  chol() produces an upper
  264. triangular matrix <EM>U</EM>, such that <CODE>U'*U</CODE> and <EM>A</EM>
  265. (the input) are equal.</P>
  266. <P>chol use the LAPACK subroutine DPOTRF and ZPOTRF.</P>
  267.  
  268. </DL>
  269. </P>
  270.  
  271. <H2><A NAME="ss7.12">7.12 class </A></H2>
  272.  
  273. <P>
  274. <DL>
  275. <DT><B> Synopsis </B><DD><P>Identify the class of an object. </P>
  276. <DT><B> Syntax </B><DD><P>class ( <EM>A</EM> ) </P>
  277. <DT><B> Description </B><DD><P>Class returns a string which identifies the type of the object
  278. that <EM>A</EM> represents. Valid classes are:</P>
  279. <P>
  280. <UL>
  281. <LI>    num</LI>
  282. <LI>    string</LI>
  283. <LI>    list</LI>
  284. <LI>    function</LI>
  285. </UL>
  286. </P>
  287. <P>It is often useful to:</P>
  288. <P>
  289. <BLOCKQUOTE><CODE>
  290. <PRE>
  291. if(class(m) == "num") 
  292. {
  293.   # Perform numerical computation on m
  294. }
  295. </PRE>
  296. </CODE></BLOCKQUOTE>
  297. </P>
  298. <P>The class of a variable can also be determined by using the
  299. class member reference (except for LISTs), like:</P>
  300. <P>
  301. <BLOCKQUOTE><CODE>
  302. <PRE>
  303. > zeros.class
  304. function
  305. </PRE>
  306. </CODE></BLOCKQUOTE>
  307. </P>
  308.  
  309. <DT><B>See Also</B><DD><P>show, type</P>
  310.  
  311. </DL>
  312. </P>
  313.  
  314. <H2><A NAME="ss7.13">7.13 clear </A></H2>
  315.  
  316. <P>
  317. <DL>
  318. <DT><B> Synopsis </B><DD><P>Delete a variable. </P>
  319. <DT><B> Syntax </B><DD><P>clear ( <EM>A</EM> ) </P>
  320. <DT><B> Description </B><DD><P>Clear effectively deletes a variables object from the symbol
  321. table. The effect is the variable does not show up when who()
  322. is used. The memory associated with the variable is freed. </P>
  323. <P>Clear accepts up to 32 arguments, the return value is the
  324. number of objects that have been successfully cleared.</P>
  325.  
  326. </DL>
  327. </P>
  328.  
  329. <H2><A NAME="ss7.14">7.14 close </A></H2>
  330.  
  331. <P>
  332. <DL>
  333. <DT><B> Synopsis </B><DD><P>Close a file. </P>
  334. <DT><B> Syntax </B><DD><P>close ( <EM>filename</EM> )</P>
  335. <DT><B> Description </B><DD><P>close takes a string (<EM>filename</EM>) as input, and attempts
  336. to close the output stream associated with
  337. <EM>filename</EM>. close returns TRUE (1) if the output stream
  338. was successfully closed, FALSE (0) if the output stream could
  339. not be closed.</P>
  340. <P>If you want to read the contents of a file that you have
  341. created with the write function in the present session, then
  342. be sure to close the file before using the read function.</P>
  343. <P>Example:
  344. <BLOCKQUOTE><CODE>
  345. <PRE>
  346. write( "eig_output", a , vec , val );
  347. close( "eig_output" );
  348. read( "eig_output" );
  349.         
  350. </PRE>
  351. </CODE></BLOCKQUOTE>
  352. </P>
  353.  
  354. <DT><B>See Also</B><DD><P>printf, fprintf, getline, open, read, readb, readm, write, writeb, writem</P>
  355.  
  356. </DL>
  357. </P>
  358.  
  359. <H2><A NAME="ss7.15">7.15 conj </A></H2>
  360.  
  361. <P>
  362. <DL>
  363. <DT><B> Synopsis </B><DD><P>Complex conjugate. </P>
  364. <DT><B> Syntax </B><DD><P>conj ( <EM>A</EM> )</P>
  365. <DT><B> Description </B><DD><P>Conj returns the complex conjugate of its input argument.
  366. For MATRIX arguments the conjugate is performed element by
  367. element.</P>
  368.  
  369. <DT><B>See Also</B><DD><P>imag, real</P>
  370.  
  371.  
  372. </DL>
  373. </P>
  374.  
  375. <H2><A NAME="ss7.16">7.16 cos </A></H2>
  376.  
  377. <P>
  378. <DL>
  379. <DT><B> Synopsis </B><DD><P>Compute the cosine. </P>
  380. <DT><B> Syntax </B><DD><P>cos ( <EM>A</EM> )</P>
  381. <DT><B> Description </B><DD><P>The trigonometric functions are scalars functions.  The return
  382. value is the result of the trigonometric operation performed
  383. on the input, element-by-element.</P>
  384. <P>All the trigonometric functions use the C language math
  385. library functions, so details about the ranges and error
  386. conditions can be found by examining the appropriate man pages
  387. on your system.</P>
  388.  
  389. </DL>
  390. </P>
  391.  
  392. <H2><A NAME="ss7.17">7.17 cumprod </A></H2>
  393.  
  394. <P>
  395. <DL>
  396. <DT><B> Synopsis </B><DD><P>Cumulative product. </P>
  397. <DT><B> Syntax </B><DD><P>cumprod ( <EM>A</EM> ) </P>
  398. <DT><B> Description </B><DD><P>cumprod computes the running, or cumulative product of the
  399. input, <EM>A</EM>. If the input is a rectangular matrix, then the
  400. cumulative product is performed over the columns of the
  401. matrix. </P>
  402. <P>Example:</P>
  403. <P>
  404. <BLOCKQUOTE><CODE>
  405. <PRE>
  406. > a=1:4
  407.  a =
  408.         1          2          3          4  
  409. > cumprod (a)
  410.         1          2          6         24  
  411. > a = [1,2,3;4,5,6;7,8,9]
  412.  a =
  413.         1          2          3  
  414.         4          5          6  
  415.         7          8          9  
  416. > cumprod (a)
  417.         1          2          3  
  418.         4         10         18  
  419.        28         80        162  
  420. </PRE>
  421. </CODE></BLOCKQUOTE>
  422. </P>
  423.  
  424. <DT><B>See Also</B><DD><P>cumsum, prod, sum</P>
  425.  
  426.  
  427. </DL>
  428. </P>
  429.  
  430. <H2><A NAME="ss7.18">7.18 cumsum </A></H2>
  431.  
  432. <P>
  433. <DL>
  434. <DT><B> Synopsis </B><DD><P>Cumulative sum. </P>
  435. <DT><B> Syntax </B><DD><P>cumsum ( <EM>A</EM> ) </P>
  436. <DT><B> Description </B><DD><P>cumsum computes the running, or cumulative sum of a vector or
  437. matrix. The return object is a matrix the same size as the
  438. input, <EM>A</EM>. If <EM>A</EM> is a rectangular matrix, then the
  439. cumulative sums are performed over the columns of the matrix.</P>
  440. <P>Example:
  441. <BLOCKQUOTE><CODE>
  442. <PRE>
  443. > a = 1:4
  444.  a =
  445.         1          2          3          4  
  446. > cumsum(a)
  447.         1          3          6         10  
  448. > a= [1,2,3;4,5,6;7,8,9]
  449.  a =
  450.         1          2          3  
  451.         4          5          6  
  452.         7          8          9  
  453. > cumsum (a)
  454.         1          2          3  
  455.         5          7          9  
  456.        12         15         18  
  457. </PRE>
  458. </CODE></BLOCKQUOTE>
  459. </P>
  460.  
  461. <DT><B>See Also</B><DD><P>cumprod, prod, sum</P>
  462.  
  463.  
  464. </DL>
  465. </P>
  466.  
  467. <H2><A NAME="ss7.19">7.19 det </A></H2>
  468.  
  469. <P>
  470. <DL>
  471. <DT><B> Synopsis </B><DD><P>Matrix determinant. </P>
  472. <DT><B> Syntax </B><DD><P>det ( <EM>A</EM> )</P>
  473. <DT><B> Description </B><DD><P>Det computes the determinant of the matrix argument.</P>
  474. <P>Det uses the LAPACK functions to factor the input, and the
  475. LINPACK algorithm to calculate the determinant.</P>
  476. <P>See Also inv, lu, rcond</P>
  477.  
  478. </DL>
  479. </P>
  480.  
  481. <H2><A NAME="ss7.20">7.20 diag </A></H2>
  482.  
  483. <P>
  484. <DL>
  485. <DT><B> Synopsis </B><DD><P>Diagnonal matrix. </P>
  486. <DT><B> Syntax </B><DD><P>diag ( <EM>A</EM> )</P>
  487. <P>    diag ( <EM>A</EM>, <EM>K</EM> )</P>
  488. <DT><B> Description </B><DD><P>If the 1st argument, <EM>A</EM> is a 1xN matrix construct a
  489. diagonal matrix from the input. Optionally if <EM>K</EM>
  490. (scalar) is specified then create a matrix with the vector as
  491. the <EM>K</EM>th diagonal.</P>
  492. <P>If the 1st argument is a MxN matrix, construct a 1xN matrix
  493. from the diagonal elements of the input matrix. Optionally if
  494. <EM>K</EM> is specified return the vector from the <EM>K</EM>th
  495. diagonal of the input matrix.</P>
  496. <P>
  497. <BLOCKQUOTE>
  498. <EM>K</EM> < is below the main diagonal.
  499. </BLOCKQUOTE>
  500. </P>
  501. <P>
  502. <BLOCKQUOTE>
  503. <EM>K</EM> > is above the main diagonal.
  504. </BLOCKQUOTE>
  505. </P>
  506.  
  507. <DT><B>See Also</B><DD><P>tril, triu</P>
  508.  
  509. </DL>
  510. </P>
  511.  
  512. <H2><A NAME="ss7.21">7.21 diary</A></H2>
  513.  
  514. <P>
  515. <DL>
  516. <DT><B> Synopsis </B><DD><P>Log commands (program statements) to a file.</P>
  517. <DT><B> Syntax </B><DD><P>diary ( ) </P>
  518. <P>diary ( <EM>FILENAME</EM> )</P>
  519. <DT><B> Description </B><DD><P>The diary function echoes all input commands and Rlab output
  520. to a diary file. If <EM>FILENAME</EM> is not specified, then a
  521. file named: <CODE>DIARY</CODE> is opened.</P>
  522. <P>The diary, used without any arguments will turn on statement
  523. logging, or turn off statement logging if a diary file is
  524. already open.</P>
  525.  
  526. </DL>
  527. </P>
  528.  
  529. <H2><A NAME="ss7.22">7.22 dlopen </A></H2>
  530.  
  531. <P>
  532. <DL>
  533. <DT><B> Synopsis </B><DD><P>Dynamically link a function. </P>
  534. <DT><B> Syntax </B><DD><P>dlopen ( <EM>FILENAME</EM> , <EM>FUNCTION_NAME</EM> )</P>
  535. <DT><B> Description </B><DD><P>dlopen opens a shared object, <EM>FILENAME</EM>, and creates a
  536. builtin function that points to <EM>FUNCTION_NAME</EM>. dlopen
  537. returns the newly created builtin function.</P>
  538. <P>For information on how to write and compile functions that can
  539. be linked with dlopen, consult the RLaB Programmer's Guide and
  540. Reference Manual.</P>
  541. <P>dlopen only exists for those platforms that support dynamic
  542. linking. As of this writing support exists for Solaris 2.x and
  543. Linux/ELF platforms.</P>
  544.  
  545. </DL>
  546. </P>
  547.  
  548. <H2><A NAME="ss7.23">7.23 eig </A></H2>
  549.  
  550. <P>
  551. <DL>
  552. <DT><B> Synopsis </B><DD><P>Eigensolver. </P>
  553. <DT><B> Syntax </B><DD><P>eig ( <EM>A</EM> ) </P>
  554. <DT><B> Description </B><DD><P>
  555. <DL>
  556. <DT><B>eig ( <EM>A</EM> )</B><DD><P>Computes the eigenvectors, and values of matrix
  557. <EM>A</EM>. eig() returns a LIST with elements `val' and
  558. `vec' which are the eigenvalues and eigenvectors. Eig
  559. checks for symmetry in <EM>A</EM>, and uses the
  560. appropriate solver.</P>
  561.  
  562. <DT><B>eig ( <EM>A</EM> , <EM>B</EM> )</B><DD><P>Computes the eigenvectors, and values of <EM>A</EM>, and
  563. <EM>B</EM>.  Where <CODE>A*x = lambda*B*x</CODE>. The values
  564. and vectors are returned in a list with element names
  565. <EM>val</EM> and <EM>vec</EM>. Eig checks for symmetry in
  566. <EM>A</EM> and <EM>B</EM> and uses the appropriate solver.</P>
  567.  
  568. </DL>
  569. </P>
  570. <P>Uses the LAPACK subroutines DSYEV/ZHEEV or DGEEV/ZGEEV.</P>
  571. <P><B>Example:</B></P>
  572. <P>The generalized eigenvalue problem arises quite regularly in
  573. structures. From the second order differential equations
  574. describing a lumped mass system arise $M$ and $K$, coefficient
  575. matrices representing the mass and stiffness of the various
  576. physical degress of freedom. The equations are formulated as
  577. follows:</P>
  578. <P>
  579. <BLOCKQUOTE><CODE>
  580. <PRE>
  581. M*dx^2/dt^2 + K*x = F 
  582.         
  583. </PRE>
  584. </CODE></BLOCKQUOTE>
  585. </P>
  586. <P>Which leads to the eigenvalue problem:</P>
  587. <P>
  588. <BLOCKQUOTE><CODE>
  589. <PRE>
  590. K*v = w^2*M*v 
  591.         
  592. </PRE>
  593. </CODE></BLOCKQUOTE>
  594. </P>
  595. <P>For a two degree of freedom system we might have:</P>
  596. <P>
  597. <BLOCKQUOTE><CODE>
  598. <PRE>
  599. > m = eye(2,2)
  600. > k = [5,1;1,5]
  601. > </ val ; vec /> = eig(k, m);
  602.         
  603. > // Test the solution
  604.         
  605. > k * vec[;1]
  606.     -2.83  
  607.      2.83  
  608. > val[1] * m * vec[;1]
  609.     -2.83  
  610.      2.83  
  611.         
  612. > // Properties of the solution
  613.  
  614. > vec' * m * vec
  615.         1  -4.27e-17  
  616. -4.27e-17          1  
  617.         
  618. > vec' * k * vec
  619.         4  -1.71e-16  
  620.  1.23e-16          6  
  621. </PRE>
  622. </CODE></BLOCKQUOTE>
  623. </P>
  624. <P>The eigenvalues and vectors are sometimes obtained by
  625. converting the generalized problem into a standard eigenvalue
  626. problem (this is only feasible under certain conditions).</P>
  627. <P>
  628. <BLOCKQUOTE><CODE>
  629. <PRE>
  630. > a = m\k
  631.  a =
  632.         5          1  
  633.         1          5  
  634. > eig(a).val
  635.  val =
  636.         4          6  
  637. > eig(a).vec
  638.  vec =
  639.    -0.707      0.707  
  640.     0.707      0.707  
  641. </PRE>
  642. </CODE></BLOCKQUOTE>
  643. </P>
  644.  
  645. <DT><B>See Also</B><DD><P>svd, schur</P>
  646.  
  647.  
  648. </DL>
  649. </P>
  650.  
  651. <H2><A NAME="ss7.24">7.24 entinfo </A></H2>
  652.  
  653. <P>
  654. <DL>
  655. <DT><B> Synopsis </B><DD><P>Return entity information.</P>
  656. <DT><B> Syntax </B><DD><P>entinfo ( <EM>VAR</EM> )</P>
  657. <DT><B> Description </B><DD><P>Entinfo returns the internal address, and reference count of
  658. <EM>VAR</EM>. This function is not intended for general
  659. use... so no explanation of the function's purpose, or
  660. guarentees regarding its future availability will be made.</P>
  661.  
  662. </DL>
  663. </P>
  664.  
  665. <H2><A NAME="ss7.25">7.25 error </A></H2>
  666.  
  667. <P>
  668. <DL>
  669. <DT><B> Synopsis </B><DD><P>Error handling / reporting.</P>
  670. <DT><B> Syntax </B><DD><P>error ( <EM>STRING</EM> ) </P>
  671. <DT><B> Description </B><DD><P>The error function allows user-functions to jump back to the
  672. prompt when some sort of error has occurred. The nature of the
  673. error is up to the user. When an error is detected the user
  674. simply calls error(). If no argument is supplied, error() will
  675. print the default message. Otherwise, error prints the string
  676. supplied as an argument, and jumps back to the prompt.</P>
  677. <P>Jumping "back to the prompt" means execution of the current
  678. loop or function is terminated immediately and execution of
  679. any prompt-level statements is performed.</P>
  680.  
  681. </DL>
  682. </P>
  683.  
  684. <H2><A NAME="ss7.26">7.26 eval </A></H2>
  685.  
  686. <P>
  687. <DL>
  688. <DT><B> Synopsis </B><DD><P>Evaluate expressions.</P>
  689. <DT><B> Syntax </B><DD><P>eval ( <EM>S</EM> ) </P>
  690. <DT><B> Description </B><DD><P>The eval function evaluates the statement contained in the
  691. string argument <EM>S</EM>. eval returns the result of the
  692. statement in <EM>S</EM>. eval can be used within functions and
  693. can distinguish local and argument variables from global.</P>
  694. <P>Before we go any further, we should note that eval is not
  695. really a necessary part of RLaB. Users should defintely not
  696. use it a a crutch as with some other matrix programming
  697. languages. The RLaB concept of variables, and the list class
  698. are more efficient ways of dealing with function evaluations
  699. and variable variable names than eval.</P>
  700. <P>Examples:</P>
  701. <P>
  702. <BLOCKQUOTE><CODE>
  703. <PRE>
  704. > // Evaluate a simple string.
  705. > // Demonstrate the ability to work with function
  706. > // arguments.
  707. >
  708. > x=function(s,a){return eval(s);}
  709.         <user-function>
  710. > str = "yy = 2 + x(\"2*a\", 3.5)"
  711.  str =
  712. yy = 2 + x("2*a", 3.5)
  713. > z = eval(str)
  714.  z =
  715.         9
  716. > whos();
  717.         Name            Class   Type    Size            NBytes
  718.         eps             num     real    1       1       16
  719.         pi              num     real    1       1       16
  720.         str             string  string  1       1       22
  721.         yy              num     real    1       1       16
  722.         z               num     real    1       1       16
  723. Total MBytes = 0.129062
  724. > // First create a function that will eval a matrix.
  725. >
  726. > evalm = function ( m )
  727. > {
  728. >   local (mnew, i)
  729. >       
  730. >   mnew = zeros (size (m));
  731. >    for (i in 1:m.n)
  732. >   {
  733. >     mnew[i] = eval (m[i]);
  734. >   }
  735. >       
  736. >   return mnew;
  737. > };
  738. >
  739. > // Then create a string matrix...
  740. >
  741. > mstr = ["x + 1",    "x + sqrt(x)" ;
  742. >         "cos(2*x)", "sin(sqrt(x))" ]
  743.         > x = 2
  744.  x =
  745.         2
  746. >
  747. > m = evalm(mstr)
  748.  m =
  749.         3       3.41  
  750.    -0.654      0.988  
  751. >
  752. > // Define a second function that does eval twice
  753. > eval2m = function ( m )
  754. > {
  755. >   local (mnew, i)
  756. >   mnew = zeros (size (m));
  757. >   for (i in 1:m.n)
  758. >   {
  759. >     mnew[i] = eval (eval (m[i]));
  760. >   }
  761. >   return mnew;
  762. > };
  763. > mstr = [ "E1", "E2" ;
  764. >          "E2", "E3" ]
  765.  mstr =
  766. E1  E2  
  767. E2  E3  
  768. > E1 = "cos(2*x) + 3";
  769. > E2 = "tan(x)";
  770. > E3 = "exp(x)";
  771. > m = eval2m(mstr)
  772.  m =
  773.      2.35      -2.19  
  774.     -2.19       7.39  
  775. </PRE>
  776. </CODE></BLOCKQUOTE>
  777. </P>
  778.  
  779. </DL>
  780. </P>
  781.  
  782. <H2><A NAME="ss7.27">7.27 exist </A></H2>
  783.  
  784. <P>
  785. <DL>
  786. <DT><B> Synopsis </B><DD><P>Check the existence of a variable.</P>
  787. <DT><B> Syntax </B><DD><P>exist ( <EM>VAR</EM> ) </P>
  788. <DT><B> Description </B><DD><P>The exist function returns TRUE (1) if <EM>VAR</EM> exists, and
  789. FALSE (0), if <EM>VAR</EM> does not exist. <EM>VAR</EM> is any
  790. valid variable name.</P>
  791. <P>If you need to know if a variable exists, and if it is a
  792. function or data, then use the exist function in conjunction
  793. with the class or type functions.</P>
  794.  
  795. <DT><B>See Also</B><DD><P>class, type, who, what</P>
  796.  
  797.  
  798. </DL>
  799. </P>
  800.  
  801. <H2><A NAME="ss7.28">7.28 exp </A></H2>
  802.  
  803. <P>
  804. <DL>
  805. <DT><B> Synopsis </B><DD><P>Exponential function.</P>
  806. <DT><B> Syntax </B><DD><P>exp ( <EM>X</EM> )</P>
  807. <DT><B> Description </B><DD><P>Exp returns the value of e (the base of natural logarithms)
  808. raised to the power of <EM>X</EM>. If the argument to exp is a
  809. matrix then an element-by-element operation is performed.</P>
  810.  
  811. </DL>
  812. </P>
  813.  
  814. <H2><A NAME="ss7.29">7.29 factor </A></H2>
  815.  
  816. <P>
  817. <DL>
  818. <DT><B> Synopsis </B><DD><P>Factor a square matrix.</P>
  819. <DT><B> Syntax </B><DD><P>factor ( <EM>A</EM> )</P>
  820. <DT><B> Description </B><DD><P>The factor function computes the LU factorization of the input
  821. matrix <EM>A</EM>. Factor returns a list with 3 elements: </P>
  822. <P><B> if <EM>A</EM> is a general matrix: </B>
  823. <DL>
  824. <DT><B><EM>lu</EM></B><DD><P>a matrix containing the LU factors</P>
  825. <DT><B><EM>pvt</EM></B><DD><P>a vector containing the pivot indices</P>
  826. <DT><B><EM>rcond</EM></B><DD><P>the inverse of the condition estimate</P>
  827. </DL>
  828. </P>
  829. <P>Factor utilizes the LAPACK subroutines DGETRF, DGECON or
  830. ZGETRF, ZGECON.</P>
  831. <P><B> if <EM>A</EM> is a symmetric matrix: </B>
  832. <DL>
  833. <DT><B><EM>ldl</EM></B><DD><P>a matrix containing the block diagonal
  834. matrix D, and the multipliers used to obtain L.</P>
  835. <DT><B><EM>pvt</EM></B><DD><P>a vector containing the pivot indices</P>
  836. <DT><B><EM>rcond</EM></B><DD><P>the inverse of the condition estimate</P>
  837. </DL>
  838. </P>
  839. <P>Factor utilizes the LAPACK subroutines DSYTRF, DSYCON or
  840. ZHETRF, ZHECON.</P>
  841. <P>The user can overide factor's choice of solution type with the
  842. optional argument TYPE. </P>
  843. <P>
  844. <BLOCKQUOTE>
  845. TYPE = "g" or "G"       The general solution is used.
  846. </BLOCKQUOTE>
  847. </P>
  848. <P>
  849. <BLOCKQUOTE>
  850. TYPE = "s" or "S"       the symmetric solution is used.
  851. </BLOCKQUOTE>
  852. </P>
  853. <P>Factor returns the results in the above format, so that they
  854. may be conveniently used with backsub for repetitive
  855. solutions. The user-function lu will separate the results from
  856. factor into separate L and U matrices.</P>
  857.  
  858. <DT><B>See Also</B><DD><P>backsub, inv, lu, solve</P>
  859.  
  860. </DL>
  861. </P>
  862.  
  863. <H2><A NAME="ss7.30">7.30 fft </A></H2>
  864.  
  865. <P>
  866. <DL>
  867. <DT><B> Synopsis </B><DD><P>Discrete Fourier Transform.</P>
  868. <DT><B> Syntax </B><DD><P>fft ( <EM>X</EM> )</P>
  869. <P>    fft ( <EM>X</EM>, <EM>N</EM> )</P>
  870. <DT><B> Description </B><DD><P>Fft utilizes the FFTPACK subroutine CFFTF to compute a
  871. discrete forward Fourier transform of the input.</P>
  872. <P>If fft is used with a second argument, <EM>N</EM>, then the
  873. matrix <EM>X</EM> is either padded with zeros, or truncated till
  874. it is of length <EM>N</EM> (if <EM>X</EM> is a vector), or has row
  875. dimension <EM>N</EM> (if it is a matrix).</P>
  876. <P>Subroutine CFFTF computes the forward complex discrete Fourier
  877. transform (the Fourier analysis). equivalently , CFFTF
  878. computes the Fourier coefficients of a complex periodic
  879. sequence.</P>
  880. <P>
  881. <BLOCKQUOTE><CODE>
  882. <PRE>
  883.         for j=1,...,n
  884.         
  885.            c(j)=the sum from k=1,...,n of
  886.         
  887.                  c(k)*exp(-i*(j-1)*(k-1)*2*pi/n)
  888.         
  889.                        where i=sqrt(-1)
  890.         
  891. </PRE>
  892. </CODE></BLOCKQUOTE>
  893. </P>
  894. <P>The argument <EM>X</EM> must be a matrix. If <EM>X</EM> is a row,
  895. or column matrix then a vector fft is performed. If <EM>X</EM>
  896. is a MxN matrix then the <EM>N</EM> columns of <EM>X</EM> are
  897. fft'ed.</P>
  898.  
  899. <DT><B>See Also</B><DD><P>ifft</P>
  900.  
  901. </DL>
  902. </P>
  903.  
  904. <H2><A NAME="ss7.31">7.31 filter</A></H2>
  905.  
  906. <P>
  907. <DL>
  908. <DT><B> Synopsis </B><DD><P>Discrete time recursive filter.</P>
  909. <DT><B> Syntax   </B><DD><P>filter ( <EM>B</EM>, <EM>A</EM>, <EM>X</EM> )</P>
  910. <P>filter ( <EM>B</EM>, <EM>A</EM>, <EM>X</EM>, <EM>Zi</EM> )</P>
  911. <DT><B> Description </B><DD><P>Filter is an implementation of the standard difference
  912. equation:</P>
  913. <P>
  914. <BLOCKQUOTE><CODE>
  915. <PRE>
  916. y[n] = b(1)*x[n] + b(2)*x[n-1] + ... b(nb+1)*x[n-nb]
  917.                  - a(2)*y[n-1] - ... a(na+1)*y[n-na]
  918. </PRE>
  919. </CODE></BLOCKQUOTE>
  920. </P>
  921. <P>The filter is implemented using a method described as a
  922. "Direct Form II Transposed" filter. More for information see
  923. Chapter 6 of "Discrete-Time Signal Processing" by Oppenheim
  924. and Schafer.</P>
  925. <P>The inputs to filter are:
  926. <DL>
  927. <DT><B><EM>B</EM></B><DD><P>The numerator coefficients, or zeros of the
  928. system transfer function. The coefficients are
  929. specified in a vector like:</P>
  930. <P>
  931. <BLOCKQUOTE><CODE>
  932. <PRE>
  933.  [ b(1) , b(2) , ... b(nb) ] 
  934. </PRE>
  935. </CODE></BLOCKQUOTE>
  936. </P>
  937.  
  938. <DT><B><EM>A</EM></B><DD><P>The denominator coefficients, or the poles of
  939. the system transfer function. the coefficients
  940. are specified in a vector like:</P>
  941. <P>
  942. <BLOCKQUOTE><CODE>
  943. <PRE>
  944.  [ a(1) , a(2) , ... a(na) ]  
  945. </PRE>
  946. </CODE></BLOCKQUOTE>
  947. </P>
  948.  
  949. <DT><B><EM>X</EM></B><DD><P>A vector of the filter inputs.</P>
  950.  
  951. <DT><B><EM>Zi</EM></B><DD><P>[Optional] The initial delays of the filter.</P>
  952. </DL>
  953. </P>
  954. <P>The filter outputs are in a list with element names:</P>
  955. <P>
  956. <DL>
  957. <DT><B><EM>y</EM></B><DD><P>The filter output. <EM>y</EM> is a vector of the same
  958. dimension as <EM>X</EM>. </P>
  959.  
  960. <DT><B><EM>zf</EM></B><DD><P>A vector of the final values of the filter delays.</P>
  961. </DL>
  962. </P>
  963. <P>The A(1) coefficient must be non-zero, as the other
  964. coefficients are divided by A(1).</P>
  965. <P>Below is an implementation of filter() in a r-file - it is
  966. provided for informational usage only.</P>
  967.  
  968. <P>
  969. <HR>
  970. <PRE>
  971. #
  972. #  Simplistic version of RLaB's builtin function filter()
  973. #  Y = filter ( b, a, x )
  974. #  Y = filter ( b, a, x, zi )
  975. #
  976.  
  977. rfilter = function ( b , a , x , zi )
  978. {
  979.   local ( b , a , x , zi )
  980.           ntotal = x.nr * x.nc;
  981.   M = b.nr * b.nc;
  982.   N = a.nr * a.nc;
  983.   NN = max ([ M, N ]);
  984.   y = zeros (x.nr, x.nc); 
  985.  
  986.   # Fix up pole and zero vectors.
  987.   # Make them the same length, this makes
  988.   # filter's job much easier.
  989.  
  990.   if (N < NN) { a[NN] = 0; }
  991.   if (M < NN) { b[NN] = 0; }
  992.   
  993.   # Adjust filter coefficients
  994.   if (a[1] == 0) { error ("rfilter: 1st A term must be non-zero"); }
  995.   a[2:NN] = a[2:NN] ./ a[1];
  996.   b = b ./ a[1];
  997.  
  998.   # Create delay vectors and load inital delays.
  999.   # Add an extra term to vi[] to make filter's 
  1000.   # job a little easier. This extra term will
  1001.   # always be zero.
  1002.  
  1003.   v = zeros (NN, 1);
  1004.   vi = zeros (NN+1, 1);
  1005.  
  1006.   if (exist (zi))
  1007.   {
  1008.     vi[1:NN] = zi;   
  1009.   }
  1010.  
  1011.   #
  1012.   # Do the work...
  1013.   #
  1014.  
  1015.   for (n in 1:ntotal)
  1016.   {
  1017.     v[1] = b[1]*x[n] + vi[2];
  1018.     y[n] = v[1];
  1019.     for (k in 2:NN)
  1020.     {
  1021.       v[k] = b[k]*x[n] - a[k]*v[1] + vi[k+1];
  1022.       vi[k] = v[k];
  1023.     }
  1024.   }
  1025.  
  1026.   return << y = y; zf = v >>;
  1027. };
  1028. </PRE>
  1029. <HR>
  1030. </P>
  1031.  
  1032. </DL>
  1033. </P>
  1034.  
  1035. <H2><A NAME="ss7.32">7.32 find </A></H2>
  1036.  
  1037. <P>
  1038. <DL>
  1039. <DT><B> Synopsis </B><DD><P>Find non-zeros.</P>
  1040. <DT><B> Syntax </B><DD><P>find ( <EM>A</EM> ) </P>
  1041. <DT><B> Description </B><DD><P>Find returns a matrix that contains the indices of the
  1042. non-zero elements of the input matrix <EM>A</EM>.</P>
  1043. <P>A common usage for find, is the selection of matrix elements
  1044. that meet certain criteria.</P>
  1045. <P>Example:</P>
  1046. <P>
  1047. <BLOCKQUOTE><CODE>
  1048. <PRE>
  1049. > a = rand(4,4)
  1050.  a =
  1051.  matrix columns 1 thru 4
  1052.     0.647      0.665      0.655      0.299  
  1053.     0.333     0.0847      0.129      0.265  
  1054.    0.0369      0.204       0.91        0.7  
  1055.     0.162      0.167      0.112       0.95  
  1056. > x = a[ find( a < .1 ) ]
  1057.  x =
  1058.  matrix columns 1 thru 2
  1059.    0.0369     0.0847  
  1060. </PRE>
  1061. </CODE></BLOCKQUOTE>
  1062. </P>
  1063. </DL>
  1064. </P>
  1065.  
  1066. <H2><A NAME="ss7.33">7.33 findstr </A></H2>
  1067.  
  1068. <P>
  1069. <DL>
  1070. <DT><B> Synopsis </B><DD><P>Find a string within another string.</P>
  1071. <DT><B> Syntax </B><DD><P>findstr ( <EM>STR1</EM>, <EM>STR2</EM> )</P>
  1072. <DT><B> Description </B><DD><P>Findstr finds the starting point(s) of one string within
  1073. another. The return value is a row vector of offsets into the
  1074. longer string.</P>
  1075. <P>Example:</P>
  1076. <P>
  1077. <BLOCKQUOTE><CODE>
  1078. <PRE>
  1079. > s = "now is the time for all good men to come to the aid of their country"
  1080. now is the time for all good men to come to the aid of their country  
  1081.  
  1082. > findstr(s, "all")
  1083.        21  
  1084. > findstr(s, "aid")
  1085.        49  
  1086. > findstr(s, "the")
  1087.         8         45         56  
  1088. > findstr(s, " ")
  1089.  matrix columns 1 thru 6
  1090.         4          7         11         16         20         24  
  1091.  
  1092.  matrix columns 7 thru 12
  1093.        29         33         36         41         44         48  
  1094.  
  1095.  matrix columns 13 thru 15
  1096.        52         55         61  
  1097. </PRE>
  1098. </CODE></BLOCKQUOTE>
  1099. </P>
  1100.  
  1101. <DT><B>See also</B><DD><P>strsplt</P>
  1102.  
  1103. </DL>
  1104. </P>
  1105.  
  1106. <H2><A NAME="ss7.34">7.34 finite </A></H2>
  1107.  
  1108. <P>
  1109. <DL>
  1110. <DT><B> Synopsis </B><DD><P>Test variable for finite values.</P>
  1111. <DT><B> Syntax </B><DD><P>finite ( <EM>A</EM> ) </P>
  1112. <DT><B> Description </B><DD><P>finite returns a matrix, the same size as the input
  1113. (<EM>A</EM>), consisting of ones and zeros. The elements of the
  1114. return matrix are 1 if the corresponding value of <EM>A</EM> is
  1115. finite, or zero if the corresponding element of <EM>A</EM> is an
  1116. Inf or a NaN.</P>
  1117. <P>Example:
  1118. <BLOCKQUOTE><CODE>
  1119. <PRE>
  1120. > a = [1, inf(), 3; 4, 5, 6; inf(), 8, nan()]
  1121.  a =
  1122.         1        inf          3  
  1123.         4          5          6  
  1124.       inf          8  nan0x80000000  
  1125. > finite (a)
  1126.         1          0          1  
  1127.         1          1          1  
  1128.         0          1          0  
  1129. </PRE>
  1130. </CODE></BLOCKQUOTE>
  1131. </P>
  1132. <DT><B>See Also</B><DD><P>isinf, isnan</P>
  1133.  
  1134. </DL>
  1135. </P>
  1136.  
  1137. <H2><A NAME="ss7.35">7.35 floor </A></H2>
  1138.  
  1139. <P>
  1140. <DL>
  1141. <DT><B> Synopsis </B><DD><P>Largest integral value not greater than <EM>X</EM></P>
  1142. <DT><B> Syntax </B><DD><P>floor ( <EM>X</EM> )</P>
  1143. <DT><B> Description </B><DD><P>Floor returns the largest integer not greater than the
  1144. argument. If the argument is a MATRIX then the floor operation
  1145. is performed on an element-by-element basis.</P>
  1146.  
  1147. <DT><B>See Also</B><DD><P>ceil, int</P>
  1148.  
  1149. </DL>
  1150. </P>
  1151.  
  1152. <H2><A NAME="ss7.36">7.36 format </A></H2>
  1153.  
  1154. <P>
  1155. <DL>
  1156. <DT><B> Synopsis </B><DD><P>Set the printing format.</P>
  1157. <DT><B> Syntax </B><DD><P>format ( ) </P>
  1158. <P>    format ( <EM>PRECISION</EM> )</P>
  1159. <P>    format ( <EM>WIDTH</EM>, <EM>PRECISION</EM> )</P>
  1160. <P>    format ( [ <EM>WIDTH</EM>, <EM>PRECISION</EM> ] )</P>
  1161. <DT><B> Description </B><DD><P>Format sets the output print format for all numeric output. If
  1162. no arguments are supplied, then the output print formats are
  1163. reset to the default values.</P>
  1164. <P>
  1165. <DL>
  1166.  
  1167. <DT><B><EM>PRECISION</EM></B><DD><P>represents the precision with
  1168. which numbers will be printed. For instance, if
  1169. <EM>PRECISION</EM> has a value of 4, then 4 significant digits
  1170. will be printed for numeric values.</P>
  1171.  
  1172. <DT><B><EM>WIDTH</EM></B><DD><P>represents the minimum field width of
  1173. the formatted output.</P>
  1174.  
  1175. </DL>
  1176. </P>
  1177. <P>Format returns a 2-element matrix contains the previous width
  1178. and precision values. Subsequently, this matrix can be used to
  1179. reset format.</P>
  1180. <P>Example:</P>
  1181. <P>
  1182. <BLOCKQUOTE><CODE>
  1183. <PRE>
  1184. > 123456789.123456789
  1185.  1.235e+08
  1186. > format(10);
  1187. > 123456789.123456789
  1188. 123456789.1
  1189. > format();
  1190. > a = rand(3,3)
  1191.  a =
  1192.  matrix columns 1 thru 3
  1193.          1      0.3331      0.6646  
  1194.     0.9745     0.03694     0.08467  
  1195.     0.6475      0.1617      0.2041  
  1196. > format(10);
  1197. > a
  1198.  a =
  1199.  matrix columns 1 thru 3
  1200. 0.9999996424  0.3330855668  0.6646450162  
  1201. 0.9745196104  0.03694454208  0.08467286825  
  1202. 0.6474838853  0.1617118716  0.2041363865  
  1203. > format(15,10);
  1204. > a
  1205.  a =
  1206.  matrix columns 1 thru 3
  1207.    0.9999996424     0.3330855668     0.6646450162  
  1208.    0.9745196104    0.03694454208    0.08467286825  
  1209.    0.6474838853     0.1617118716     0.2041363865  
  1210. </PRE>
  1211. </CODE></BLOCKQUOTE>
  1212. </P>
  1213.  
  1214. </DL>
  1215. </P>
  1216.  
  1217. <H2><A NAME="ss7.37">7.37 fprintf </A></H2>
  1218.  
  1219. <P>
  1220. <DL>
  1221. <DT><B> Synopsis </B><DD><P>Formatted printing to a file.</P>
  1222. <DT><B> Syntax </B><DD><P>fprintf ( <EM>filestring</EM>, <EM>formatstring</EM>, <EM>VARi</EM> ... )</P>
  1223. <DT><B> Description </B><DD><P>The RLaB fprintf is a limited feature version of the
  1224. C-language fprintf. The features are limited because RLaB
  1225. does not support all of the data types the C-language does.</P>
  1226. <P>
  1227. <DL>
  1228.  
  1229. <DT><B><EM>filestring</EM></B><DD><P>The 1st string argument
  1230. determines the file to which the output is sent. If the
  1231. filename starts with a <CODE>|</CODE> then a pipe is opened to the
  1232. process following the <CODE>|</CODE> and the output is written to
  1233. the pipe. For example:</P>
  1234. <P>
  1235. <BLOCKQUOTE><CODE>
  1236. <PRE>
  1237. > fprintf("|gnuplot"; "set term X11\n plot sin(x)\n");
  1238. </PRE>
  1239. </CODE></BLOCKQUOTE>
  1240. </P>
  1241. <P>will create the sub-process gnuplot, and pipe the command
  1242. string to it.</P>
  1243.  
  1244. <DT><B><EM>formatstring</EM></B><DD><P>A valid fprintf format string.</P>
  1245.  
  1246. <DT><B><EM>VARi</EM></B><DD><P>Are any number of constants or
  1247. variables that match the format string. fprintf cannot print
  1248. out vector, matrix, or  list objects as a whole. Valid print
  1249. objects are strings,    constants, and scalars. </P>
  1250.  
  1251. </DL>
  1252. </P>
  1253. <P>Example:
  1254. <BLOCKQUOTE><CODE>
  1255. <PRE>
  1256. > for (i in 1:a.n) { fprintf("stdout", "element %i: %20.10g\n", i, a[i]); }
  1257. element 1:          1.414213562
  1258. element 2:          4.242640687
  1259. element 3:          2.828427125
  1260. element 4:          5.656854249
  1261. </PRE>
  1262. </CODE></BLOCKQUOTE>
  1263. </P>
  1264.  
  1265. <DT><B>See Also</B><DD><P>printf, sprintf, write, read</P>
  1266.  
  1267. </DL>
  1268. </P>
  1269.  
  1270. <H2><A NAME="ss7.38">7.38 fread </A></H2>
  1271.  
  1272. <P>
  1273. <DL>
  1274. <DT><B> Synopsis </B><DD><P>Binary stream input.</P>
  1275. <DT><B> Syntax </B><DD><P>fread ( <EM>FILENAME</EM>, <EM>NITEMS</EM>, <EM>TYPE</EM>, <EM>SWAPB</EM> )</P>
  1276. <DT><B> Description </B><DD><P>fread reads <EM>NITEMS</EM> of type <EM>TYPE</EM> from
  1277. <EM>FILENAME</EM> (a string) and returns the result in a numeric
  1278. matrix.</P>
  1279. <P>Allowable arguments are:
  1280. <DL>
  1281.  
  1282. <DT><B><EM>NITEMS</EM></B><DD><P>Number of objects of type <EM>TYPE</EM>
  1283. to read from <EM>FILENAME</EM>. If <EM>NITEMS</EM> is inf(), then
  1284. fread will read from <EM>FILENAME</EM> until end-of-file is
  1285. reached. </P>
  1286.  
  1287. <DT><B><EM>TYPE</EM></B><DD><P>
  1288. <BLOCKQUOTE>
  1289. "char"
  1290. </BLOCKQUOTE>
  1291. </P>
  1292. <P>
  1293. <BLOCKQUOTE>
  1294. "unsigned char"
  1295. </BLOCKQUOTE>
  1296. </P>
  1297. <P>
  1298. <BLOCKQUOTE>
  1299. "short int"
  1300. </BLOCKQUOTE>
  1301. </P>
  1302. <P>
  1303. <BLOCKQUOTE>
  1304. "unsigned int"
  1305. </BLOCKQUOTE>
  1306. </P>
  1307. <P>
  1308. <BLOCKQUOTE>
  1309. "int"
  1310. </BLOCKQUOTE>
  1311. </P>
  1312. <P>
  1313. <BLOCKQUOTE>
  1314. "float"
  1315. </BLOCKQUOTE>
  1316. </P>
  1317. <P>
  1318. <BLOCKQUOTE>
  1319. "double"
  1320. </BLOCKQUOTE>
  1321. </P>
  1322.  
  1323. <DT><B><EM>SWAPB</EM></B><DD><P>
  1324. <BLOCKQUOTE>
  1325. 0       Do not swap bytes in a word (default).
  1326. </BLOCKQUOTE>
  1327. </P>
  1328. <P>
  1329. <BLOCKQUOTE>
  1330. 1       Do swap the bytes in each word.
  1331. </BLOCKQUOTE>
  1332. </P>
  1333.  
  1334. </DL>
  1335. </P>
  1336.  
  1337. <DT><B>See Also</B><DD><P>FILES, fseek, fwrite, close, open, write</P>
  1338.  
  1339. </DL>
  1340. </P>
  1341.  
  1342. <H2><A NAME="ss7.39">7.39 frexp </A></H2>
  1343.  
  1344. <P>
  1345. <DL>
  1346. <DT><B> Synopsis </B><DD><P>Convert floating-point number to fractional and
  1347. integral components </P>
  1348. <DT><B> Syntax </B><DD><P>frexp ( <EM>A</EM> )</P>
  1349. <DT><B> Description </B><DD><P>Frexp returns a list with elements <EM>f</EM> and <EM>e</EM>
  1350. Frexp splits <EM>A</EM> into a normalized fraction in the interval:</P>
  1351. <P>
  1352. <BLOCKQUOTE><CODE>
  1353. <PRE>
  1354.                 0.5 <= abs(f) <= 1
  1355.         
  1356. </PRE>
  1357. </CODE></BLOCKQUOTE>
  1358. </P>
  1359. <P>which is returned in <EM>f</EM>, and a power of 2, which is returned
  1360. in <EM>e</EM>. If <EM>A</EM> is zero, then both <EM>e</EM> and
  1361. <EM>f</EM> are zero.</P>
  1362. <P>Frexp operates on REAL matrices of any dimension.</P>
  1363.  
  1364. <DT><B>See Also</B><DD><P>log, log10, log2, exp, mod</P>
  1365.  
  1366. </DL>
  1367. </P>
  1368.  
  1369. <H2><A NAME="ss7.40">7.40 fseek </A></H2>
  1370.  
  1371. <P>
  1372. <DL>
  1373. <DT><B> Synopsis </B><DD><P>Reposition a stream.</P>
  1374. <DT><B> Syntax </B><DD><P>fseek ( <EM>FILENAME</EM>, <EM>OFFSET</EM> )</P>
  1375. <P>    fseek ( <EM>FILENAME</EM>, <EM>OFFSET</EM>, <EM>OFFSET</EM> )</P>
  1376. <DT><B> Description </B><DD><P>fseek sets the current position in <EM>FILENAME</EM>. a
  1377. subsequent read will access data beginning at the new
  1378. position. fseek is an interface to the C library function of
  1379. the same name. <EM>OFFSET</EM> is specified in bytes.</P>
  1380. <P>
  1381. <DL>
  1382. <DT><B><EM>ORIGIN</EM></B><DD><P>
  1383. <BLOCKQUOTE>
  1384. "SEEK_SET"      beginning of file (default)
  1385. </BLOCKQUOTE>
  1386. </P>
  1387. <P>
  1388. <BLOCKQUOTE>
  1389. "SEEK_CUR"      current position
  1390. </BLOCKQUOTE>
  1391. </P>
  1392. <P>
  1393. <BLOCKQUOTE>
  1394. "SEEK_END"      end of file
  1395. </BLOCKQUOTE>
  1396. </P>
  1397.  
  1398. </DL>
  1399. </P>
  1400.  
  1401. <DT><B>See Also</B><DD><P>FILES, fread, open, close</P>
  1402.  
  1403. </DL>
  1404. </P>
  1405.  
  1406. <H2><A NAME="ss7.41">7.41 full </A></H2>
  1407.  
  1408. <P>
  1409. <DL>
  1410. <DT><B> Synopsis </B><DD><P>Convert sparse storage to full (dense) storage. </P>
  1411. <DT><B> Syntax </B><DD><P>full( <EM>A</EM> ) </P>
  1412. <DT><B> Description </B><DD><P>full converts its argument from the sparse storage format
  1413. to the full, or dense, storage format.</P>
  1414. <P>Example:</P>
  1415. <P>
  1416. <BLOCKQUOTE><CODE>
  1417. <PRE>
  1418. > d = [1, 1, 10;
  1419. >      2, 4, 20;
  1420. >      3, 1, 12;
  1421. >      5, 2, 13;
  1422. >      1, 4, 3];
  1423. > s = spconvert(d)
  1424.  (1, 1)                10
  1425.  (1, 4)                 3
  1426.  (2, 4)                20
  1427.  (3, 1)                12
  1428.  (5, 2)                13
  1429. > f = full(s)
  1430.        10          0          0          3  
  1431.         0          0          0         20  
  1432.        12          0          0          0  
  1433.         0          0          0          0  
  1434.         0         13          0          0  
  1435. </PRE>
  1436. </CODE></BLOCKQUOTE>
  1437. </P>
  1438.  
  1439. <DT><B>See Also</B><DD><P>sparse, spconvert</P>
  1440. </DL>
  1441. </P>
  1442.  
  1443. <H2><A NAME="ss7.42">7.42 fwrite</A></H2>
  1444.  
  1445. <P>
  1446. <DL>
  1447. <DT><B> Synopsis </B><DD><P>Binary stream output.</P>
  1448. <DT><B> Syntax </B><DD><P>fwrite ( <EM>FILENAME</EM>, <EM>TYPE</EM>, <EM>DATA</EM> )</P>
  1449. <DT><B> Description </B><DD><P>fwrite writes <EM>DATA</EM> to the file identified by
  1450. <EM>FILENAME</EM>. <EM>DATA</EM> is cast, or converted to the data
  1451. type identified in <EM>TYPE</EM>. fwrite roughly mimincs the C
  1452. programming language's fwrite library function.</P>
  1453. <P><EM>DATA</EM> can either be a dense numeric matrix, or a string
  1454. matrix. The size of the matrix does not need to be specified
  1455. because the entire matrix is written.</P>
  1456. <P>If <EM>DATA</EM> is a string matrix, then the first character of
  1457. each element is written to <EM>FILENAME</EM>, after being
  1458. coerced to type <EM>TYPE</EM>. </P>
  1459. <P>Allowable arguments are:
  1460. <DL>
  1461.  
  1462. <DT><B><EM>TYPE</EM></B><DD><P>
  1463. <BLOCKQUOTE>
  1464. "char"
  1465. </BLOCKQUOTE>
  1466. </P>
  1467. <P>
  1468. <BLOCKQUOTE>
  1469. "unsigned char"
  1470. </BLOCKQUOTE>
  1471. </P>
  1472. <P>
  1473. <BLOCKQUOTE>
  1474. "short int"
  1475. </BLOCKQUOTE>
  1476. </P>
  1477. <P>
  1478. <BLOCKQUOTE>
  1479. "unsigned int"
  1480. </BLOCKQUOTE>
  1481. </P>
  1482. <P>
  1483. <BLOCKQUOTE>
  1484. "int"
  1485. </BLOCKQUOTE>
  1486. </P>
  1487. <P>
  1488. <BLOCKQUOTE>
  1489. "float"
  1490. </BLOCKQUOTE>
  1491. </P>
  1492. <P>
  1493. <BLOCKQUOTE>
  1494. "double"
  1495. </BLOCKQUOTE>
  1496. </P>
  1497.  
  1498. </DL>
  1499. </P>
  1500.  
  1501. <DT><B>See Also</B><DD><P>FILES, fread, fseek, close, open, write</P>
  1502.  
  1503. </DL>
  1504. </P>
  1505.  
  1506.  
  1507.  
  1508. <H2><A NAME="ss7.43">7.43 getenv </A></H2>
  1509.  
  1510. <P>
  1511. <DL>
  1512. <DT><B> Synopsis </B><DD><P>Get an environment variable</P>
  1513. <DT><B> Syntax </B><DD><P>getenv ( <EM>NAME</EM> )</P>
  1514. <DT><B> Description </B><DD><P>Getenv searches the current environment for a variable with
  1515. name <EM>NAME</EM>. The value of the environment variable is
  1516. returned as a string.</P>
  1517. <P>Exactly how getenv behaves is depends upon the underlying
  1518. operating system implementation. On UNIX system getenv will
  1519. return a NULL string if the environment variable does not
  1520. exist. </P>
  1521.  
  1522. <DT><B>See Also</B><DD><P>putenv</P>
  1523.  
  1524. </DL>
  1525. </P>
  1526.  
  1527. <H2><A NAME="ss7.44">7.44 getline </A></H2>
  1528.  
  1529. <P>
  1530. <DL>
  1531. <DT><B> Synopsis </B><DD><P>Get a line of input.</P>
  1532. <DT><B> Syntax </B><DD><P>getline ( <EM>FN</EM> ) </P>
  1533. <P>    getline ( <EM>FN</EM>, <EM>LL</EM> )</P>
  1534. <DT><B> Description </B><DD><P>Getline returns an N-element list which contains all of the
  1535. tokens from a line in the file described by <EM>FN</EM>. The
  1536. tokens are delimited by whitespace. Numbers are installed in
  1537. the list as numeric scalars, everything else is installed as
  1538. scalar strings.</P>
  1539. <P>The list elements have numeric indices, and are numbered from
  1540. 1 to N. The 1st element containing the 1st token on the line,
  1541. and the Nth element containing the last token on the line. The
  1542. newline is not returned as a token.</P>
  1543. <P>Getline will also recognize everything enclosed within a pair
  1544. of <CODE>"</CODE> as a string, including escape characters.</P>
  1545. <P>Getline will always return a list-object. When an empty-line
  1546. has been read, getline returns an empty list. Getline will
  1547. terminate on an End-Of-File (EOF).</P>
  1548. <P>The filename can be a string that specifies a sub-process (see
  1549. <CODE>help FILES</CODE>), in which case getline will run the
  1550. sub-process, and read from the process's standard output.</P>
  1551. <P>The second, and optional argument,<EM> LL</EM>, forces getline
  1552. to return the entire line (including the newline) as a string,
  1553. without any parsing. If <EM>LL</EM> is <= 0, then getline will
  1554. read lines as long as 512 characters. If <EM>LL</EM> > 0, then
  1555. getline will read lines as long as <EM>LL</EM> characters. The
  1556. return value is a single string, not a list, when <EM>LL</EM> is
  1557. used. If getline encounters and EOF, while LL is being used, a
  1558. numeric value of 0 is returned.</P>
  1559. <P>Examples:</P>
  1560. <P>To get input interactively:</P>
  1561. <P>
  1562. <BLOCKQUOTE><CODE>
  1563. <PRE>
  1564. > printf( "Enter a string and a number: " ); x = getline( "stdin" );
  1565. Enter a string and a number: test-string 1.234e5
  1566. > show(x)
  1567.    name:   x     
  1568.    class:  list  
  1569.        n:  2     
  1570. > x.[1]
  1571. test-string
  1572. > x.[2]
  1573.  2 =
  1574.  1.23e+05
  1575. </PRE>
  1576. </CODE></BLOCKQUOTE>
  1577. </P>
  1578. <P>Given a file named `test', which contains the following lines:</P>
  1579. <P>
  1580. <BLOCKQUOTE><CODE>
  1581. <PRE>
  1582. jcool  259  4 1075  822 vt01     S   Dec 29  9:32 X :0 -p 1 -s 5 
  1583. jcool  256  0   21    0 console  S   Dec 29  0:00 startx 
  1584. jcool  261  0  338   88 console  S   Dec 29  0:16 twm 
  1585. jcool  288  8  635  333 ?        S   Dec 29  2:00 emacs 
  1586. jcool  287  0  408   65 console  S   Dec 29  0:01 xclock 
  1587. </PRE>
  1588. </CODE></BLOCKQUOTE>
  1589. </P>
  1590. <P>
  1591. <BLOCKQUOTE><CODE>
  1592. <PRE>
  1593. > tmp = getline( "test" );
  1594. </PRE>
  1595. </CODE></BLOCKQUOTE>
  1596. </P>
  1597. <P>would produce a list variable named `tmp' with 16 elements:
  1598. tmp.<F>1</F> would be the string "jcool" and tmp.<F>16</F> would be the
  1599. number 5.  The next call to getline() would read the second
  1600. line in the file, and create a new list containing those
  1601. elements.</P>
  1602. <P>The above could also have been done with:</P>
  1603. <P>
  1604. <BLOCKQUOTE><CODE>
  1605. <PRE>
  1606. > tmp = getline( "|ps -aux | grep jcool" );
  1607. </PRE>
  1608. </CODE></BLOCKQUOTE>
  1609. </P>
  1610. <P>Which would open a readable pipe to the "ps -aux | grep jcool"
  1611. command and grab a line at a time from the process.</P>
  1612. <P>To read the entire contents of a file:</P>
  1613. <P>
  1614. <BLOCKQUOTE><CODE>
  1615. <PRE>
  1616. if (length (ans = getline("stdin"))) 
  1617.   // do something with ans
  1618. else
  1619.   // finish up
  1620. }
  1621. </PRE>
  1622. </CODE></BLOCKQUOTE>
  1623. </P>
  1624. <P>Since getline returns an empty list when there is no input, we
  1625. can tell when to terminate the input loop by checking the
  1626. length of the returned list.</P>
  1627. <P>Using the optional second arguemnt to getline we can get
  1628. old-style Fortran formattted output. For example, we have a
  1629. file filled with:</P>
  1630. <P>
  1631. <BLOCKQUOTE><CODE>
  1632. <PRE>
  1633. 0.1285186E+000.1463163E+000.0000000E+000.0000000E+000.0000000E+000.0000000E+00
  1634. 0.0000000E+000.0000000E+000.0000000E+000.0000000E+000.7322469E-010.5245288E-01
  1635. 0.0000000E+00-.9399651E-010.2397120E-01-.6551484E-010.2616772E+020.5796479E-01
  1636. 0.0000000E+000.2500000E+000.7788281E-010.2121489E-010.0000000E+00-.1345507E+00
  1637. 0.1516225E-01-.1284981E+000.1136876E+020.3010250E-010.0000000E+00-.2500000E+00
  1638. </PRE>
  1639. </CODE></BLOCKQUOTE>
  1640. </P>
  1641. <P>we can do:</P>
  1642. <P>
  1643. <BLOCKQUOTE><CODE>
  1644. <PRE>
  1645. > lv = strtod (getline (FN, 13));
  1646. </PRE>
  1647. </CODE></BLOCKQUOTE>
  1648. </P>
  1649. <P>and get a vector with the numeric values for each line.</P>
  1650.  
  1651. <DT><B>See Also</B><DD><P>strsplt</P>
  1652.  
  1653. </DL>
  1654. </P>
  1655.  
  1656. <H2><A NAME="ss7.45">7.45 help </A></H2>
  1657.  
  1658. <P>
  1659. <DL>
  1660. <DT><B> Synopsis </B><DD><P>Online Help</P>
  1661. <DT><B> Syntax </B><DD><P>help </P>
  1662. <P>    help <EM>NAME</EM></P>
  1663. <DT><B> Description </B><DD><P>
  1664. <DL>
  1665.  
  1666. <DT><B>help</B><DD><P>Prints a list of available help files. Help
  1667. first prints out the help files in the default help
  1668. file directory. Next, the directories identified in
  1669. the environment variable <CODE>RLAB_SEARCH_PATH</CODE> are
  1670. searched for files ending in `.r' -- rfiles. A list of
  1671. each directory's rfiles is printed on the standard
  1672. output.</P>
  1673.  
  1674. <DT><B>help <EM>NAME</EM></B><DD><P>Prints out the help file
  1675. identified by <EM>NAME</EM>. If <EM>NAME</EM> matches a
  1676. file in the default help directory, that file is paged
  1677. to the standard output. If no match is found, the
  1678. directories identified in the environment variable
  1679. <CODE>RLAB_SEARCH_PATH</CODE> are searched for matches. The
  1680. first match is paged to the standard output. The rfile
  1681. extension (`.r') is not considered when checking for
  1682. matches.</P>
  1683.  
  1684. </DL>
  1685. </P>
  1686. <P>If the user's environment does not contain
  1687. <CODE>RLAB_SEARCH_PATH</CODE>, then the default search-path is
  1688. used. The default is set at compile time. Normally the default
  1689. is ".", the current working directory.</P>
  1690. <P>Help is a command, not an expression or statement. Therefore,
  1691. it must be issued on a line by itself, and cannot occur in the
  1692. midst of another statement or expression.</P>
  1693.  
  1694. <DT><B>See Also</B><DD><P>rfile </P>
  1695.  
  1696. </DL>
  1697. </P>
  1698.  
  1699. <H2><A NAME="ss7.46">7.46 hess </A></H2>
  1700.  
  1701. <P>
  1702. <DL>
  1703. <DT><B> Synopsis </B><DD><P>Find the Hessenberg form of a matrix.</P>
  1704. <DT><B> Syntax </B><DD><P>hess( <EM>A</EM> )</P>
  1705. <DT><B> Description </B><DD><P>Hess finds the Hessenberg from of a matrix. Hess takes a
  1706. single matrix, <EM>A</EM>, as input, and returns a list with two
  1707. elements, <EM>h</EM>, and <EM>p</EM>.</P>
  1708. <P>
  1709. <BLOCKQUOTE>
  1710. A = p * h * p'          where A is the input
  1711. </BLOCKQUOTE>
  1712. </P>
  1713. <P>Hess uses the LAPACK subroutines DGEHRD, DORGHR, and ZGEHRD,
  1714. ZUNGHR.</P>
  1715.  
  1716. </DL>
  1717. </P>
  1718.  
  1719. <H2><A NAME="ss7.47">7.47 ifft </A></H2>
  1720.  
  1721. <P>
  1722. <DL>
  1723. <DT><B> Synopsis </B><DD><P>Inverse Discrete Fourier Transform</P>
  1724. <DT><B> Syntax </B><DD><P>ifft ( <EM>X</EM> )</P>
  1725. <P>    ifft ( <EM>X</EM>, <EM>N</EM> )</P>
  1726. <DT><B> Description </B><DD><P>Ifft utilizes the FFTPACK subroutine CFFTB to compute a
  1727. discrete Fourier transform of the input. The output is scaled
  1728. by 1/N, so that a call to fft() followed by a call to ifft()
  1729. will reproduce the original input. </P>
  1730. <P>If ifft is used with a second argument, <EM>N</EM>, then the
  1731. matrix <EM>X</EM> is either padded with zeros, or truncated till
  1732. it is of length <EM>N</EM> (if <EM>X</EM> is a vector), or has row
  1733. dimension <EM>N</EM> (if it is a matrix).</P>
  1734. <P>Subroutine CFFTB computes the backward complex discrete
  1735. Fourier transform (the Fourier synthesis). equivalently, CFFTB
  1736. computes a complex periodic sequence from its Fourier
  1737. coefficients.</P>
  1738. <P>
  1739. <BLOCKQUOTE><CODE>
  1740. <PRE>
  1741.         for j=1,...,n
  1742.  
  1743.            c(j)=the sum from k=1,...,n of
  1744.  
  1745.                  c(k)*exp(i*(j-1)*(k-1)*2*pi/n)
  1746.  
  1747.                          where i=sqrt(-1)
  1748.         
  1749. </PRE>
  1750. </CODE></BLOCKQUOTE>
  1751. </P>
  1752. <P>The argument <EM>X</EM> must be a matrix. If <EM>X</EM> is a row,
  1753. or column matrix then a vector ifft is performed. If <EM>X</EM>
  1754. is a MxN matrix then the N columns of <EM>X</EM> are ifft'ed.</P>
  1755.  
  1756. <DT><B>See Also</B><DD><P>fft</P>
  1757.  
  1758. </DL>
  1759. </P>
  1760.  
  1761. <H2><A NAME="ss7.48">7.48 imag </A></H2>
  1762.  
  1763. <P>
  1764. <DL>
  1765. <DT><B> Synopsis </B><DD><P>Imaginary part</P>
  1766. <DT><B> Syntax </B><DD><P>imag ( <EM>A</EM> )</P>
  1767. <DT><B> Description </B><DD><P>Imag returns the imaginary part of an <EM>A</EM>.</P>
  1768. <P>Example:
  1769. <BLOCKQUOTE><CODE>
  1770. <PRE>
  1771. > z = pi + 3*pi*1j
  1772.             3.14 + 9.42i
  1773. > imag(z)
  1774.      9.42  
  1775. </PRE>
  1776. </CODE></BLOCKQUOTE>
  1777. </P>
  1778.  
  1779. <DT><B>See Also</B><DD><P>conj, real</P>
  1780.  
  1781. </DL>
  1782. </P>
  1783.  
  1784. <H2><A NAME="ss7.49">7.49 inf </A></H2>
  1785.  
  1786. <P>
  1787. <DL>
  1788. <DT><B> Synopsis </B><DD><P>Create a variable with value of infinity.</P>
  1789. <DT><B> Syntax </B><DD><P>inf ( )</P>
  1790. <DT><B> Description </B><DD><P>Inf returns a scalar whose value is infinity, according to
  1791. IEEE-754. Unlike NaN, inf == inf should return TRUE (1).</P>
  1792.  
  1793. <DT><B>See Also</B><DD><P>nan</P>
  1794.  
  1795. </DL>
  1796. </P>
  1797.  
  1798. <H2><A NAME="ss7.50">7.50 int </A></H2>
  1799.  
  1800. <P>
  1801. <DL>
  1802. <DT><B> Synopsis </B><DD><P>Return an integer.</P>
  1803. <DT><B> Syntax </B><DD><P>int ( <EM>A</EM> )</P>
  1804. <DT><B> Description </B><DD><P>Int returns its argument after it has been "cast" to an
  1805. integer. If the argument is a MATRIX then the int operation is
  1806. performed on an element-by-element basis.</P>
  1807. <P>int has the effect of truncating the input, for example:</P>
  1808. <P>
  1809. <BLOCKQUOTE><CODE>
  1810. <PRE>
  1811. > int(1.1)
  1812.            1
  1813. > int(1.5)
  1814.            1
  1815. > int(1.999)
  1816.            1
  1817. </PRE>
  1818. </CODE></BLOCKQUOTE>
  1819. </P>
  1820.  
  1821. <DT><B>See Also</B><DD><P>ceil, floor</P>
  1822.  
  1823. </DL>
  1824. </P>
  1825.  
  1826. <H2><A NAME="ss7.51">7.51 isinf </A></H2>
  1827.  
  1828. <P>
  1829. <DL>
  1830. <DT><B> Synopsis </B><DD><P>Test for values of infinity.</P>
  1831. <DT><B> Syntax </B><DD><P>isinf ( <EM>A</EM> )</P>
  1832. <DT><B> Description </B><DD><P>isinf returns TRUE (1) if <EM>A</EM> is Infinity (according to
  1833. IEEE-754). If <EM>A</EM> is a vector or a matrix the test is
  1834. performed element-by-element, and a matrix the same size as
  1835. <EM>A</EM> is returned.</P>
  1836. <P>Infs can usually be created by attempting to divide by zero,
  1837. or using the builtin inf function.</P>
  1838. <P>Example:
  1839. <BLOCKQUOTE><CODE>
  1840. <PRE>
  1841. > a = [1, 2, 3; 4, 5, inf(); 7, 8, 9]
  1842.  a =
  1843.         1          2          3  
  1844.         4          5        inf  
  1845.         7          8          9  
  1846. > isinf (a)
  1847.         0          0          0  
  1848.         0          0          1  
  1849.         0          0          0  
  1850. </PRE>
  1851. </CODE></BLOCKQUOTE>
  1852. </P>
  1853.  
  1854.  
  1855. <DT><B>See Also</B><DD><P>isnan, finite</P>
  1856.  
  1857. </DL>
  1858. </P>
  1859.  
  1860. <H2><A NAME="ss7.52">7.52 isnan </A></H2>
  1861.  
  1862. <P>
  1863. <DL>
  1864. <DT><B> Synopsis </B><DD><P>Test for NaN values.</P>
  1865. <DT><B> Syntax </B><DD><P>isnan ( <EM>A</EM> )</P>
  1866. <DT><B> Description </B><DD><P>isnan returns TRUE (1) if <EM>A</EM> is a NaN (Not A Number). If
  1867. <EM>A</EM> is a vector or a matrix the test is performed
  1868. element-by-element, and a matrix the same size as <EM>A</EM> is
  1869. returned.</P>
  1870. <P>NaNs can be create by the 0/0 operation on most computers.</P>
  1871. <P>Example:
  1872. <BLOCKQUOTE><CODE>
  1873. <PRE>
  1874. > a = [1, 2, 3; 4, 5, nan(); 7, 8, 9]
  1875.  a =
  1876.         1          2          3  
  1877.         4          5  nan0x80000000  
  1878.         7          8          9  
  1879. > isnan (a)
  1880.         0          0          0  
  1881.         0          0          1  
  1882.         0          0          0  
  1883. </PRE>
  1884. </CODE></BLOCKQUOTE>
  1885. </P>
  1886.  
  1887. <DT><B>See Also</B><DD><P>inf, isinf, finite, nan</P>
  1888.  
  1889. </DL>
  1890. </P>
  1891.  
  1892. <H2><A NAME="ss7.53">7.53 issymm </A></H2>
  1893.  
  1894. <P>
  1895. <DL>
  1896. <DT><B> Synopsis </B><DD><P>Test matrix for symmetry</P>
  1897. <DT><B> Syntax </B><DD><P>issymm ( <EM>A</EM> )</P>
  1898. <DT><B> Description </B><DD><P>Issymm returns TRUE (1) if the argument <EM>A</EM> is a
  1899. symmetric (or Hermitian) matrix, and FALSE (0) if <EM>A</EM> is
  1900. not symmetric (Hermitian).</P>
  1901.  
  1902. </DL>
  1903. </P>
  1904.  
  1905. <H2><A NAME="ss7.54">7.54 length </A></H2>
  1906.  
  1907. <P>
  1908. <DL>
  1909. <DT><B> Synopsis </B><DD><P>Return the length of an object.</P>
  1910. <DT><B> Syntax </B><DD><P>length ( <EM>A</EM> ) </P>
  1911. <DT><B> Description </B><DD><P>The length function returns the length of vector <EM>A</EM>. It
  1912. is equivalent to <CODE>max (size (A))</CODE>, when <EM>A</EM> is
  1913. numeric.</P>
  1914. <P>To summarize:</P>
  1915. <P>
  1916. <DL>
  1917.  
  1918. <DT><B>NUMERIC:</B><DD><P><CODE>max (size (A))</CODE></P>
  1919.  
  1920. <DT><B>STRING:</B><DD><P>number of characters in a string.</P>
  1921.  
  1922. <DT><B>LIST:</B><DD><P>number of elements in list.</P>
  1923.  
  1924. </DL>
  1925. </P>
  1926.  
  1927. <DT><B>See Also</B><DD><P>show, size</P>
  1928.  
  1929. </DL>
  1930. </P>
  1931.  
  1932. <H2><A NAME="ss7.55">7.55 load </A></H2>
  1933.  
  1934. <P>
  1935. <DL>
  1936. <DT><B> Synopsis </B><DD><P>Load / execute the instructions in a file.</P>
  1937. <DT><B> Syntax </B><DD><P>load( <EM>filename</EM> ) </P>
  1938. <DT><B> Description </B><DD><P>Load opens the file named <EM>filename</EM> and reads its
  1939. contents as though a user were typing the contents at the
  1940. command line. Thus a user can use load to enter data,
  1941. user-functions, or execute repetitive commands saved in a
  1942. file. there is no limit to the number of functions, or regular
  1943. statements that can exist in a file called by load.</P>
  1944. <P>Immediately after the the input is read, load closes the
  1945. file, so that subsequent calls to load will re-open the
  1946. file.</P>
  1947. <P>Load requires that a complete file specification be provided.
  1948. If the file is in the present working directory, then only the
  1949. filename is necessary otherwise, a complete path is required.</P>
  1950. <P>In most cases the rfile command is simpler to use.</P>
  1951. <P>Example:
  1952. <BLOCKQUOTE><CODE>
  1953. <PRE>
  1954. // load the roots() function into memory
  1955. > load( "roots.r" )
  1956. </PRE>
  1957. </CODE></BLOCKQUOTE>
  1958. </P>
  1959.  
  1960. <DT><B>See Also</B><DD><P>rfile</P>
  1961.  
  1962. </DL>
  1963. </P>
  1964.  
  1965. <H2><A NAME="ss7.56">7.56 log </A></H2>
  1966.  
  1967. <P>
  1968. <DL>
  1969. <DT><B> Synopsis </B><DD><P>Logarithmic function.</P>
  1970. <DT><B> Syntax </B><DD><P>log ( <EM>A</EM> ) </P>
  1971. <DT><B> Description </B><DD><P>Log returns the natural logarithm of it's argument. If the
  1972. argument is a VECTOR or MATRIX an element-by-element log
  1973. operation is performed.</P>
  1974.  
  1975. </DL>
  1976. </P>
  1977.  
  1978. <H2><A NAME="ss7.57">7.57 log10 </A></H2>
  1979.  
  1980. <P>
  1981. <DL>
  1982. <DT><B> Synopsis </B><DD><P>Base-10 logarithm.</P>
  1983. <DT><B> Syntax </B><DD><P>log10 ( <EM>A</EM> )</P>
  1984. <DT><B> Description </B><DD><P>Log10 returns the base-10 logarithm of it's argument. If the
  1985. argument is a MATRIX, an element-by-element log10 operation is
  1986. performed.</P>
  1987. <P>log10 is not implemented yet for COMPLEX data.</P>
  1988.  
  1989. </DL>
  1990. </P>
  1991.  
  1992. <H2><A NAME="ss7.58">7.58 logb </A></H2>
  1993.  
  1994. <P>
  1995. <DL>
  1996. <DT><B> Synopsis </B><DD><P>Unbiased exponent.</P>
  1997. <DT><B> Syntax </B><DD><P>logb ( <EM>A</EM> ) </P>
  1998. <DT><B> Description </B><DD><P>Logb returns the unbiased exponent of its REAL argument.</P>
  1999. <P>This function depends upon operating system support. Logb is
  2000. part of the IEEE-754 standard, and should be available on most
  2001. machines that implement this standard in one form or another.</P>
  2002.  
  2003. <DT><B>See Also</B><DD><P>frexp</P>
  2004.  
  2005. </DL>
  2006. </P>
  2007.  
  2008. <H2><A NAME="ss7.59">7.59 max </A></H2>
  2009.  
  2010. <P>
  2011. <DL>
  2012. <DT><B> Synopsis </B><DD><P>Maximum function</P>
  2013. <DT><B> Syntax </B><DD><P>max ( <EM>A</EM> ) </P>
  2014. <P>    max ( <EM>A</EM>, <EM>B</EM> )</P>
  2015. <DT><B> Description </B><DD><P>Max returns the maximum value(s) contained in the matrix
  2016. <EM>A</EM>. If the argument is a vector, then the largest value
  2017. is returned.  If <EM>A</EM> is a MxN matrix, then a row-vector
  2018. of N columns is returned containing the maximum value from
  2019. each column of <EM>A</EM>.</P>
  2020. <P>If max is used with two arguments, then max returns a matrix
  2021. the same size as <EM>A</EM> and <EM>B</EM> filled with the largest
  2022. elements from <EM>A</EM> and <EM>B</EM>.</P>
  2023. <P>When matrix elements are complex the absolute value is used
  2024. for comparison purposes.</P>
  2025.  
  2026. <DT><B>See Also</B><DD><P>maxi, min, mini</P>
  2027.  
  2028. </DL>
  2029. </P>
  2030.  
  2031. <H2><A NAME="ss7.60">7.60 maxi </A></H2>
  2032.  
  2033. <P>
  2034. <DL>
  2035. <DT><B> Synopsis </B><DD><P>Maximum value indices</P>
  2036. <DT><B> Syntax </B><DD><P>maxi ( <EM>A</EM> ) </P>
  2037. <DT><B> Description </B><DD><P>Maxi returns the index of the maximum value contained in
  2038. matrix. If the input argument (<EM>A</EM>) is a vector, then the
  2039. index of the largest value is returned. If <EM>A</EM> is a MxN
  2040. matrix, then a row-vector of the column indices of the largest
  2041. column values of <EM>A</EM> is returned.</P>
  2042.  
  2043. <DT><B>See Also</B><DD><P>max, min, mini</P>
  2044.  
  2045. </DL>
  2046. </P>
  2047.  
  2048. <H2><A NAME="ss7.61">7.61 members </A></H2>
  2049.  
  2050. <P>
  2051. <DL>
  2052. <DT><B> Synopsis </B><DD><P>Return an object's member names.</P>
  2053. <DT><B> Syntax </B><DD><P>members ( <EM>L</EM> )</P>
  2054. <DT><B> Description </B><DD><P>The members function takes a variable as an argument
  2055. (<EM>L</EM>), and returns a string-vector containing the
  2056. object's member names.</P>
  2057. <P>For example: <CODE>x = members ($$)</CODE> will
  2058. create a row-vector and assign it to <EM>x</EM>. The row-vector
  2059. will contain the names of all the elements in the
  2060. global-symbol-table.</P>
  2061. <P>The members function is probably most useful when used in
  2062. conjunction with for-loops. The result of members can be
  2063. used as the loop index, allowing users to operate on the
  2064. elements of an object. For example:</P>
  2065. <P>
  2066. <BLOCKQUOTE><CODE>
  2067. <PRE>
  2068. ll = << a = rand(3,3); b = rand(3,3); c = rand(3,3) >>;
  2069. for (i in members (ll)) { ll.[i] = diag(ll.[i]); }
  2070. </PRE>
  2071. </CODE></BLOCKQUOTE>
  2072. </P>
  2073.  
  2074. </DL>
  2075. </P>
  2076.  
  2077. <H2><A NAME="ss7.62">7.62 min </A></H2>
  2078.  
  2079. <P>
  2080. <DL>
  2081. <DT><B> Synopsis </B><DD><P>Minimum function.</P>
  2082. <DT><B> Syntax </B><DD><P>min ( <EM>A</EM> )</P>
  2083. <P>    min ( <EM>A</EM>, <EM>B</EM> )</P>
  2084. <DT><B> Description </B><DD><P>Min returns the minimum value(s) contained in the matrix
  2085. <EM>A</EM>. If the argument is a vector, then the smallest value
  2086. is returned.  If <EM>A</EM> is a MxN matrix, then a row-vector
  2087. of N columns is returned containing the minimum value from
  2088. each column of <EM>A</EM>.</P>
  2089. <P>If min is used with two arguments, then min returns a matrix
  2090. the same size as <EM>A</EM> and <EM>B</EM> filled with the
  2091. smallest elements from <EM>A</EM> and <EM>B</EM>.</P>
  2092. <P>When matrix elements are complex the absolute value is used
  2093. for comparison purposes.</P>
  2094.  
  2095. <DT><B>See Also</B><DD><P>mini, max, maxi</P>
  2096.  
  2097. </DL>
  2098. </P>
  2099.  
  2100. <H2><A NAME="ss7.63">7.63 mini </A></H2>
  2101.  
  2102. <P>
  2103. <DL>
  2104. <DT><B> Synopsis </B><DD><P>Minimum value indices.</P>
  2105. <DT><B> Syntax </B><DD><P>mini ( <EM>A</EM> ) </P>
  2106. <DT><B> Description </B><DD><P>Mini returns the index of the minimum value contained in
  2107. matrix. If the input argument (<EM>A</EM>) is a vector, then the
  2108. index of the smallest value is returned. If <EM>A</EM> is a MxN
  2109. matrix, then a row-vector of the column indices of the
  2110. smallest column values of <EM>A</EM> is returned.</P>
  2111.  
  2112. <DT><B>See Also</B><DD><P>max, maxi, min</P>
  2113.  
  2114.  
  2115. </DL>
  2116. </P>
  2117.  
  2118. <H2><A NAME="ss7.64">7.64 mnorm</A></H2>
  2119.  
  2120. <P>
  2121. <DL>
  2122. <DT><B> Synopsis </B><DD><P>Compute the matrix norm.</P>
  2123. <DT><B> Syntax   </B><DD><P>mnorm ( <EM>A</EM> )</P>
  2124. <P>         mnorm ( <EM>A</EM> , <EM>TYPE</EM> )</P>
  2125.  
  2126. <DT><B> Description </B><DD><P>The first form defaults to computing the 1-norm of the input
  2127. matrix. The second form allows the user to specify the desired
  2128. type of matrix norm with a string argument.</P>
  2129. <P>
  2130. <DL>
  2131.  
  2132. <DT><B><CODE>M</CODE> or <CODE>m</CODE></B><DD><P>returns <CODE>max(abs( <EM>A</EM> ))</CODE></P>
  2133.  
  2134. <DT><B> <CODE>1</CODE>, <CODE>O</CODE> or <CODE>o</CODE> </B><DD><P>return the 1-norm (default), the largest column sum
  2135. (max(sum(abs(A)))). </P>
  2136.  
  2137. <DT><B> <CODE>2</CODE> </B><DD><P>returns the matrix 2-norm 
  2138. (largest singular value)</P>
  2139.  
  2140. <DT><B> <CODE>I</CODE> or <CODE>i</CODE> </B><DD><P>returns the infinity-norm,
  2141. the largest row sum (max(sum(abs(A')))).</P>
  2142.  
  2143. <DT><B> <CODE>F</CODE>, <CODE>f</CODE>, <CODE>E</CODE> or <CODE>e</CODE> </B><DD><P>returns the Frobenius norm.</P>
  2144.  
  2145. </DL>
  2146. </P>
  2147. <P>LAPACK subroutines DLANGE and ZLANGE are used to compute all
  2148. norms, except the 2-norm.</P>
  2149. <P><B>Obscure feature:</B> If <EM>TYPE</EM> is Inf (the output from
  2150. <CODE>inf()</CODE>, for example), then norm will compute the
  2151. Infinity norm of the matrix <EM>A</EM>.</P>
  2152. <P>Example:</P>
  2153. <P>
  2154. <BLOCKQUOTE><CODE>
  2155. <PRE>
  2156. > a = magic(4)
  2157.        16          2          3         13  
  2158.         5         11         10          8  
  2159.         9          7          6         12  
  2160.         4         14         15          1  
  2161. > mnorm ( a )
  2162.        34  
  2163. > mnorm ( a , "m" )
  2164.        16  
  2165. > mnorm ( a , "1" )
  2166.        34  
  2167. > mnorm ( a , "2" )
  2168.        34  
  2169. > mnorm ( a , "i" )
  2170.        34  
  2171. > mnorm ( a , inf() )
  2172.        34  
  2173. </PRE>
  2174. </CODE></BLOCKQUOTE>
  2175. </P>
  2176.  
  2177. </DL>
  2178. </P>
  2179.  
  2180. <H2><A NAME="ss7.65">7.65 mod </A></H2>
  2181.  
  2182. <P>
  2183. <DL>
  2184. <DT><B> Synopsis </B><DD><P>Floating point remainder</P>
  2185. <DT><B> Syntax </B><DD><P>mod( <EM>A</EM>, <EM>B</EM> ) </P>
  2186. <DT><B> Description </B><DD><P>The mod routine returns the floating point remainder of the
  2187. division of <EM>A</EM> by <EM>B</EM>: zero if <EM>B</EM> is zero or
  2188. if <EM>A</EM>/<EM>B</EM> would overflow; otherwise the number F
  2189. with the same sign as <EM>A</EM>, such that <EM>A</EM> = i<EM>B</EM>
  2190. + F for some integer i, and |f| < |B|.</P>
  2191. <P>When the arguments to mod are two matrices, then an element by
  2192. element mod is performed. Mod works on complex number also.</P>
  2193. <P>mod(x,y) is equivalent to: 
  2194. <BLOCKQUOTE>
  2195. n = int( x/y )
  2196. </BLOCKQUOTE>
  2197. </P>
  2198. <P>
  2199. <BLOCKQUOTE>
  2200. mod(x,y) = x - y.*n
  2201. </BLOCKQUOTE>
  2202. </P>
  2203. <P>mod is implemented via libm.a fmod function.</P>
  2204.  
  2205. </DL>
  2206. </P>
  2207.  
  2208. <H2><A NAME="ss7.66">7.66 nan </A></H2>
  2209.  
  2210. <P>
  2211. <DL>
  2212. <DT><B> Synopsis </B><DD><P>Return a NaN (Not a Number)</P>
  2213. <DT><B> Syntax </B><DD><P>nan ( ) </P>
  2214. <DT><B> Description </B><DD><P>Nan returns a NaN (Not a Number) according to IEEE-754. One
  2215. way to determine if a variable contains a NaN is to test it
  2216. against itself.</P>
  2217. <P>
  2218. <BLOCKQUOTE>
  2219. NaN == NaN
  2220. </BLOCKQUOTE>
  2221. </P>
  2222. <P>Should always return FALSE (0).</P>
  2223.  
  2224. <DT><B>See Also</B><DD><P>inf</P>
  2225.  
  2226. </DL>
  2227. </P>
  2228.  
  2229. <H2><A NAME="ss7.67">7.67 ode </A></H2>
  2230.  
  2231. <P>
  2232. <DL>
  2233. <DT><B> Synopsis </B><DD><P>Integrate Ordinary Differential Equations.</P>
  2234. <DT><B> Syntax </B><DD><P>ode ( <EM>rhsf</EM>, <EM>tstart</EM>, <EM>tend</EM>, <EM>ystart</EM>, <EM>dtout</EM>, <EM>relerr</EM>, <EM>abserr</EM>, <EM>uout</EM> )</P>
  2235. <DT><B> Description </B><DD><P>ode integrates a system of N first order ordinary
  2236. differential equations of the form: </P>
  2237. <P>
  2238. <BLOCKQUOTE><CODE>
  2239. <PRE>
  2240. dy(i)/dt = f(t,y(1),y(2),...,y(N))
  2241. y(i) given at  t .
  2242.         
  2243. </PRE>
  2244. </CODE></BLOCKQUOTE>
  2245. </P>
  2246. <P>The arguments to ode are:</P>
  2247. <P>
  2248. <DL>
  2249. <DT><B><EM>rhsf</EM></B><DD><P>A function that evaluates <CODE>dy(i)/dt</CODE> at
  2250. <CODE>t</CODE>. The function takes two arguments and returns
  2251. <CODE>dy/dt</CODE>. An example that generates <CODE>dy/dt</CODE>
  2252. for Van der Pol's equation is shown below.</P>
  2253. <P>
  2254. <BLOCKQUOTE><CODE>
  2255. <PRE>
  2256. vdpol = function ( t , x ) 
  2257. {
  2258.   xp = zeros(2,1);
  2259.   xp[1] = x[1] * (1 - x[2]^2) - x[2];
  2260.   xp[2] = x[1];
  2261.   return xp;
  2262. };
  2263.                 
  2264. </PRE>
  2265. </CODE></BLOCKQUOTE>
  2266. </P>
  2267.  
  2268. <DT><B><EM>ystart</EM></B><DD><P>The initial values of <CODE>y, y(tstart)</CODE>.</P>
  2269.  
  2270. <DT><B><EM>tstart</EM></B><DD><P>The initial value of the independent
  2271. variable. </P>
  2272.  
  2273. <DT><B><EM>tend</EM></B><DD><P>The final value of the independent
  2274. variable. </P>
  2275.  
  2276. <DT><B><EM>dtout</EM></B><DD><P>The output interval. The vector <CODE>y</CODE> will
  2277. be saved at <EM>tstart</EM>, increments of <EM>tstart</EM>
  2278. + <EM>dtout</EM>, and <EM>tend</EM>. If <EM>dtout</EM> is
  2279. not specified, then the default is to store output at
  2280. 101 values of the independent variable.</P>
  2281.  
  2282. <DT><B><EM>relerr</EM></B><DD><P>The relative error tolerance. Default
  2283. value is 1.e-6. </P>
  2284.  
  2285. <DT><B><EM>abserr</EM></B><DD><P>The absolute error tolerance. At each
  2286. step, ode requires that:</P>
  2287. <P>
  2288. <BLOCKQUOTE>
  2289. abs(local error) <= abs(y)*relerr + abserr
  2290. </BLOCKQUOTE>
  2291. </P>
  2292. <P>For each component of the local error and solution
  2293. vectors. The default value is 1.e-6.</P>
  2294.  
  2295. <DT><B><EM>uout</EM></B><DD><P>Optional. A user-supplied function that
  2296. computes an arbitrary output during the
  2297. integration. <EM>uout</EM> must return a row-matrix at
  2298. each dtout during the integration. It is entirely up
  2299. to the user what to put in the matrix. The matrix is
  2300. used to build up a larger matrix of the output, with
  2301. one row for each <EM>dtout</EM>. The resulting matrix is
  2302. returned by ode when the integration is complete.</P>
  2303.  
  2304. </DL>
  2305. </P>
  2306. <P>The Fortran source code for ode is completely explained and
  2307. documented in the text, "Computer Solution of Ordinary
  2308. Differential Equations: The Initial Value Problem" by 
  2309. L. F. Shampine and  M. K. Gordon.</P>
  2310. <P>Example:</P>
  2311. <P>
  2312. <BLOCKQUOTE><CODE>
  2313. <PRE>
  2314. //
  2315. //  Integrate the Van der Pol equation, and measure the effect
  2316. //  of relerr and abserr on the solution.
  2317. //
  2318.  
  2319. vdpol = function ( t , x ) 
  2320. {
  2321.   xp = zeros(2,1);
  2322.   xp[1] = x[1] * (1 - x[2]^2) - x[2];
  2323.   xp[2] = x[1];
  2324.   return xp;
  2325. };
  2326.  
  2327. t0 = 0;
  2328. tf = 10;
  2329. x0 = [0; 0.25];
  2330. dtout = 0.05;
  2331.  
  2332. relerr = [1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1];
  2333. abserr = relerr;
  2334.  
  2335. //
  2336. //  Baseline
  2337. //
  2338.  
  2339. xbase = ode( vdpol, 0, 20, x0, 0.05, 1e-9, 1e-9);
  2340. results = zeros (relerr.n, abserr.n);
  2341. elapse = zeros (relerr.n, abserr.n);
  2342.  
  2343. //
  2344. // Now loop through the combinations of relerr
  2345. // and abserr, saving the results, and computing
  2346. // the maximum difference.
  2347. //
  2348.         "start testing loop"
  2349. for (i in 1:abserr.n)
  2350. {
  2351.   xode.[i] = <<>>;
  2352.   for (j in 1:relerr.n)
  2353.   {
  2354.     printf("\t%i %i\n", i, j);
  2355.     tic();
  2356.     xode.[i].[j] = ode( vdpol, 0, 20, x0, 0.05, relerr[j], abserr[i]);
  2357.     elapse[i;j] = toc();
  2358.  
  2359.     // Save results
  2360.     results[i;j] = max (max (abs (xode.[i].[j] - xbase)));
  2361.   }
  2362. }
  2363.  
  2364. > results
  2365.  results =
  2366.  matrix columns 1 thru 6
  2367.  1.97e-05   0.000297   0.000634    0.00815      0.078       1.44  
  2368.  0.000128   7.89e-05   0.000632    0.00924     0.0732       1.61  
  2369.  0.000647   0.000625    0.00112     0.0147     0.0995       1.46  
  2370.   0.00355    0.00352    0.00271     0.0118     0.0883      0.862  
  2371.    0.0254     0.0254     0.0254      0.104      0.218       1.72  
  2372.     0.513      0.513      0.513      0.589      0.467       1.82  
  2373.  
  2374.         
  2375. </PRE>
  2376. </CODE></BLOCKQUOTE>
  2377. </P>
  2378. <P>Each row of results is a function of the absolute error
  2379. (abserr) and each column is a function of the relative error
  2380. (relerr).</P>
  2381.  
  2382. <DT><B>See Also</B><DD><P>ode4</P>
  2383.  
  2384.  
  2385. </DL>
  2386. </P>
  2387.  
  2388. <H2><A NAME="ss7.68">7.68 ones </A></H2>
  2389.  
  2390. <P>
  2391. <DL>
  2392. <DT><B> Synopsis </B><DD><P>Create a matrix filled with ones.</P>
  2393. <DT><B> Syntax </B><DD><P>ones ( <EM>M</EM> , <EM>N</EM> ) </P>
  2394. <P>    ones ( <EM>A</EM> )</P>
  2395. <DT><B> Description </B><DD><P>Create a matrix of ones. If the input is two scalars, then
  2396. create a matrix of 1s with dimensions <EM>N</EM>x<EM>M</EM>.</P>
  2397. <P>If the input is a 2 element matrix, then create a matrix with
  2398. row and column dimensions equal to <EM>A</EM>[1] and
  2399. <EM>A</EM>[2] respectively.  This is useful when used
  2400. in conjunction with size():</P>
  2401. <P>
  2402. <BLOCKQUOTE><CODE>
  2403. <PRE>
  2404.         ones( size( X ) )
  2405.         
  2406. </PRE>
  2407. </CODE></BLOCKQUOTE>
  2408. </P>
  2409. <P>will return a matrix of ones the same size as <CODE>X</CODE>.</P>
  2410.  
  2411. <DT><B>See Also</B><DD><P>zeros</P>
  2412.  
  2413.  
  2414. </DL>
  2415. </P>
  2416.  
  2417. <H2><A NAME="ss7.69">7.69 open </A></H2>
  2418.  
  2419. <P>
  2420. <DL>
  2421. <DT><B> Synopsis </B><DD><P>Open a file for reading.</P>
  2422. <DT><B> Syntax </B><DD><P>open ( <EM>FILENAME</EM>, <EM>MODE</EM> ) </P>
  2423. <P>    open ( <EM>FILENAME</EM>, <EM>MODE</EM>, <EM>BUFFSIZE</EM> ) </P>
  2424. <DT><B> Description </B><DD><P>Open will open a file or a pipe for read or write
  2425. operations. Open allows the user to specify the mode of
  2426. operation, and optionally a buffer-size for I/O. The "normal"
  2427. UNIX modes are:</P>
  2428. <P>
  2429. <DL>
  2430. <DT><B>r</B><DD><P>read access</P>
  2431. <DT><B>w</B><DD><P>write access</P>
  2432. <DT><B>a</B><DD><P>append: open for writing at end of file, or
  2433. create for writing</P>
  2434.  
  2435. <DT><B><EM>BUFFSIZE</EM></B><DD><P>Buffersize is specified in
  2436. bytes. If BUFFSIZE  is not specified the system
  2437. defaults are used. </P>
  2438. </DL>
  2439. </P>
  2440. <P>Other operating systems may have different mode keys. Look at
  2441. the API documentation for fopen on your system to find what
  2442. mode values are acceptable.</P>
  2443.  
  2444. <DT><B>See Also</B><DD><P>close, printf, fprintf, read, readb, readm, write, writeb, writem</P>
  2445.  
  2446. </DL>
  2447. </P>
  2448.  
  2449. <H2><A NAME="ss7.70">7.70 printf </A></H2>
  2450.  
  2451. <P>
  2452. <DL>
  2453. <DT><B> Synopsis </B><DD><P>Formatted printing.</P>
  2454. <DT><B> Syntax </B><DD><P>printf ( <EM>formatstring</EM> , <EM>VARi</EM> ... )</P>
  2455. <DT><B> Description </B><DD><P>The RLaB printf is a limited feature version of the C-language
  2456. printf(). The features are limited because RLaB does not
  2457. support all of the data type the C-language does.</P>
  2458. <P>
  2459. <DL>
  2460.  
  2461. <DT><B><EM>formatstring</EM></B><DD><P>must be a valid printf format
  2462. string</P>
  2463.  
  2464. <DT><B><EM>VARi</EM></B><DD><P>are any number of constants or
  2465. variables that match the format string. printf
  2466. cannot print out vector, matrix, or list objects as a
  2467. whole. Valid print objects are strings, constants, and
  2468. scalars.</P>
  2469. </DL>
  2470. </P>
  2471. <P>The following shows how one might print out the annotated
  2472. contents of a matrix.</P>
  2473. <P>
  2474. <BLOCKQUOTE><CODE>
  2475. <PRE>
  2476. for(i in 0:size(a)[0]-1) 
  2477. {
  2478.   for(j in 0:size(a)[1]-1) 
  2479.   {
  2480.     printf("a[%i;%i] = %f\n", i, j, a[i;j]);
  2481.   }
  2482. }
  2483.         
  2484. </PRE>
  2485. </CODE></BLOCKQUOTE>
  2486. </P>
  2487. <P>However, it would be more efficient to use:</P>
  2488. <P>
  2489. <BLOCKQUOTE><CODE>
  2490. <PRE>
  2491. > writem("stdout", a);
  2492.         
  2493. </PRE>
  2494. </CODE></BLOCKQUOTE>
  2495. </P>
  2496.  
  2497. <DT><B>See Also</B><DD><P>fprintf, sprintf, write, read</P>
  2498.  
  2499. </DL>
  2500. </P>
  2501.  
  2502. <H2><A NAME="ss7.71">7.71 prod </A></H2>
  2503.  
  2504. <P>
  2505. <DL>
  2506. <DT><B> Synopsis </B><DD><P>Product.</P>
  2507. <DT><B> Syntax </B><DD><P>prod ( <EM>A</EM> )</P>
  2508. <DT><B> Description </B><DD><P>Compute the product of the elements of <EM>A</EM> (if <EM>A</EM>
  2509. is a vector).  If <EM>A</EM> is a matrix return a row vector
  2510. containing the product of each column.</P>
  2511.  
  2512. </DL>
  2513. </P>
  2514.  
  2515. <H2><A NAME="ss7.72">7.72 putenv </A></H2>
  2516.  
  2517. <P>
  2518. <DL>
  2519. <DT><B> Synopsis </B><DD><P>Change or add an environment variable.</P>
  2520. <DT><B> Syntax </B><DD><P>putenv ( <EM>STRING</EM> ) </P>
  2521. <DT><B> Description </B><DD><P>putenv takes a single argument, <EM>STRING</EM>, of the form:</P>
  2522. <P>
  2523. <BLOCKQUOTE><CODE>
  2524. <PRE>
  2525. "NAME=VALUE"
  2526.         
  2527. </PRE>
  2528. </CODE></BLOCKQUOTE>
  2529. </P>
  2530. <P>putenv make the value of the environment variable <CODE>NAME</CODE> equal
  2531. to <CODE>VALUE</CODE> by altering an existing variable or creating a new
  2532. one. </P>
  2533. <P>Exactly how putenv behaves is depends upon the underlying
  2534. operating system implementation. </P>
  2535. <P>On most Unix systems putenv will return  non-zero if an error
  2536. occurred, and zero otherwise.</P>
  2537.  
  2538. <DT><B>See Also</B><DD><P>getenv</P>
  2539.  
  2540. </DL>
  2541. </P>
  2542.  
  2543. <H2><A NAME="ss7.73">7.73 qr </A></H2>
  2544.  
  2545. <P>
  2546. <DL>
  2547. <DT><B> Synopsis </B><DD><P>QR decomposition</P>
  2548. <DT><B> Syntax </B><DD><P>qr ( <EM>A</EM> )</P>
  2549. <P>    qr ( <EM>A</EM>, <CODE>"p"</CODE> )</P>
  2550. <DT><B> Description </B><DD>
  2551. <P>Qr computes the QR decomposition of the input matrix A such
  2552. that: </P>
  2553. <P>
  2554. <BLOCKQUOTE>
  2555. A = Q * R
  2556. </BLOCKQUOTE>
  2557. </P>
  2558. <P>or</P>
  2559. <P>
  2560. <BLOCKQUOTE>
  2561. A*p = Q * R
  2562. </BLOCKQUOTE>
  2563. </P>
  2564. <P>Qr returns a list containing elements <EM>q</EM> and
  2565. <EM>r</EM>. Optionally, qr can take a second argument,
  2566. <CODE>"p"</CODE> which tells qr to perform column pivoting when
  2567. computing <EM>q</EM> and <EM>r</EM>. The permutation matrix
  2568. <EM>p</EM> is returned in the same list as <EM>q</EM> and
  2569. <EM>r</EM>.</P>
  2570. <P>Qr utilizes LAPACK subroutines DGEQRF and DORGQR for REAL
  2571. inputs, and ZGEQRF and ZUNGQR for COMPLEX inputs. When column
  2572. pivoting is requested the LAPACK subroutines DGEQPF, and
  2573. ZGEQPF are used.</P>
  2574.  
  2575. </DL>
  2576. </P>
  2577.  
  2578. <H2><A NAME="ss7.74">7.74 quit </A></H2>
  2579.  
  2580. <P>
  2581. <DL>
  2582. <DT><B> Synopsis </B><DD><P>Quit, terminate an Rlab session.</P>
  2583. <DT><B> Syntax </B><DD><P>quit</P>
  2584. <DT><B> Description </B><DD><P>The statement <CODE>quit</CODE> causes RLaB to stop execution
  2585. immediately. Quit is an executable statement, that is, it is
  2586. not built into the parser, it only takes effect when executed.
  2587. This allows users to embed a quit statement in a branch of a
  2588. conditional statement.</P>
  2589. <P>RLaB can also be stopped by a ctrl-d (hold down the control
  2590. key while typing `d').</P>
  2591.  
  2592. </DL>
  2593. </P>
  2594.  
  2595. <H2><A NAME="ss7.75">7.75 rand </A></H2>
  2596.  
  2597. <P>
  2598. <DL>
  2599. <DT><B> Synopsis </B><DD><P>Random number generator.</P>
  2600. <DT><B> Syntax </B><DD><P>rand ( ) </P>
  2601. <P>    rand ( <EM>nrow</EM>, <EM>ncol</EM> )</P>
  2602. <P>    rand ( <EM>DTYPE</EM>, <EM>D1</EM> )</P>
  2603. <P>    rand ( <EM>DTYPE</EM>, <EM>D1</EM>, <EM>D2</EM> )</P>
  2604. <DT><B> Description </B><DD><P>
  2605. <DL>
  2606.  
  2607. <DT><B>rand()</B><DD><P>produces a random scalar.</P>
  2608.  
  2609. <DT><B>rand ( <EM>X</EM> , <EM>Y</EM> )</B><DD><P>produces a randomly
  2610. generated MATRIX with row dimension <EM>X</EM>, and
  2611. column dimension <EM>Y</EM>.</P>
  2612.  
  2613. <DT><B>rand ( <EM>DTYPE</EM> , ... )</B><DD><P>changes the
  2614. distribution used when generating random numbers. The
  2615. value of <EM>DTYPE</EM> determines the subsequent
  2616. parameters.</P>
  2617.  
  2618. </DL>
  2619. </P>
  2620. <P>Types of distributions:</P>
  2621. <P>
  2622. <DL>
  2623.  
  2624. <DT><B><CODE>rand ( "beta" , A , B )</CODE></B><DD><P>Sets the generator to return a random deviate from the beta
  2625. distribution with parameters <CODE>A</CODE> and <CODE>B</CODE>.  The
  2626. density of the beta is</P>
  2627. <P>
  2628. <BLOCKQUOTE><CODE>
  2629. <PRE>
  2630. x^(a-1) * (1-x)^(b-1) / B(a,b) for 0 < x < 1
  2631.         
  2632. </PRE>
  2633. </CODE></BLOCKQUOTE>
  2634. </P>
  2635.  
  2636. <DT><B><CODE>rand ( "chi" , DF )</CODE></B><DD><P>Sets the generator to return a random deviate from the
  2637. distribution of a chi-square with <CODE>DF</CODE> degrees of freedom
  2638. random variable.</P>
  2639.  
  2640. <DT><B><CODE>rand ( "exp" , AV )</CODE></B><DD><P>Sets the generator to return a random deviate from an
  2641. exponential distribution with mean <CODE>AV</CODE>.</P>
  2642.  
  2643. <DT><B><CODE>rand ( "f" , DFN  DFD )</CODE></B><DD><P>Sets the generator to return a random deviate from the F
  2644. (variance ratio) distribution with <CODE>DFN</CODE> degrees of
  2645. freedom in the numerator and <CODE>DFD</CODE> degrees of freedom in
  2646. the denominator.</P>
  2647.  
  2648. <DT><B><CODE>rand ( "gamma" , A , R )</CODE></B><DD><P>Sets the generator to return a random deviate from the gamma
  2649. distribution whose density is:</P>
  2650. <P>
  2651. <BLOCKQUOTE><CODE>
  2652. <PRE>
  2653. (A**R)/Gamma(R) * X**(R-1) * Exp(-A*X)
  2654.         
  2655. </PRE>
  2656. </CODE></BLOCKQUOTE>
  2657. </P>
  2658.  
  2659. <DT><B><CODE>rand ( "nchi" , DF , XNONC )</CODE></B><DD><P>Sets the generator to return a random deviate from the
  2660. distribution of a noncentral chi-square with <CODE>DF</CODE> degrees
  2661. of freedom and noncentrality parameter <CODE>XNONC</CODE>.</P>
  2662.  
  2663. <DT><B><CODE>rand ( "nf" , DFN , DFD, XNONC )</CODE></B><DD><P>Sets the generator to return a random deviate from the
  2664. noncentral F (variance ratio) distribution with <CODE>DFN</CODE>
  2665. degrees of freedom in the numerator, and <CODE>DFD</CODE> degrees of
  2666. freedom in the denominator, and noncentrality parameter
  2667. <CODE>XNONC</CODE>.</P>
  2668.  
  2669. <DT><B><CODE>rand ( "normal" , AV , SD )</CODE></B><DD><P>Sets the generator to return a random deviate from a normal
  2670. distribution with mean, <EM>AV</EM>, and standard deviation,
  2671. <EM>SD</EM>.</P>
  2672.  
  2673. <DT><B><CODE>rand ( "uniform" , LOW , HIGH )</CODE></B><DD><P>Sets the generator to return a uniform double between
  2674. <CODE>LOW</CODE> and <CODE>HIGH</CODE>.</P>
  2675.  
  2676. <DT><B><CODE>rand ( "bin" , N , P )</CODE></B><DD><P>Returns a single random deviate from a binomial distribution
  2677. whose number of trials is <CODE>N</CODE> and whose probability of an
  2678. event in each trial is <CODE>P</CODE>.</P>
  2679.  
  2680. <DT><B><CODE>rand ( "poisson" , AV )</CODE></B><DD><P>Sets the generator to return a random deviate from a
  2681. Poisson distribution with mean <CODE>AV</CODE>.</P>
  2682.  
  2683. <DT><B><CODE>rand ( "default" )</CODE></B><DD><P>Resets the random number generator to the default generator,
  2684. which generates a distributed random variable in the interval
  2685. 0 -> 1. The interval endpoints are not returned.</P>
  2686.  
  2687. </DL>
  2688.  
  2689. Examples:</P>
  2690. <P>
  2691. <BLOCKQUOTE><CODE>
  2692. <PRE>
  2693. > rand()
  2694.        0.368
  2695. > rand(4)
  2696.  vector elements 1 thru 4
  2697.        0.983       0.535       0.766       0.646
  2698. > rand(3,3)
  2699.  matrix columns 1 thru 3
  2700.        0.767       0.152       0.347
  2701.         0.78       0.625       0.917
  2702.        0.823       0.315        0.52
  2703.  
  2704. > rand("norm", 10.0, 2.0 );
  2705. > rand(10)
  2706.  vector elements 1 thru 5
  2707.         9.86        11.8        12.1        7.35        8.76
  2708.  vector elements 6 thru 10
  2709.         10.5        7.44        11.1        6.93        9.87
  2710.         
  2711. </PRE>
  2712. </CODE></BLOCKQUOTE>
  2713. </P>
  2714. <P>rand uses the RANLIB library, authored by B. W. Brown and
  2715. J. Lovato under grant CA-16672 from the National Cancer
  2716. Institute.</P>
  2717.  
  2718. <DT><B>See Also</B><DD><P>srand</P>
  2719.  
  2720. </DL>
  2721. </P>
  2722.  
  2723. <H2><A NAME="ss7.76">7.76 rcond </A></H2>
  2724.  
  2725. <P>
  2726. <DL>
  2727. <DT><B> Synopsis </B><DD><P>Condition number.</P>
  2728. <DT><B> Syntax </B><DD><P>rcond( <EM>A</EM> )</P>
  2729. <DT><B> Description </B><DD><P>Rcond computes an estimate of the condition number of the
  2730. input matrix, <EM>A</EM>. rcond() uses the LAPACK routines
  2731. DGECON, or ZGECON.</P>
  2732. <P>Probably the most published way to compute the condition of a
  2733. matrix is:</P>
  2734. <P>
  2735. <BLOCKQUOTE><CODE>
  2736. <PRE>
  2737. Kcond = ||A|| * ||inv(A)||
  2738.         
  2739. </PRE>
  2740. </CODE></BLOCKQUOTE>
  2741. </P>
  2742. <P>Another method is to use the 1st and last singular values of
  2743. A:</P>
  2744. <P>
  2745. <BLOCKQUOTE><CODE>
  2746. <PRE>
  2747. Kcond = sigma(1)/sigma(n)
  2748.         
  2749. </PRE>
  2750. </CODE></BLOCKQUOTE>
  2751. </P>
  2752. <P>rcond computes an ESTIMATE of the condition number without
  2753. computing all of the columns of inv(A). For more information
  2754. see the LAPACK User's Guide.</P>
  2755. <P>See Also  inv, det, lu</P>
  2756.  
  2757. </DL>
  2758. </P>
  2759.  
  2760. <H2><A NAME="ss7.77">7.77 read </A></H2>
  2761.  
  2762. <P>
  2763. <DL>
  2764. <DT><B> Synopsis </B><DD><P>Read data from a file.</P>
  2765. <DT><B> Syntax </B><DD><P>read ( <EM>FILENAME</EM> )</P>
  2766. <P>    read ( <EM>FILENAME</EM>, <EM>LIST</EM> )</P>
  2767. <DT><B> Description </B><DD><P>read reads the file identified by the <EM>FILENAME</EM>. The
  2768. file is opened with read access, and all of the contents are
  2769. read.  The file identified by the 1st argument must contain
  2770. data that is in RLaB binary format.  The entities in the file
  2771. are installed in the global symbol table, overwriting any
  2772. existing entities. Upon completion the file is closed.</P>
  2773. <P>Example:</P>
  2774. <P>
  2775. <BLOCKQUOTE><CODE>
  2776. <PRE>
  2777. read ("bunch_of_data_in_a_file");
  2778.         
  2779. </PRE>
  2780. </CODE></BLOCKQUOTE>
  2781. </P>
  2782. <P>The second form of the read function allows the data in the
  2783. file to be read into list variable <EM>LIST</EM>. The
  2784. global-symbol-table is untouched (except for <EM>LIST</EM>).</P>
  2785. <P>Example:</P>
  2786. <P>
  2787. <BLOCKQUOTE><CODE>
  2788. <PRE>
  2789. read ("bunch_of_data", X);
  2790.         
  2791. </PRE>
  2792. </CODE></BLOCKQUOTE>
  2793. </P>
  2794. <P>The contents of the file <CODE>bunch_of_data</CODE> are read and
  2795. stored in the list variable <CODE>X</CODE>. Except for the
  2796. creation/modification of the variable <CODE>X</CODE>, the
  2797. global-symbol-table is unchanged.</P>
  2798. <P>Read will read most numeric matrices written by MATLAB's save
  2799. command. Read will not read MATLAB text matrices, or sparse
  2800. matrices, or matrices written with reduced precision (integer
  2801. format). Read will not read Cray, or VAX binaries. Read will
  2802. read big and little endian binaries - this includes binaries
  2803. written from PCs, DEC Risc, Macintosh, Sun, and Apollo.</P>
  2804.  
  2805. <DT><B>See Also</B><DD><P>FILES, close, getline, read, readm, writem</P>
  2806.  
  2807.  
  2808. </DL>
  2809. </P>
  2810.  
  2811. <H2><A NAME="ss7.78">7.78 readm </A></H2>
  2812.  
  2813. <P>
  2814. <DL>
  2815. <DT><B> Synopsis </B><DD><P>Read ASCII matrices from a file.</P>
  2816. <DT><B> Syntax </B><DD><P>readm ( <EM>FILENAME</EM> )</P>
  2817. <P>    readm ( <EM>FILENAME</EM>, [ <EM>NR</EM>,<EM>NC</EM> ] )</P>
  2818. <P>    readm ( <EM>FILENAME</EM>, <EM>NROW</EM> )</P>
  2819. <DT><B> Description </B><DD><P>Readm reads a generic matrix of data from the file denoted by
  2820. the string argument <EM>FILENAME</EM>. The return value is the
  2821. newly created matrix. The second, and optional, argument is a
  2822. two-element matrix that specifies the size of the matrix to
  2823. read.</P>
  2824. <P>If the matrix size is not specified, then the matrix is filled
  2825. row-wise with the input data. Otherwise (if the size is
  2826. specified), the matrix if filled column-wise, as the input is
  2827. read.</P>
  2828. <P>The file format is generic ASCII. The rows of the matrix are
  2829. separated by newlines, and the columns are separated by
  2830. whitespace. Unnecessary newlines, either before, or after the
  2831. data will confuse readm, and will probably result in an error
  2832. message. Only one matrix can be stored in a file. If you need
  2833. to store more than one matrix in a file, use write, and
  2834. read. </P>
  2835. <P>Readm can only read in numeric matrices. The result of reading
  2836. in string matrices is undefined.</P>
  2837. <P>Example:</P>
  2838. <P>
  2839. <BLOCKQUOTE><CODE>
  2840. <PRE>
  2841. 1 2 3 4
  2842. 5 6 7 8
  2843. 9 10 11 12
  2844. </PRE>
  2845. </CODE></BLOCKQUOTE>
  2846. </P>
  2847. <P>The above values in a file called "test" would be read in like:</P>
  2848. <P>
  2849. <BLOCKQUOTE><CODE>
  2850. <PRE>
  2851. > a = readm("test")
  2852.  a =
  2853.  matrix columns 1 thru 4
  2854.         1          2          3          4  
  2855.         5          6          7          8  
  2856.         9         10         11         12  
  2857. </PRE>
  2858. </CODE></BLOCKQUOTE>
  2859. </P>
  2860. <P>Readm exists to read in data from other programs. In many
  2861. cases a simple awk script will filter the other programs
  2862. output into one or more columns of data. readm will read the
  2863. data into the matrix, then the matrix can be reshaped if
  2864. necessary.</P>
  2865. <P>Notes:</P>
  2866. <P>Readm has no idea how many rows are in the matrix it is
  2867. reading. This is because readm can work with pipes and process
  2868. output where it gets the matrix as a stream. Readm uses a
  2869. heuristic to guess how many rows of the matrix to allocate at
  2870. one time. A second, optional argument, NROW can be specified
  2871. if the heuristic does not yield the performance you
  2872. desire. The heuristic is purposely memory conservative.</P>
  2873. <P>
  2874. <BLOCKQUOTE><CODE>
  2875. <PRE>
  2876. readm ( "filename" , NROW )
  2877. </PRE>
  2878. </CODE></BLOCKQUOTE>
  2879. </P>
  2880.  
  2881. <DT><B>See Also</B><DD><P>reshape, getline, open, read, write, writem</P>
  2882.  
  2883. </DL>
  2884. </P>
  2885.  
  2886. <H2><A NAME="ss7.79">7.79 require </A></H2>
  2887.  
  2888. <P>
  2889. <DL>
  2890. <DT><B> Synopsis </B><DD><P>Specify program dependencies/requirements.</P>
  2891. <DT><B> Syntax </B><DD><P>require <EM>NAME</EM></P>
  2892. <DT><B> Description </B><DD><P>The require command takes Rfile names as operands, and checks
  2893. the workspace for a function variable called <EM>NAME</EM>. If
  2894. that function exists, then no action is taken. If the function
  2895. does not exist, then the file <CODE>NAME.r</CODE> is loaded.</P>
  2896. <P>More than one <EM>NAME</EM> can be given on the same
  2897. line. Continuations are not allowed.</P>
  2898. <P><EM>NAME</EM> can contain the `.r' extension that distinguishes
  2899. Rfiles (by convention), or <EM>NAME</EM> can omit the `.r'
  2900. extension. In either case a workspace variable without the
  2901. `.r' extension is checked for.</P>
  2902. <P>Example:</P>
  2903. <P>
  2904. <BLOCKQUOTE><CODE>
  2905. <PRE>
  2906. > require roots poly.r bode
  2907. </PRE>
  2908. </CODE></BLOCKQUOTE>
  2909. </P>
  2910. <P>The require command syntax is identical to the rfile command,
  2911. with the obvious exception of the initial keyword.</P>
  2912. <P>The rules for searching the user's <CODE>RLAB2_PATH</CODE> are the
  2913. same as those used with the rfile command.</P>
  2914.  
  2915. <DT><B>See Also</B><DD><P>rfile, load</P>
  2916.  
  2917.  
  2918. </DL>
  2919. </P>
  2920.  
  2921. <H2><A NAME="ss7.80">7.80 reshape </A></H2>
  2922.  
  2923. <P>
  2924. <DL>
  2925. <DT><B> Synopsis </B><DD><P>Reshape a matrix</P>
  2926. <DT><B> Syntax </B><DD><P>reshape ( <EM>A</EM>, <EM>nrow</EM>, <EM>ncol</EM> )</P>
  2927. <DT><B> Description </B><DD><P>Reshape does what its name implies, it reshapes the input
  2928. matrix so that the return value has the number of rows and
  2929. columns specified by the last two arguments. Reshape will not
  2930. reshape the matrix if the product of the new row and column
  2931. dimensions does not equal the product of the existing row and
  2932. column dimensions.</P>
  2933. <P>Examples:</P>
  2934. <P>
  2935. <BLOCKQUOTE><CODE>
  2936. <PRE>
  2937. m = [1,2,3;4,5,6;7,8,9];
  2938. mrow = reshape(m, 1, 9); // converts m to a row matrix
  2939. mcol = reshape(m, 9, 1); // converts m to a column matrix
  2940. </PRE>
  2941. </CODE></BLOCKQUOTE>
  2942. </P>
  2943.  
  2944. </DL>
  2945. </P>
  2946.  
  2947. <H2><A NAME="ss7.81">7.81 rfile </A></H2>
  2948.  
  2949. <P>
  2950. <DL>
  2951. <DT><B> Synopsis </B><DD><P>Load an rfile.</P>
  2952. <DT><B> Syntax </B><DD><P>rfile</P>
  2953. <P>    rfile <EM>NAME</EM></P>
  2954. <DT><B> Description </B><DD><P>
  2955. <DL>
  2956.  
  2957. <DT><B>rfile</B><DD><P>Prints a list of all the files with a `.r'
  2958. suffix. The list is compiled by searching the
  2959. directories contained in the environment variable
  2960. <CODE>RLAB2__PATH</CODE>.</P>
  2961.  
  2962. <DT><B>rfile <EM>NAME</EM></B><DD><P>Loads the contents of the file
  2963. denoted by <EM>NAME</EM> into the workspace. The
  2964. <EM>NAME</EM> argument is NOT a string, and does not
  2965. have to include the `.r' suffix.</P>
  2966. <P>Allowable names for rfiles are filenames that start
  2967. with:
  2968. <BLOCKQUOTE>
  2969. A digit, or a letter (a-z or A-Z).
  2970. </BLOCKQUOTE>
  2971.  
  2972. and contain:
  2973. <BLOCKQUOTE>
  2974.         
  2975. digits, letters, and/or <CODE>-</CODE>, <CODE>_</CODE>, <CODE>.</CODE>
  2976. </BLOCKQUOTE>
  2977. </P>
  2978. <P>You may not be able to use all the possible filenames
  2979. allowed by the host operating system.</P>
  2980.  
  2981. </DL>
  2982. </P>
  2983. <P>If the user's environment does not contain <CODE>RLAB2_PATH</CODE>,
  2984. then the default search-path is used. The default is set at
  2985. compile time. Normally the default is ".", the current working
  2986. directory. </P>
  2987. <P>Rfile is a command, not an expression or statement. Therefore,
  2988. it must be issued on a line by itself, and cannot occur in the
  2989. midst of another statement or expression.  The rfile command
  2990. cannot be continued across lines (no continuations).</P>
  2991. <P>The command `rfile <EM>NAME</EM>' can be used more than
  2992. once. Each time the command is issued the file `<EM>NAME</EM>.r'
  2993. is loaded.</P>
  2994. <P>The rfile command tries to be friendly. If you give it a
  2995. string without the `.r' extension, it will automatically add
  2996. one for you. If you give is a string with the `.r' extension,
  2997. it will leave it alone.</P>
  2998. <P>The contents of the named file can be any valid RLaB commands
  2999. or functions. There is no limit to the number of functions
  3000. that a file can contain. Additionally, a mixture of commands,
  3001. and function definitions can be included in the same file.</P>
  3002. <P>Example:</P>
  3003. <P>
  3004. <BLOCKQUOTE><CODE>
  3005. <PRE>
  3006. > rfile roots.r poly bode
  3007. </PRE>
  3008. </CODE></BLOCKQUOTE>
  3009. </P>
  3010.  
  3011. <DT><B>See Also</B><DD><P>help, load, require</P>
  3012.  
  3013. </DL>
  3014. </P>
  3015.  
  3016. <H2><A NAME="ss7.82">7.82 round </A></H2>
  3017.  
  3018. <P>
  3019. <DL>
  3020. <DT><B> Synopsis </B><DD><P>Round to the nearest integer.</P>
  3021. <DT><B> Syntax </B><DD><P>round ( <EM>A</EM> ) </P>
  3022. <DT><B> Description </B><DD><P>Round returns the nearest integer value to its floating point
  3023. argument <EM>X</EM> as a double-precision floating point
  3024. number. The returned value is rounded according to the
  3025. currently set machine rounding mode. If round-to-nearest (the
  3026. default mode) is set and the difference between the function
  3027. argument and the rounded result is exactly 0.5, then the
  3028. result will be rounded to the nearest even integer.</P>
  3029. <P>Round uses the libm.a function rint. If your machine does not
  3030. have rint, then the supplied rint is used.</P>
  3031.  
  3032. <DT><B>See Also</B><DD><P>ceil, int, floor</P>
  3033.  
  3034. </DL>
  3035. </P>
  3036.  
  3037. <H2><A NAME="ss7.83">7.83 schur </A></H2>
  3038.  
  3039. <P>
  3040. <DL>
  3041. <DT><B> Synopsis </B><DD><P>Schur decomposition.</P>
  3042. <DT><B> Syntax </B><DD><P>schur ( <EM>A</EM> )</P>
  3043. <DT><B> Description </B><DD><P>The schur function returns a list containing elements <EM>t</EM>
  3044. and <EM>z</EM>, such that:</P>
  3045. <P>
  3046. <BLOCKQUOTE>
  3047.         
  3048. <EM>A = z * t * z'</EM>
  3049. </BLOCKQUOTE>
  3050. </P>
  3051. <P>If <EM>A</EM> is real, the <EM>t</EM> is in "Real-Schur" form. The
  3052. "Real-Schur" form is block upper-triangular with 1-by-1 and
  3053. 2-by-2 diagonal blocks; each 2-by-2 diagonal block has its
  3054. diagonal elements equal and its off-diagonal elements of
  3055. opposite sign. The eigenvalues of the 2-by-2 block: 
  3056. <CODE>[a, b; c, a]</CODE> are: <CODE>a +/- sqrt(b*c)</CODE></P>
  3057. <P>schur uses the LAPACK subroutines DGEES, and ZGEES.</P>
  3058.  
  3059. </DL>
  3060. </P>
  3061.  
  3062. <H2><A NAME="ss7.84">7.84 sign </A></H2>
  3063.  
  3064. <P>
  3065. <DL>
  3066. <DT><B> Synopsis </B><DD><P>Return the sign of <EM>A</EM></P>
  3067. <DT><B> Syntax </B><DD><P>sign ( <EM>A</EM> ) </P>
  3068. <DT><B> Description </B><DD>
  3069. <P>For real scalar argument, sign returns:</P>
  3070. <P>
  3071. <BLOCKQUOTE>
  3072. 1 if A > 0
  3073. </BLOCKQUOTE>
  3074.  
  3075. <BLOCKQUOTE>
  3076. 0 if A == 0
  3077. </BLOCKQUOTE>
  3078.  
  3079. <BLOCKQUOTE>
  3080. -1 if A < 0
  3081. </BLOCKQUOTE>
  3082. </P>
  3083. <P>For a complex scalar sign returns:</P>
  3084. <P>
  3085. <BLOCKQUOTE>
  3086. A ./ abs (A)
  3087. </BLOCKQUOTE>
  3088. </P>
  3089. <P>sign performs its operation on real and complex matrices in an
  3090. element by element fashion.</P>
  3091.  
  3092. </DL>
  3093. </P>
  3094.  
  3095. <H2><A NAME="ss7.85">7.85 trig </A></H2>
  3096.  
  3097. <P>
  3098. <DL>
  3099. <DT><B> Synopsis </B><DD><P>Compute the sin.</P>
  3100. <DT><B> Syntax </B><DD><P>sin ( <EM>A</EM> ) </P>
  3101. <DT><B> Description </B><DD><P>RLaB trigonometric functions are designed to take scalars, and
  3102. matrices as arguments. The return value is the input argument
  3103. with the trigonometric operation performed element by element.</P>
  3104. <P>All the trigonometric functions use the C language math
  3105. library functions, so details about the ranges and error
  3106. conditions can be found by examining the appropriate man pages
  3107. on your system.</P>
  3108.  
  3109. </DL>
  3110. </P>
  3111.  
  3112. <H2><A NAME="ss7.86">7.86 size </A></H2>
  3113.  
  3114. <P>
  3115. <DL>
  3116. <DT><B> Synopsis </B><DD><P>Return the size of an object.</P>
  3117. <DT><B> Syntax </B><DD><P>size ( <EM>A</EM> )</P>
  3118. <DT><B> Description </B><DD><P>The size function returns the size of the argument. </P>
  3119. <P>
  3120. <DL>
  3121.  
  3122. <DT><B>NUMERIC</B><DD><P>size returns a matrix whose 1st element is
  3123. the number of rows, and whose 2nd element is the
  3124. number of columns.</P>
  3125.  
  3126. <DT><B>STRING</B><DD><P>size returns a matrix whose 1st element is
  3127. the number of rows, and whose 2nd element is the
  3128. number of columns. If the length of a particular
  3129. string is desired, then the length function must be
  3130. used.</P>
  3131.  
  3132. <DT><B>LIST</B><DD><P>size returns the number of elements in the
  3133. list. </P>
  3134.  
  3135. </DL>
  3136. </P>
  3137.  
  3138. <DT><B>See Also</B><DD><P>length, show</P>
  3139.  
  3140. </DL>
  3141. </P>
  3142.  
  3143. <H2><A NAME="ss7.87">7.87 sizeof </A></H2>
  3144.  
  3145. <P>
  3146. <DL>
  3147. <DT><B> Synopsis </B><DD><P>Return the size of an object in bytes.</P>
  3148. <DT><B> Syntax </B><DD><P>sizeof ( <EM>A</EM> ) </P>
  3149. <DT><B> Description </B><DD><P>The sizeof function returns the number of bytes of data in the
  3150. argument <EM>A</EM>.</P>
  3151.  
  3152. <DT><B>See Also</B><DD><P>size, who, whos</P>
  3153.  
  3154. </DL>
  3155. </P>
  3156.  
  3157. <H2><A NAME="ss7.88">7.88 solve </A></H2>
  3158.  
  3159. <P>
  3160. <DL>
  3161. <DT><B> Synopsis </B><DD><P>Solve linear equations.</P>
  3162. <DT><B> Syntax </B><DD><P>solve ( <EM>A</EM>, <EM>B</EM> )</P>
  3163. <P>    solve ( <EM>A</EM>, <EM>B</EM>, <EM>TYPE</EM> )</P>
  3164. <DT><B> Description </B><DD><P>Solve solves a system of linear equations:</P>
  3165. <P>
  3166. <BLOCKQUOTE>
  3167. <EM>A * X = B</EM>
  3168. </BLOCKQUOTE>
  3169. </P>
  3170. <P>
  3171. <DL>
  3172. <DT><B><EM>A</EM></B><DD><P>is the coefficient matrix.</P>
  3173. <DT><B><EM>B</EM></B><DD><P>is the right hand side.</P>
  3174. <DT><B><EM>X</EM></B><DD><P>is the solution.</P>
  3175. </DL>
  3176. </P>
  3177. <P><EM>B</EM> can contain multiple right-hand-sides, one in each
  3178. column.  Solve returns a matrix of the solutions, <EM>X</EM>,
  3179. where each column of the solution corresponds to a column of
  3180. <EM>B</EM>.</P>
  3181. <P>Solve uses the LAPACK subroutines DGETRF, and ZGETRF if
  3182. <EM>A</EM> is general.</P>
  3183. <P>Solve uses the LAPACK subroutines DSYTRF, and ZHETRF if
  3184. <EM>A</EM> is symmetric.</P>
  3185. <P>The third and optional argument, <EM>TYPE</EM> allows the user
  3186. to overide the symmetry check, and force the solve to use
  3187. either the general or the symmetric solver.</P>
  3188. <P>
  3189. <BLOCKQUOTE>
  3190. TYPE = "g" or "G":      The general solution is used.
  3191. </BLOCKQUOTE>
  3192. </P>
  3193. <P>
  3194. <BLOCKQUOTE>
  3195. TYPE = "s" or "S":      The symmetric solution is used.
  3196. </BLOCKQUOTE>
  3197. </P>
  3198.  
  3199. <DT><B>See Also</B><DD><P>backsub, inv, factor, lu, rcond</P>
  3200.  
  3201. </DL>
  3202. </P>
  3203.  
  3204. <H2><A NAME="ss7.89">7.89 sort </A></H2>
  3205.  
  3206. <P>
  3207. <DL>
  3208. <DT><B> Synopsis </B><DD><P>Sort an object.</P>
  3209. <DT><B> Syntax </B><DD><P>sort ( <EM>A</EM> )</P>
  3210. <DT><B> Description </B><DD><P>If A is a vector (either row or column): </P>
  3211. <P>
  3212. <BLOCKQUOTE>
  3213. Then sort returns a list, containing the sorted values and
  3214. indices. List element names are `val' and `ind'.
  3215. </BLOCKQUOTE>
  3216. </P>
  3217. <P>If A is a matrix (m > 2):</P>
  3218. <P>
  3219. <BLOCKQUOTE>
  3220. Then sort returns a list, containing a matrix with the
  3221. sorted columns of A, and a matrix containing the sorted
  3222. indices of A.
  3223. </BLOCKQUOTE>
  3224. </P>
  3225. <P>Numerical matrices are sorted in ascending numerical value.
  3226. Complex matrices are sorted by absolute value.
  3227. String matrices are sorted alphabetically (using strcmp()).</P>
  3228. <P>The sort function uses a simplistic version of qsort.</P>
  3229.  
  3230. </DL>
  3231. </P>
  3232.  
  3233. <H2><A NAME="ss7.90">7.90 sparse </A></H2>
  3234.  
  3235. <P>
  3236. <DL>
  3237. <DT><B> Synopsis </B><DD><P>Convert full (dense) storage to sparse storage </P>
  3238. <DT><B> Syntax </B><DD><P>sparse ( <EM>A</EM> ) </P>
  3239. <DT><B> Description </B><DD><P>sparse converts its argument from a dense storage format to the
  3240. sparse storage format. If the argument is already sparse, then it
  3241. is condensed (any non-zeros are removed).  The sparse storage
  3242. format is commonly referred to as <EM>sparse row-wise</EM>
  3243. storage. Only the non-zero elements of the matrix are stored in a
  3244. row-wise fashion. Row-wise storage is used for several reasons:</P>
  3245. <P>
  3246. <UL>
  3247. <LI> The matrix vector product <CODE>A*x</CODE> is a very common operation,
  3248. efficiently performed with row-wise storage.
  3249. </LI>
  3250. <LI> Row-wise (and column-wise) storage is a very general storage
  3251. scheme that works well for general non-symmetric matrices. There is
  3252. a penalty to pay for storing symmetric matrices in this fashion,
  3253. but it is small.
  3254. </LI>
  3255. </UL>
  3256. </P>
  3257. <P>Rlab does not attempt to out-smart the user by automatically
  3258. converting sparse matrices to dense matrices, or vice-versa. Even
  3259. if the user explicitly fills the a sparse matrix so that the number
  3260. of non-zeros is equal to the full size of the matrix, the sparse
  3261. storage format is retained.</P>
  3262. <P>Certain operations on sparse matrices will return dense
  3263. matrices. For instance, the cosine operation on a sparse matrix
  3264. will create a dense matrix with ones where there used to be zeros. </P>
  3265. <P>Sparse matrices are printed differently than full, or dense
  3266. matrices. Only the non-zero elements are printed, along with their
  3267. row and column values. For example:</P>
  3268. <P>
  3269. <BLOCKQUOTE><CODE>
  3270. <PRE>
  3271. > a = [0, 1, 0;
  3272. >      2, 0, 0;
  3273. >      0, 0, 3];
  3274. > s = sparse(a)
  3275.  (1, 2)                 1
  3276.  (2, 1)                 2
  3277.  (3, 3)                 3
  3278. </PRE>
  3279. </CODE></BLOCKQUOTE>
  3280. </P>
  3281.  
  3282. </DL>
  3283. </P>
  3284.  
  3285. <H2><A NAME="ss7.91">7.91 spconvert </A></H2>
  3286.  
  3287. <P>
  3288. <DL>
  3289. <DT><B> Synopsis </B><DD><P>Convert a full column matrix to sparse storage. </P>
  3290. <DT><B> Syntax </B><DD><P>spconvert ( <EM>A</EM> ) </P>
  3291. <DT><B> Description </B><DD><P>spconvert converts its argument to, or from, the sparse storage
  3292. format. If the argument is a 3 (or 4) column full matrix, the
  3293. argument is converted to sparse storage format. The 1st two columns
  3294. are taken as the row and column indices for the elements in the
  3295. third column. The rows of the input matrix do not have to be in any
  3296. particular order. If there are duplicate elements (same row and
  3297. column number), then they are summed.</P>
  3298. <P>If the argument is a sparse matrix, then it is converted to a full
  3299. matrix with 3 columns. The first two columns being the row and
  3300. column indices of each non-zero element, and the third column in
  3301. the element value (columns 3 and 4 if the matrix is complex).</P>
  3302. <P>Example:</P>
  3303. <P>Create a sparse matrix of zeros with 1000 rows, and 1000 columns</P>
  3304. <P>
  3305. <BLOCKQUOTE><CODE>
  3306. <PRE>
  3307. > s = spconvert ([ 1000, 1000, 0 ])
  3308.  (1000, 1000)                   0
  3309. > show(s);
  3310.         nr                  :   1000
  3311.         nc                  :   1000
  3312.         n                   :   1e+06
  3313.         nnz                 :   1
  3314.         class               :   num
  3315.         type                :   real
  3316.         storage             :   sparse
  3317. </PRE>
  3318. </CODE></BLOCKQUOTE>
  3319. </P>
  3320.  
  3321. </DL>
  3322. </P>
  3323.  
  3324. <H2><A NAME="ss7.92">7.92 sprintf </A></H2>
  3325.  
  3326. <P>
  3327. <DL>
  3328. <DT><B> Synopsis </B><DD><P>Formatted printing to a string.</P>
  3329. <DT><B> Syntax </B><DD><P>sprintf ( <EM>stringvar</EM>, <EM>formatstr</EM>, <EM>VARi</EM> ... ) </P>
  3330. <DT><B> Description </B><DD><P>The RLaB sprintf is a limited feature version of the
  3331. C-language sprintf. The features are limited because RLaB
  3332. does not support all of the data types the C-language does.</P>
  3333. <P>
  3334. <DL>
  3335.  
  3336. <DT><B><EM>stringvar</EM></B><DD><P>The output of sprintf is written to this
  3337. variable.</P>
  3338.  
  3339. <DT><B><EM>formatstr</EM></B><DD><P>A valid sprintf format string.</P>
  3340.  
  3341. <DT><B><EM>VARi</EM></B><DD><P>Are any number of constants or
  3342. variables that match the format string. sprintf
  3343. cannot print out vector, matrix, or list objects as a
  3344. whole. Valid print objects are strings, constants, and
  3345. scalars.</P>
  3346. </DL>
  3347. </P>
  3348.  
  3349. <DT><B>See Also</B><DD><P>printf, fprintf, write, read</P>
  3350.  
  3351. </DL>
  3352. </P>
  3353.  
  3354. <H2><A NAME="ss7.93">7.93 spsolve </A></H2>
  3355.  
  3356. <P>
  3357. <DL>
  3358. <DT><B> Synopsis </B><DD><P>Solve sparse linear equations.</P>
  3359. <DT><B> Syntax </B><DD><P>spsolve ( <EM>A</EM>, <EM>B</EM>, <EM>DIAG_PIVOT</EM>,
  3360. <EM>PERMV</EM> )</P>
  3361. <DT><B> Description </B><DD><P>Solve solves a system of sparse linear equations:</P>
  3362. <P>
  3363. <BLOCKQUOTE>
  3364. <EM>A * X = B</EM>
  3365. </BLOCKQUOTE>
  3366. </P>
  3367. <P>
  3368. <DL>
  3369. <DT><B><EM>A</EM></B><DD><P>is the coefficient matrix.</P>
  3370. <DT><B><EM>B</EM></B><DD><P>is the right hand side.</P>
  3371. <DT><B><EM>DIAG_PIVOT</EM></B><DD><P>specifies the diagonal-pivoting
  3372. threshold. </P>
  3373. <DT><B><EM>PERMV</EM></B><DD><P>is the permutation vector.</P>
  3374. <DT><B><EM>X</EM></B><DD><P>is the solution vector/matrix.</P>
  3375. </DL>
  3376. </P>
  3377. <P>To be finished later...</P>
  3378. <DT><B>See Also</B><DD><P>solve, backsub, factor</P>
  3379.  
  3380. </DL>
  3381. </P>
  3382.  
  3383. <H2><A NAME="ss7.94">7.94 spwrite </A></H2>
  3384.  
  3385. <P>
  3386. <DL>
  3387. <DT><B> Synopsis </B><DD><P>Write a sparse matrix to file.</P>
  3388. <DT><B> Syntax </B><DD><P>spwrite ( <EM>FILENAME</EM> , <EM>SPM</EM>  )</P>
  3389. <DT><B> Syntax </B><DD><P>spwrite ( <EM>FILENAME</EM> , <EM>SPM</EM> , <EM>FORMAT</EM> )</P>
  3390. <DT><B> Description </B><DD><P>The spwrite function takes at least two arguments. The 1st
  3391. argument is the string that identifies the file to write to.
  3392. The file is opened with write permission, destroying any
  3393. pre-existing contents. The file closed after the matrix is
  3394. written.</P>
  3395. <P>The default format for the sparse matrix is the internal
  3396. storage format: compressed row-wise storage. See the Rlab
  3397. Reference Manual for more explanation of this storage format.</P>
  3398. <P>A third, and optional argument, is a string specifying either
  3399. the default, or an optional output format. The value of the
  3400. string can be either <CODE>"sparse"</CODE> (default) or
  3401. <CODE>"graph"</CODE>. The graph output is a file suitable for use
  3402. with the Metis or Chaco graph partitioning/re-ordering
  3403. software. </P>
  3404.  
  3405. <DT><B>See Also</B><DD><P>write</P>
  3406.  
  3407. </DL>
  3408. </P>
  3409.  
  3410. <H2><A NAME="ss7.95">7.95 sqrt </A></H2>
  3411.  
  3412. <P>
  3413. <DL>
  3414. <DT><B> Synopsis </B><DD><P>Compute the square root.</P>
  3415. <DT><B> Syntax </B><DD><P>sqrt ( <EM>A</EM> )</P>
  3416. <DT><B> Description </B><DD><P>Sqrt returns the square-root of it's argument. If the argument
  3417. is a matrix, then an element-by-element square-root operation
  3418. is performed.</P>
  3419. <P><CODE>sqrt(-1)</CODE> will produce <CODE>1i</CODE>.</P>
  3420.  
  3421. </DL>
  3422. </P>
  3423.  
  3424. <H2><A NAME="ss7.96">7.96 srand </A></H2>
  3425.  
  3426. <P>
  3427. <DL>
  3428. <DT><B> Synopsis </B><DD><P>Seed the random number generator.</P>
  3429. <DT><B> Syntax </B><DD><P>srand ( ) </P>
  3430. <P>    srand ( <EM>A</EM> )</P>
  3431. <P>    srand ( <EM>SEED</EM> )</P>
  3432. <DT><B> Description </B><DD><P>Srand sets the seed for the random number generator.
  3433. <CODE>srand()</CODE> sets the seed to the original value (the last
  3434. value given to srand, or the default value, 1).</P>
  3435. <P><CODE>srand( "clock" )</CODE>' sets the seed based upon the machines
  3436. clock value. This provides users a way of picking a unique
  3437. seed each time.</P>
  3438. <P>Srand uses the RANLIB subroutine SETALL.</P>
  3439.  
  3440. <DT><B>See Also</B><DD><P>rand</P>
  3441.  
  3442. </DL>
  3443. </P>
  3444.  
  3445. <H2><A NAME="ss7.97">7.97 strsplt </A></H2>
  3446.  
  3447. <P>
  3448. <DL>
  3449. <DT><B> Synopsis </B><DD><P>Split a string.</P>
  3450. <DT><B> Syntax </B><DD><P>strsplt ( <EM>STR</EM> )</P>
  3451. <P>    strsplt ( <EM>STR</EM>, <EM>FW</EM> )</P>
  3452. <DT><B> Description </B><DD><P>Strsplt returns a row matrix that contains a single character
  3453. string as each element. The resulting matrix has as many
  3454. columns as the input argument had characters.</P>
  3455. <P>Example:</P>
  3456. <P>
  3457. <BLOCKQUOTE><CODE>
  3458. <PRE>
  3459. > smat = strsplt( "string" )
  3460.  smat =
  3461. s  t  r  i  n  g  
  3462. > show(smat)
  3463.    name:      smat    
  3464.    class:     matrix  
  3465.    type:      string  
  3466.      nr:      1       
  3467.      nc:      6       
  3468. </PRE>
  3469. </CODE></BLOCKQUOTE>
  3470. </P>
  3471. <P>The second, and optional, argument to strsplt, <EM>FW</EM> forces
  3472. strsplt to split <EM>STR</EM> into <EM>FW</EM> length strings.</P>
  3473. <P><EM>FW</EM> can also be a string, or a string matrix, specifying
  3474. the field separators that strsplt will use:</P>
  3475. <P>
  3476. <BLOCKQUOTE><CODE>
  3477. <PRE>
  3478. > str = "this;is;a;sem-colon;separated string;with numbers;1.234"
  3479. this;is;a;sem-colon;separated string;with numbers;1.234  
  3480.  
  3481. > strsplt(str,";")
  3482. this              is                a                 sem-colon         
  3483.  
  3484. separated string  with numbers      1.234             
  3485. </PRE>
  3486. </CODE></BLOCKQUOTE>
  3487. </P>
  3488.  
  3489. <DT><B>See also</B><DD><P>getline</P>
  3490.  
  3491. </DL>
  3492. </P>
  3493.  
  3494. <H2><A NAME="ss7.98">7.98 strtod </A></H2>
  3495.  
  3496. <P>
  3497. <DL>
  3498. <DT><B> Synopsis </B><DD><P>String to decimal conversion.</P>
  3499. <DT><B> Syntax </B><DD><P>strtod ( <EM>STR</EM> )</P>
  3500. <DT><B> Description </B><DD><P>The strtod functions converts its argument, <EM>STR</EM>, from
  3501. string class to numeric class. Strtod stands for STRing TO
  3502. Decimal.</P>
  3503. <P>Strtod will return a NaN (Not a Number) if it cannot recognize
  3504. a string, or an element of a string matrix, as a number.</P>
  3505.  
  3506. </DL>
  3507. </P>
  3508.  
  3509. <H2><A NAME="ss7.99">7.99 sum </A></H2>
  3510.  
  3511. <P>
  3512. <DL>
  3513. <DT><B> Synopsis </B><DD><P>Sum the elements of a matrix.</P>
  3514. <DT><B> Syntax </B><DD><P>sum ( <EM>A</EM> ) </P>
  3515. <DT><B> Description </B><DD><P>Sum computes the sum of a matrix. The return object is a row
  3516. matrix which contains the sum of each column of the input.</P>
  3517. <P>If the input is a vector (row-matrix) then the sum of the
  3518. elements is returned. </P>
  3519.  
  3520. </DL>
  3521. </P>
  3522.  
  3523. <H2><A NAME="ss7.100">7.100 svd </A></H2>
  3524.  
  3525. <P>
  3526. <DL>
  3527. <DT><B> Synopsis </B><DD><P>Singular Value Decomposition</P>
  3528. <DT><B> Syntax </B><DD><P>svd ( <EM>A</EM> ) </P>
  3529. <P>    svd ( <EM>A</EM>, <EM>TYPE</EM> )</P>
  3530. <DT><B> Description </B><DD><P>Computes the singular values of the input matrix <EM>A</EM>, as
  3531. well as the right and left singular vectors in various
  3532. forms. Where:</P>
  3533. <P>
  3534. <BLOCKQUOTE><CODE>
  3535. <PRE>
  3536. A = U * diag (sigma) * Vt
  3537. </PRE>
  3538. </CODE></BLOCKQUOTE>
  3539. </P>
  3540. <P>The output is a list containing the three afore-mentioned
  3541. objects (<EM>u</EM>, <EM>sigma</EM>, <EM>vt</EM>).  Various forms of
  3542. the right and left singular vectors can be computed, depending
  3543. upon the value of the second, optional, string argument
  3544. <EM>TYPE</EM>:</P>
  3545. <P>
  3546. <DL>
  3547.  
  3548. <DT><B><CODE>S</CODE></B><DD><P>A minimal version of <CODE>U</CODE>, and
  3549. <CODE>Vt</CODE> are returned.  This is the default.</P>
  3550.  
  3551. <DT><B><CODE>A</CODE></B><DD><P>The full <CODE>U</CODE>, and <CODE>Vt</CODE> are
  3552. returned.</P>
  3553.  
  3554. <DT><B><CODE>N</CODE></B><DD><P><CODE>U</CODE> and <CODE>Vt</CODE> are not computed,
  3555. empty <CODE>U</CODE> and <CODE>Vt</CODE> are returned.</P>
  3556. </DL>
  3557. </P>
  3558. <P>The LAPACK subroutine DGESVD, or ZGESVD is used to perform the
  3559. computation.</P>
  3560. <P>Example:</P>
  3561. <P>
  3562. <BLOCKQUOTE><CODE>
  3563. <PRE>
  3564. > A = [0.96, 1.72; 2.28, 0.96];
  3565. > Asvd = svd(A)
  3566.    sigma        u            vt
  3567. > Asvd.vt
  3568.  matrix columns 1 thru 2
  3569.         -0.8        -0.6
  3570.          0.6        -0.8
  3571. > Asvd.u
  3572.  matrix columns 1 thru 2
  3573.         -0.6        -0.8
  3574.         -0.8         0.6
  3575. > Asvd.sigma
  3576.  vector elements 1 thru 2
  3577.            3           1
  3578. > check = Asvd.u * diag(Asvd.sigma) * Asvd.vt
  3579.  check =
  3580.  matrix columns 1 thru 2
  3581.         0.96        1.72
  3582.         2.28        0.96
  3583. </PRE>
  3584. </CODE></BLOCKQUOTE>
  3585. </P>
  3586.  
  3587. </DL>
  3588. </P>
  3589.  
  3590. <H2><A NAME="ss7.101">7.101 system </A></H2>
  3591.  
  3592. <P>
  3593. <DL>
  3594. <DT><B> Synopsis </B><DD><P>Execute operating system commands.</P>
  3595. <DT><B> Syntax </B><DD><P>system ( <EM>COMMAND</EM> ) </P>
  3596. <DT><B> Description </B><DD><P>The system function behaves like the the UNIX system call. The
  3597. string argument to system, <EM>COMMAND</EM>, is passed directly
  3598. to the bourne-shell for execution. The program waits until the
  3599. system call is finished.</P>
  3600. <P>Example:
  3601. <BLOCKQUOTE><CODE>
  3602. <PRE>
  3603. > system( "vi test.r" )
  3604. </PRE>
  3605. </CODE></BLOCKQUOTE>
  3606. </P>
  3607. <P>will allow the user to edit (create) the file
  3608. <CODE>test.r</CODE>. When the vi process is finished the user will
  3609. be back at the RLaB prompt.</P>
  3610. <P>
  3611. <BLOCKQUOTE><CODE>
  3612. <PRE>
  3613. > rfile test
  3614. </PRE>
  3615. </CODE></BLOCKQUOTE>
  3616. </P>
  3617. <P>will then load the result of the vi process.</P>
  3618.  
  3619. </DL>
  3620. </P>
  3621.  
  3622. <H2><A NAME="ss7.102">7.102 trig </A></H2>
  3623.  
  3624. <P>
  3625. <DL>
  3626. <DT><B> Synopsis </B><DD><P>Compute the tangent.</P>
  3627. <DT><B> Syntax </B><DD><P>tan ( <EM>A</EM> ) </P>
  3628. <DT><B> Description </B><DD><P>RLaB trigonometric functions are designed to take scalars, and
  3629. matrices as arguments. The return value is the input argument
  3630. with the trigonometric operation performed element by element.</P>
  3631. <P>All the trigonometric functions use the C language math
  3632. library functions, so details about the ranges and error
  3633. conditions can be found by examining the appropriate man pages
  3634. on your system.</P>
  3635.  
  3636. </DL>
  3637. </P>
  3638.  
  3639. <H2><A NAME="ss7.103">7.103 tic </A></H2>
  3640.  
  3641. <P>
  3642. <DL>
  3643. <DT><B> Synopsis </B><DD><P>Start the timer.</P>
  3644. <DT><B> Syntax </B><DD><P>tic ( ) </P>
  3645. <DT><B> Description </B><DD><P>Tic internally marks the time at which it was invoked. To
  3646. measure elapsed time, use tic in conjunction with toc.</P>
  3647. <P>Example:
  3648. <BLOCKQUOTE><CODE>
  3649. <PRE>
  3650. tic();
  3651. a = rand(100,100);
  3652. eig(a);
  3653. toc()
  3654. </PRE>
  3655. </CODE></BLOCKQUOTE>
  3656. </P>
  3657. <P>The above would measure the time spent generating the 100x100
  3658. random matrix, and calculating the eigenvectors and values.</P>
  3659.  
  3660. <DT><B>See Also</B><DD><P>toc</P>
  3661.  
  3662. </DL>
  3663. </P>
  3664.  
  3665. <H2><A NAME="ss7.104">7.104 tmpnam </A></H2>
  3666.  
  3667. <P>
  3668. <DL>
  3669. <DT><B> Synopsis </B><DD><P>Generate temporary file name.</P>
  3670. <DT><B> Syntax </B><DD><P>tmpnam ( ) </P>
  3671. <DT><B> Description </B><DD><P>tmpnam returns a string that is not the name of an existing
  3672. file. tmpnam generates a different name each time it is
  3673. called. The string tmpnam returns can be used a a filename
  3674. with RLaB's file I/O functions.</P>
  3675.  
  3676. <DT><B>See Also</B><DD><P>open, close, read, write, fprintf</P>
  3677.  
  3678. </DL>
  3679. </P>
  3680.  
  3681. <H2><A NAME="ss7.105">7.105 toc </A></H2>
  3682.  
  3683. <P>
  3684. <DL>
  3685. <DT><B> Synopsis </B><DD><P>Measure time elapsed since tic.</P>
  3686. <DT><B> Syntax </B><DD><P>toc ( )</P>
  3687. <DT><B> Description </B><DD><P>Toc reports the time (in seconds) elapsed since the last call
  3688. to tic.</P>
  3689. <P>See also: tic</P>
  3690.  
  3691. </DL>
  3692. </P>
  3693.  
  3694. <H2><A NAME="ss7.106">7.106 type </A></H2>
  3695.  
  3696. <P>
  3697. <DL>
  3698. <DT><B> Synopsis </B><DD><P>Return the type of an object.</P>
  3699. <DT><B> Syntax </B><DD><P>type ( <EM>A</EM> )</P>
  3700. <DT><B> Description </B><DD><P>Type returns a string that describes the type of element
  3701. contained in object <EM>A</EM>. The valid types for an object
  3702. vary according to the class of the object</P>
  3703. <P>If a list object has a string member with name <CODE>type</CODE>,
  3704. then the type function will report the contents of that
  3705. member.</P>
  3706.  
  3707. <DT><B>See Also</B><DD><P>class, show</P>
  3708.  
  3709. </DL>
  3710. </P>
  3711.  
  3712. <H2><A NAME="ss7.107">7.107 vpnorm</A></H2>
  3713.  
  3714. <P>
  3715. <DL>
  3716. <DT><B> Synopsis </B><DD><P>Compute the vector <EM>P</EM> norm.</P>
  3717. <DT><B> Syntax   </B><DD><P>vpnorm ( <EM>V</EM> , <EM>P</EM> )</P>
  3718.  
  3719. <DT><B> Description </B><DD><P><CODE>vpnorm</CODE> computes the vector P-norm of <EM>V</EM>. The
  3720. second argument is required, and specifies the value of
  3721. <EM>P</EM>.</P>
  3722. <P>A small Rlab program demonstrating the P-norm computation is
  3723. provided below. However, <CODE>vpnorm</CODE> is implemented as a
  3724. builtin function for maximum efficiency. </P>
  3725. <P>
  3726. <HR>
  3727. <PRE>
  3728. pnorm = function ( V , P )
  3729. {
  3730.   return (sum ( V.^P )).^(1/P);
  3731. }
  3732.         
  3733. </PRE>
  3734. <HR>
  3735. </P>
  3736.  
  3737. </DL>
  3738. </P>
  3739.  
  3740. <H2><A NAME="ss7.108">7.108 writeb </A></H2>
  3741.  
  3742. <P>
  3743. <DL>
  3744. <DT><B> Synopsis </B><DD><P>Write object(s) to file.</P>
  3745. <DT><B> Syntax </B><DD><P>write ( <EM>FILENAME</EM> , <EM>A</EM> , <EM>b</EM> , ... )</P>
  3746. <DT><B> Description </B><DD><P>The write function takes at least two arguments. The 1st
  3747. argument is the string that identifies the file to write to.
  3748. The file is opened with write permission, destroying any
  3749. pre-existing contents. The file is left open so that
  3750. subsequent writes will append to the file, and not destroy the
  3751. contents.</P>
  3752. <P>The arguments after the file name are the objects that will
  3753. be written. All objects are written in RLaB binary format.</P>
  3754. <P>Example:</P>
  3755. <P>
  3756. <BLOCKQUOTE><CODE>
  3757. <PRE>
  3758. writeb ( "filename", a , b , c );
  3759. </PRE>
  3760. </CODE></BLOCKQUOTE>
  3761. </P>
  3762. <P>Will open the file named <CODE>filename</CODE> in write mode, and
  3763. write the contents of the variables <CODE>a</CODE>, <CODE>b</CODE>, and
  3764. <CODE>c</CODE>.</P>
  3765. <P>The matrix format that write uses is compatible with MATLAB's
  3766. matrix format. As long as the file only contains matrices,
  3767. MATLAB should be able to read RLaB binary output.</P>
  3768.  
  3769. <DT><B>See Also</B><DD><P>close, readb</P>
  3770.  
  3771. </DL>
  3772. </P>
  3773.  
  3774. <H2><A NAME="ss7.109">7.109 writem </A></H2>
  3775.  
  3776. <P>
  3777. <DL>
  3778. <DT><B> Synopsis </B><DD><P>Write a matrix in ASCII format.</P>
  3779. <DT><B> Syntax </B><DD><P>writem ( <CODE>"filename"</CODE> , <EM>A</EM> )</P>
  3780. <DT><B> Description </B><DD>
  3781. <P>Writem is the counterpart to readm. Writem writes the matrix
  3782. <EM>A</EM> to the file denoted by the 1st argument in a generic format.</P>
  3783. <P>The format used is:</P>
  3784. <P>
  3785. <BLOCKQUOTE><CODE>
  3786. <PRE>
  3787. line 1:         value[1;1]    ... value[1;ncol] \n
  3788. line nrow:      value[nrow;1] ... value[nrow;ncol] \n
  3789.         
  3790. </PRE>
  3791. </CODE></BLOCKQUOTE>
  3792. </P>
  3793. <P>Writem will write real and complex numeric matrices, as well
  3794. as string matrices even though readm can only read real numeric
  3795. matrices. </P>
  3796. <P>Writem does not close the file after writing <EM>A</EM>. The file is
  3797. left open for further writes if necessary. Close can be called
  3798. to explicitly close the file.</P>
  3799.  
  3800. <DT><B>See Also</B><DD><P>close, getline, open, readm, write</P>
  3801.  
  3802.  
  3803. </DL>
  3804. </P>
  3805.  
  3806. <H2><A NAME="ss7.110">7.110 zeros </A></H2>
  3807.  
  3808. <P>
  3809. <DL>
  3810. <DT><B> Synopsis </B><DD><P>Create a matrix of zeros</P>
  3811. <DT><B> Syntax </B><DD><P>zeros ( <EM>nrow</EM>, <EM>ncol</EM> )</P>
  3812. <P>    zeros ( [ <EM>nrow</EM>, <EM>ncol</EM> ] )</P>
  3813. <DT><B> Description </B><DD><P>Zeros returns a matrix with all zero elements. If the
  3814. arguments are two scalars, then zeros returns a matrix with
  3815. dimensions <EM>nrow</EM>x<EM>ncol</EM>.</P>
  3816. <P>If the argument is a MATRIX, then zeros returns a matrix with
  3817. dimensions m<F>1</F> by m<F>2</F>.</P>
  3818. <P>Examples:
  3819. <BLOCKQUOTE><CODE>
  3820. <PRE>
  3821. > Z = zeros( 3 , 3 );
  3822. > A = rand([10,4]);
  3823. > B = zeros( size(A) )
  3824. </PRE>
  3825. </CODE></BLOCKQUOTE>
  3826. </P>
  3827.  
  3828. <DT><B>See Also</B><DD><P>size</P>
  3829.  
  3830. </DL>
  3831. </P>
  3832.  
  3833.  
  3834.  
  3835. <HR>
  3836. <A HREF="rlab-ref-6.html"><IMG SRC="prev.gif" ALT="Previous"></A>
  3837. <A HREF="rlab-ref-8.html"><IMG SRC="next.gif" ALT="Next"></A>
  3838. <A HREF="rlab-ref.html#toc7"><IMG SRC="toc.gif" ALT="Contents"></A>
  3839. </BODY>
  3840. </HTML>
  3841.