linalg.tex 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082
  1. \section{Linear Algebra package}
  2. \begin{Introduction}{Linear Algebra package}
  3. This section briefly describes what's available in the Linear Algebra
  4. package.
  5. Note on examples: In the examples throughout this
  6. document, the matrix A will be
  7. \begin{verbatim}
  8. [1 2 3]
  9. [4 5 6]
  10. [7 8 9].
  11. \end{verbatim}
  12. The functions can be divided into four categories:
  13. {\bf Basic matrix handling}
  14. \nameref{add\_columns},
  15. \nameref{add\_rows},
  16. \nameref{add\_to\_columns},
  17. \nameref{add\_to\_rows},
  18. \nameref{augment\_columns},
  19. \nameref{char\_poly},
  20. \nameref{column\_dim},
  21. \nameref{copy\_into},
  22. \nameref{diagonal},
  23. \nameref{extend},
  24. \nameref{find\_companion},
  25. \nameref{get\_columns},
  26. \nameref{get\_rows},
  27. \nameref{hermitian\_tp},
  28. \nameref{matrix\_augment},
  29. \nameref{matrix\_stack} ,
  30. \nameref{minor},
  31. \nameref{mult\_columns},
  32. \nameref{mult\_rows},
  33. \nameref{pivot},
  34. \nameref{remove\_columns},
  35. \nameref{remove\_rows},
  36. \nameref{row\_dim},
  37. \nameref{rows\_pivot},
  38. \nameref{stack\_rows},
  39. \nameref{sub\_matrix},
  40. \nameref{swap\_columns},
  41. \nameref{swap\_entries},
  42. \nameref{swap\_rows}.
  43. {\bf Constructors -- functions that create matrices}
  44. \nameref{band\_matrix},
  45. \nameref{block\_matrix},
  46. \nameref{char\_matrix},
  47. \nameref{coeff\_matrix},
  48. \nameref{companion},
  49. \nameref{hessian},
  50. \nameref{hilbert},
  51. \nameref{jacobian},
  52. \nameref{jordan\_block},
  53. \nameref{make\_identity},
  54. \nameref{random\_matrix},
  55. \nameref{toeplitz},
  56. \nameref{vandermonde}.
  57. {\bf High level algorithms}
  58. \nameref{char\_poly},
  59. \nameref{cholesky},
  60. \nameref{gram\_schmidt},
  61. \nameref{lu\_decom},
  62. \nameref{pseudo\_inverse},
  63. \nameref{simplex},
  64. \nameref{svd}.
  65. {\bf Normal Forms}
  66. There is a separate package, NORMFORM, for computing
  67. the following matrix normal forms in \REDUCE:
  68. \nameref{smithex},
  69. \nameref{smithex\_int},
  70. \nameref{frobenius},
  71. \nameref{ratjordan},
  72. \nameref{jordansymbolic},
  73. \nameref{jordan}.
  74. {\bf Predicates}
  75. \nameref{matrixp},
  76. \nameref{squarep},
  77. \nameref{symmetricp}.
  78. \end{Introduction}
  79. \begin{Switch}{fast_la}
  80. By turning the \name{fast\_la} switch on, the speed of the following
  81. functions will be increased:
  82. \nameref{add\_columns},
  83. \nameref{add\_rows},
  84. \nameref{augment\_columns},
  85. \nameref{column\_dim},
  86. \nameref{copy\_into},
  87. \nameref{make\_identity},
  88. \nameref{matrix\_augment},
  89. \nameref{matrix\_stack},
  90. \nameref{minor},
  91. \nameref{mult\_columns},
  92. \nameref{mult\_rows},
  93. \nameref{pivot},
  94. \nameref{remove\_columns},
  95. \nameref{remove\_rows},
  96. \nameref{rows\_pivot},
  97. \nameref{squarep},
  98. \nameref{stack\_rows},
  99. \nameref{sub\_matrix},
  100. \nameref{swap\_columns},
  101. \nameref{swap\_entries},
  102. \nameref{swap\_rows},
  103. \nameref{symmetricp}.
  104. The increase in speed will be negligible unless you are making a
  105. significant number (i.e. thousands) of calls. When using this switch,
  106. error checking is minimized. This means that illegal input may give
  107. strange error messages. Beware.
  108. \end{Switch}
  109. \begin{Operator}{add_columns}
  110. Add columns, add rows:
  111. \begin{Syntax}
  112. \name{add\_columns}\(\meta{matrix},\meta{c1},\meta{c2},\meta{expr}\)
  113. \end{Syntax}
  114. \meta{matrix} :- a \nameref{matrix}.
  115. \meta{c1},\meta{c2} :- positive integers.
  116. \meta{expr} :- a scalar expression.
  117. The Operator \name{add\_columns} replaces column \meta{\meta{c2}} of
  118. \meta{matrix} by \meta{expr} * column(\meta{matrix},\meta{c1}) +
  119. column(\meta{matrix},\meta{c2}).
  120. \name{add\_rows} performs the equivalent task on the rows of
  121. \meta{matrix}.
  122. \begin{Examples}
  123. add_columns(A,1,2,x); &
  124. \begin{multilineoutput}{6cm}
  125. [1 x + 2 3]
  126. [ ]
  127. [4 4*x + 5 6]
  128. [ ]
  129. [7 7*x + 8 9]
  130. \end{multilineoutput} \\
  131. add_rows(A,2,3,5); &
  132. \begin{multilineoutput}{6cm}
  133. [1 2 3 ]
  134. [ ]
  135. [4 5 6 ]
  136. [ ]
  137. [27 33 39]
  138. \end{multilineoutput} \\
  139. \end{Examples}
  140. Related functions: \nameref{add\_to\_columns},
  141. \nameref{add\_to\_rows}, \nameref{mult\_columns},
  142. \nameref{mult\_rows}.
  143. \end{Operator}
  144. \begin{Operator}{add_rows}
  145. see: \nameref{add\_columns}.
  146. \end{Operator}
  147. \begin{Operator}{add_to_columns}
  148. Add to columns, add to rows:
  149. \begin{Syntax}
  150. \name{add\_to\_columns}\(\meta{matrix},\meta{column\_list},\meta{expr}\)
  151. \end{Syntax}
  152. \meta{matrix} :- a matrix.
  153. \meta{column\_list} :- a positive integer or a list of positive
  154. integers.
  155. \meta{expr} :- a scalar expression.
  156. \name{add\_to\_columns} adds \meta{expr} to each column specified in
  157. \meta{column\_list} of \meta{matrix}.
  158. \name{add\_to\_rows} performs the equivalent task on the rows of
  159. \meta{matrix}.
  160. \begin{Examples}
  161. add_to_columns(A,\{1,2\},10); &
  162. \begin{multilineoutput}{6cm}
  163. [11 12 3]
  164. [ ]
  165. [14 15 6]
  166. [ ]
  167. [17 18 9]
  168. \end{multilineoutput}\\
  169. add_to_rows(A,2,-x) &
  170. \begin{multilineoutput}{6cm}
  171. [ 1 2 3 ]
  172. [ ]
  173. [ - x + 4 - x + 5 - x + 6]
  174. [ ]
  175. [ 7 8 9 ]
  176. \end{multilineoutput} \\
  177. \end{Examples}
  178. Related functions:
  179. \nameref{add\_columns}, \nameref{add\_rows}, \nameref{mult\_rows},
  180. \nameref{mult\_columns}.
  181. \end{Operator}
  182. \begin{Operator}{add_to_rows}
  183. see: \nameref{add\_to\_columns}.
  184. \end{Operator}
  185. \begin{Operator}{augment_columns}
  186. Augment columns, stack rows:
  187. \begin{Syntax}
  188. \name{augment\_columns}(\meta{matrix},\meta{column\_list})
  189. \end{Syntax}
  190. \meta{matrix} :- a matrix.
  191. \meta{column\_list} :- either a positive integer or a list of positive
  192. integers.
  193. \name{augment\_columns} gets hold of the columns of \meta{matrix}
  194. specified in \name{column\_list} and sticks them together.
  195. \name{stack\_rows} performs the same task on rows of \meta{matrix}.
  196. \begin{Examples}
  197. augment_columns(A,\{1,2\}) &
  198. \begin{multilineoutput}{6cm}
  199. [1 2]
  200. [ ]
  201. [4 5]
  202. [ ]
  203. [7 8]
  204. \end{multilineoutput} \\
  205. stack_rows(A,\{1,3\}) &
  206. \begin{multilineoutput}{6cm}
  207. [1 2 3]
  208. [ ]
  209. [7 8 9]
  210. \end{multilineoutput} \\
  211. \end{Examples}
  212. Related functions:
  213. \nameref{get\_columns}, \nameref{get\_rows}, \nameref{sub\_matrix}.
  214. \end{Operator}
  215. \begin{Operator}{band_matrix}
  216. \begin{Syntax}
  217. \name{band\_matrix}(\meta{expr\_list},\meta{square\_size})
  218. \end{Syntax}
  219. \meta{expr\_list} :- either a single scalar expression or a list of
  220. an odd number of scalar expressions.
  221. \meta{square\_size} :- a positive integer.
  222. \name{band\_matrix} creates a square matrix of dimension
  223. \meta{square\_size}. The diagonal consists of the middle expression
  224. of the \meta{expr\_list}. The expressions to the left of this fill
  225. the required number of sub\_diagonals and the expressions to the right
  226. the super\_diagonals.
  227. \begin{Examples}
  228. band_matrix(\{x,y,z\},6) &
  229. \begin{multilineoutput}{6cm}
  230. [y z 0 0 0 0]
  231. [ ]
  232. [x y z 0 0 0]
  233. [ ]
  234. [0 x y z 0 0]
  235. [ ]
  236. [0 0 x y z 0]
  237. [ ]
  238. [0 0 0 x y z]
  239. [ ]
  240. [0 0 0 0 x y]
  241. \end{multilineoutput} \\
  242. \end{Examples}
  243. Related functions: \nameref{diagonal}.
  244. \end{Operator}
  245. \begin{Operator}{block_matrix}
  246. \begin{Syntax}
  247. \name{block\_matrix}(\meta{r},\meta{c},\meta{matrix\_list})
  248. \end{Syntax}
  249. \meta{r},\meta{c} :- positive integers.
  250. \meta{matrix\_list} :- a list of matrices.
  251. \name{block\_matrix} creates a matrix that consists of \meta{r} by
  252. \meta{c} matrices filled from the \meta{matrix\_list} row wise.
  253. \begin{Examples}
  254. B := make_identity(2); &
  255. \begin{multilineoutput}{6cm}
  256. [1 0]
  257. b := [ ]
  258. [0 1]
  259. \end{multilineoutput} \\
  260. C := mat((5),(5)); &
  261. \begin{multilineoutput}{6cm}
  262. [5]
  263. c := [ ]
  264. [5]
  265. \end{multilineoutput} \\
  266. D := mat((22,33),(44,55)); &
  267. \begin{multilineoutput}{6cm}
  268. [22 33]
  269. d := [ ]
  270. [44 55]
  271. \end{multilineoutput} \\
  272. block_matrix(2,3,\{B,C,D,D,C,B\}); &
  273. \begin{multilineoutput}{6cm}
  274. [1 0 5 22 33]
  275. [ ]
  276. [0 1 5 44 55]
  277. [ ]
  278. [22 33 5 1 0 ]
  279. [ ]
  280. [44 55 5 0 1 ]
  281. \end{multilineoutput} \\
  282. \end{Examples}
  283. \end{Operator}
  284. \begin{Operator}{char_matrix}
  285. \begin{Syntax}
  286. \name{char\_matrix}(\meta{matrix},\meta{lambda})
  287. \end{Syntax}
  288. \meta{matrix} :- a square matrix.
  289. \meta{lambda} :- a symbol or algebraic expression.
  290. \meta{char\_matrix} creates the characteristic matrix C of
  291. \meta{matrix}.
  292. This is C = \meta{lambda} * Id - A.
  293. Id is the identity matrix.
  294. \begin{Examples}
  295. char_matrix(A,x); &
  296. \begin{multilineoutput}{6cm}
  297. [x - 1 -2 -3 ]
  298. [ ]
  299. [ -4 x - 5 -6 ]
  300. [ ]
  301. [ -7 -8 x - 9]
  302. \end{multilineoutput} \\
  303. \end{Examples}
  304. Related functions: \nameref{char\_poly}.
  305. \end{Operator}
  306. \begin{Operator}{char_poly}
  307. \begin{Syntax}
  308. \name{char\_poly}(\meta{matrix},\meta{lambda})
  309. \end{Syntax}
  310. \meta{matrix} :- a square matrix.
  311. \meta{lambda} :- a symbol or algebraic expression.
  312. \name{char\_poly} finds the characteristic polynomial of \meta{matrix}.
  313. This is the determinant of \meta{lambda} * Id - A.
  314. Id is the identity matrix.
  315. \begin{Examples}
  316. char_poly(A,x); &
  317. x^3-15*x^2-18*x
  318. \end{Examples}
  319. Related functions: \nameref{char\_matrix}.
  320. \end{Operator}
  321. \begin{Operator}{cholesky}
  322. \begin{Syntax}
  323. \name{cholesky}(\meta{matrix})
  324. \end{Syntax}
  325. \meta{matrix} :- a positive definite matrix containing numeric entries.
  326. \name{cholesky} computes the cholesky decomposition of \meta{matrix}.
  327. It returns \{L,U\} where L is a lower matrix, U is an upper matrix,
  328. A = LU, and U = $L^T$.
  329. \begin{Examples}
  330. F := mat((1,1,0),(1,3,1),(0,1,1)); &
  331. \begin{multilineoutput}{6cm}
  332. [1 1 0]
  333. [ ]
  334. f := [1 3 1]
  335. [ ]
  336. [0 1 1]
  337. \end{multilineoutput} \\
  338. on rounded; \\
  339. cholesky(F); &
  340. \begin{multilineoutput}{6cm}
  341. \{
  342. [1 0 0 ]
  343. [ ]
  344. [1 1.41421356237 0 ]
  345. [ ]
  346. [0 0.707106781187 0.707106781187]
  347. ,
  348. [1 1 0 ]
  349. [ ]
  350. [0 1.41421356237 0.707106781187]
  351. [ ]
  352. [0 0 0.707106781187]
  353. \}
  354. \end{multilineoutput} \\
  355. \end{Examples}
  356. Related functions: \nameref{lu\_decom}.
  357. \end{Operator}
  358. \begin{Operator}{coeff_matrix}
  359. \begin{Syntax}
  360. \name{coeff\_matrix}(\{\meta{lineq\_list}\})
  361. \end{Syntax}
  362. (If you are feeling lazy then the braces can be omitted.)
  363. \meta{lineq\_list} :- linear equations. Can be of the form equation = number
  364. or just equation.
  365. \name{coeff\_matrix} creates the coefficient matrix C of the linear
  366. equations.
  367. It returns \{C,X,B\} such that CX = B.
  368. \begin{Examples}
  369. coeff_matrix(\{x+y+4*z=10,y+x-z=20,x+y+4\}); &
  370. \begin{multilineoutput}{6cm}
  371. \{
  372. [4 1 1]
  373. [ ]
  374. [-1 1 1]
  375. [ ]
  376. [0 1 1]
  377. ,
  378. [z]
  379. [ ]
  380. [y]
  381. [ ]
  382. [x]
  383. ,
  384. [10]
  385. [ ]
  386. [20]
  387. [ ]
  388. [-4]
  389. \}
  390. \end{multilineoutput} \\
  391. \end{Examples}
  392. \end{Operator}
  393. \begin{Operator}{column_dim}
  394. Column dimension, row dimension:
  395. \begin{Syntax}
  396. \name{column\_dim}(\meta{matrix})
  397. \end{Syntax}
  398. \meta{matrix} :- a matrix.
  399. \name{column\_dim} finds the column dimension of \meta{matrix}.
  400. \name{row\_dim} finds the row dimension of \meta{matrix}.
  401. \begin{Examples}
  402. column_dim(A); &
  403. 3 \\
  404. row_dim(A); &
  405. 3 \\
  406. \end{Examples}
  407. \end{Operator}
  408. \begin{Operator}{companion}
  409. \begin{Syntax}
  410. \name{companion}(\meta{poly},\meta{x})
  411. \end{Syntax}
  412. \meta{poly} :- a monic univariate polynomial in \meta{x}.
  413. \meta{x} :- the variable.
  414. \name{companion} creates the companion matrix C of \meta{poly}.
  415. This is the square matrix of dimension n, where n is the degree of
  416. \meta{poly} w.r.t. \meta{x}.
  417. The entries of C are:
  418. C(i,n) = -coeffn(\meta{poly},\meta{x},i-1) for i = 1
  419. \ldots n, C(i,i-1) = 1 for i = 2 \ldots n and
  420. the rest are 0.
  421. \begin{Examples}
  422. companion(x^4+17*x^3-9*x^2+11,x); &
  423. \begin{multilineoutput}{6cm}
  424. [0 0 0 -11]
  425. [ ]
  426. [1 0 0 0 ]
  427. [ ]
  428. [0 1 0 9 ]
  429. [ ]
  430. [0 0 1 -17]
  431. \end{multilineoutput} \\
  432. \end{Examples}
  433. Related functions:
  434. \nameref{find\_companion}.
  435. \end{Operator}
  436. \begin{Operator}{copy_into}
  437. \begin{Syntax}
  438. \name{copy\_into}(\meta{A},\meta{B},\meta{r},\meta{c})
  439. \end{Syntax}
  440. \meta{A},\meta{B} :- matrices.
  441. \meta{r},\meta{c} :- positive integers.
  442. \name{copy\_into} copies matrix \meta{matrix} into \meta{B} with
  443. \meta{matrix}(1,1) at \meta{B}(\meta{r},\meta{c}).
  444. \begin{Examples}
  445. G := mat((0,0,0,0,0),(0,0,0,0,0),(0,0,0,0,0),(0,0,0,0,0),(0,0,0,0,0)); &
  446. \begin{multilineoutput}{6cm}
  447. [0 0 0 0 0]
  448. [ ]
  449. [0 0 0 0 0]
  450. [ ]
  451. g := [0 0 0 0 0]
  452. [ ]
  453. [0 0 0 0 0]
  454. [ ]
  455. [0 0 0 0 0]
  456. \end{multilineoutput} \\
  457. copy_into(A,G,1,2); &
  458. \begin{multilineoutput}{6cm}
  459. [0 1 2 3 0]
  460. [ ]
  461. [0 4 5 6 0]
  462. [ ]
  463. [0 7 8 9 0]
  464. [ ]
  465. [0 0 0 0 0]
  466. [ ]
  467. [0 0 0 0 0]
  468. \end{multilineoutput} \\
  469. \end{Examples}
  470. Related functions:
  471. \nameref{augment\_columns}, \nameref{extend}, \nameref{matrix\_augment},
  472. \nameref{matrix\_stack}, \nameref{stack\_rows}, \nameref{sub\_matrix}.
  473. \end{Operator}
  474. \begin{Operator}{diagonal}
  475. \begin{Syntax}
  476. \name{diagonal}(\{\meta{mat\_list}\})
  477. \end{Syntax}
  478. (If you are feeling lazy then the braces can be omitted.)
  479. \meta{mat\_list} :- each can be either a scalar expression or a
  480. square \nameref{matrix}.
  481. \name{diagonal} creates a matrix that contains the input on the
  482. diagonal.
  483. \begin{Examples}
  484. H := mat((66,77),(88,99)); &
  485. \begin{multilineoutput}{6cm}
  486. [66 77]
  487. h := [ ]
  488. [88 99]
  489. \end{multilineoutput} \\
  490. diagonal(\{A,x,H\}); &
  491. \begin{multilineoutput}{6cm}
  492. [1 2 3 0 0 0 ]
  493. [ ]
  494. [4 5 6 0 0 0 ]
  495. [ ]
  496. [7 8 9 0 0 0 ]
  497. [ ]
  498. [0 0 0 x 0 0 ]
  499. [ ]
  500. [0 0 0 0 66 77]
  501. [ ]
  502. [0 0 0 0 88 99]
  503. \end{multilineoutput} \\
  504. \end{Examples}
  505. Related functions:
  506. \nameref{jordan\_block}.
  507. \end{Operator}
  508. \begin{Operator}{extend}
  509. \begin{Syntax}
  510. \name{extend}(\meta{matrix},\meta{r},\meta{c},\meta{expr})
  511. \end{Syntax}
  512. \meta{matrix} :- a \nameref{matrix}.
  513. \meta{r},\meta{c} :- positive integers.
  514. \meta{expr} :- algebraic expression or symbol.
  515. \name{extend} returns a copy of \meta{matrix} that has been extended by
  516. \meta{r} rows and \meta{c} columns. The new entries are made equal to
  517. \meta{expr}.
  518. \begin{Examples}
  519. extend(A,1,2,x); &
  520. \begin{multilineoutput}{6cm}
  521. [1 2 3 x x]
  522. [ ]
  523. [4 5 6 x x]
  524. [ ]
  525. [7 8 9 x x]
  526. [ ]
  527. [x x x x x]
  528. \end{multilineoutput} \\
  529. \end{Examples}
  530. Related functions:
  531. \nameref{copy\_into}, \nameref{matrix\_augment}, \nameref{matrix\_stack},
  532. \nameref{remove\_columns}, \nameref{remove\_rows}.
  533. \end{Operator}
  534. \begin{Operator}{find_companion}
  535. \begin{Syntax}
  536. \name{find\_companion}(\meta{matrix},\meta{x})
  537. \end{Syntax}
  538. \meta{matrix} :- a \nameref{matrix}.
  539. \meta{x} :- the variable.
  540. Given a companion matrix, \name{find\_companion} finds the polynomial
  541. from which it was made.
  542. \begin{Examples}
  543. C := companion(x^4+17*x^3-9*x^2+11,x); &
  544. \begin{multilineoutput}{6cm}
  545. [0 0 0 -11]
  546. [ ]
  547. [1 0 0 0 ]
  548. c := [ ]
  549. [0 1 0 9 ]
  550. [ ]
  551. [0 0 1 -17]
  552. \end{multilineoutput}\\
  553. find_companion(C,x); &
  554. x^4+17*x^3-9*x^2+11
  555. \end{Examples}
  556. Related functions:
  557. \nameref{companion}.
  558. \end{Operator}
  559. \begin{Operator}{get_columns}
  560. Get columns, get rows:
  561. \begin{Syntax}
  562. \name{get\_columns}(\meta{matrix},\meta{column\_list})
  563. \end{Syntax}
  564. \meta{matrix} :- a \nameref{matrix}.
  565. \meta{c} :- either a positive integer or a list of positive
  566. integers.
  567. \name{get\_columns} removes the columns of \meta{matrix} specified in
  568. \meta{column\_list} and returns them as a list of column matrices.
  569. \name{get\_rows} performs the same task on the rows of \meta{matrix}.
  570. \begin{Examples}
  571. get_columns(A,\{1,3\}); &
  572. \begin{multilineoutput}{6cm}
  573. \{
  574. [1]
  575. [ ]
  576. [4]
  577. [ ]
  578. [7]
  579. ,
  580. [3]
  581. [ ]
  582. [6]
  583. [ ]
  584. [9]
  585. \}
  586. \end{multilineoutput} \\
  587. get_rows(A,2); &
  588. \begin{multilineoutput}{6cm}
  589. \{
  590. [4 5 6]
  591. \}
  592. \end{multilineoutput} \\
  593. \end{Examples}
  594. Related functions:
  595. \nameref{augment\_columns}, \nameref{stack\_rows}, \nameref{sub\_matrix}.
  596. \end{Operator}
  597. \begin{Operator}{get_rows}
  598. see: \nameref{get\_columns}.
  599. \end{Operator}
  600. \begin{Operator}{gram_schmidt}
  601. \begin{Syntax}
  602. \name{gram\_schmidt}(\{\meta{vec\_list}\})
  603. \end{Syntax}
  604. (If you are feeling lazy then the braces can be omitted.)
  605. \meta{vec\_list} :- linearly independent vectors. Each vector must be
  606. written as a list, eg:\{1,0,0\}.
  607. \name{gram\_schmidt} performs the gram\_schmidt orthonormalization on
  608. the input vectors.
  609. It returns a list of orthogonal normalized vectors.
  610. \begin{Examples}
  611. gram_schmidt(\{\{1,0,0\},\{1,1,0\},\{1,1,1\}\}); &
  612. \{\{1,0,0\},\{0,1,0\},\{0,0,1\}\} \\
  613. gram_schmidt(\{\{1,2\},\{3,4\}\}); &
  614. \{\{ \rfrac{1}{{sqrt(5)}} , \rfrac{2}{sqrt(5)} \},
  615. \{ \rfrac{2*sqrt(5)}{5} , \rfrac{-sqrt(5)}{5} \}\}
  616. \end{Examples}
  617. \end{Operator}
  618. \begin{Operator}{hermitian_tp}
  619. \begin{Syntax}
  620. \name{ hermitian\_tp}(\meta{matrix})
  621. \end{Syntax}
  622. \meta{matrix} :- a \nameref{matrix}.
  623. \name{hermitian\_tp} computes the hermitian transpose of \meta{matrix}.
  624. This is a \nameref{matrix} in which the (i,j)'th entry is the conjugate
  625. of the (j,i)'th entry of \meta{matrix}.
  626. \begin{Examples}
  627. J := mat((i+1,i+2,i+3),(4,5,2),(1,i,0)); &
  628. \begin{multilineoutput}{6cm}
  629. [i + 1 i + 2 i + 3]
  630. [ ]
  631. j := [ 4 5 2 ]
  632. [ ]
  633. [ 1 i 0 ]
  634. \end{multilineoutput} \\
  635. hermitian_tp(j); &
  636. \begin{multilineoutput}{6cm}
  637. [ - i + 1 4 1 ]
  638. [ ]
  639. [ - i + 2 5 - i]
  640. [ ]
  641. [ - i + 3 2 0 ]
  642. \end{multilineoutput} \\
  643. \end{Examples}
  644. Related functions:
  645. \nameref{tp}.
  646. \end{Operator}
  647. \begin{Operator}{hessian}
  648. \begin{Syntax}
  649. \name{hessian}(\meta{expr},\meta{variable\_list})
  650. \end{Syntax}
  651. \meta{expr} :- a scalar expression.
  652. \meta{variable\_list} :- either a single variable or a list of
  653. variables.
  654. \name{hessian} computes the hessian matrix of \meta{expr} w.r.t. the
  655. variables in \meta{variable\_list}.
  656. % Does df exist in the help pages?
  657. This is an n by n matrix where n is the number of variables and the
  658. (i,j)'th entry is \nameref{df}(\meta{expr},\meta{variable\_list}(i),
  659. \meta{variable\_list}(j)).
  660. \begin{Examples}
  661. hessian(x*y*z+x^2,\{w,x,y,z\}); &
  662. \begin{multilineoutput}{6cm}
  663. [0 0 0 0]
  664. [ ]
  665. [0 2 z y]
  666. [ ]
  667. [0 z 0 x]
  668. [ ]
  669. [0 y x 0]
  670. \end{multilineoutput}{6cm}
  671. \end{Examples}
  672. Related functions: \nameref{df}.
  673. \end{Operator}
  674. \begin{Operator}{hilbert}
  675. \begin{Syntax}
  676. \name{hilbert}(\meta{square\_size},\meta{expr})
  677. \end{Syntax}
  678. \meta{square\_size} :- a positive integer.
  679. \meta{expr} :- an algebraic expression.
  680. \name{hilbert} computes the square hilbert matrix of dimension
  681. \meta{square\_size}.
  682. This is the symmetric matrix in which the (i,j)'th entry is
  683. 1/(i+j-\meta{expr}).
  684. \begin{Examples}
  685. hilbert(3,y+x); &
  686. \begin{multilineoutput}{6cm}
  687. [ - 1 - 1 - 1 ]
  688. [----------- ----------- -----------]
  689. [ x + y - 2 x + y - 3 x + y - 4 ]
  690. [ ]
  691. [ - 1 - 1 - 1 ]
  692. [----------- ----------- -----------]
  693. [ x + y - 3 x + y - 4 x + y - 5 ]
  694. [ ]
  695. [ - 1 - 1 - 1 ]
  696. [----------- ----------- -----------]
  697. [ x + y - 4 x + y - 5 x + y - 6 ]
  698. \end{multilineoutput}
  699. \end{Examples}
  700. \end{Operator}
  701. \begin{Operator}{jacobian}
  702. \begin{Syntax}
  703. \name{jacobian}(\meta{expr\_list},\meta{variable\_list})
  704. \end{Syntax}
  705. \meta{expr\_list} :- either a single algebraic expression or a list
  706. of algebraic expressions.
  707. \meta{variable\_list} :- either a single variable or a list of
  708. variables.
  709. \name{jacobian} computes the jacobian matrix of \meta{expr\_list}
  710. w.r.t. \meta{variable\_list}.
  711. This is a matrix whose (i,j)'th entry is \nameref{df}(\meta{expr\_list}
  712. (i),\meta{variable\_list}(j)).
  713. The matrix is n by m where n is the number of variables and m the number
  714. of expressions.
  715. \begin{Examples}
  716. jacobian(\{x^4,x*y^2,x*y*z^3\},\{w,x,y,z\}); &
  717. \begin{multilineoutput}{6cm}
  718. [ 3 ]
  719. [0 4*x 0 0 ]
  720. [ ]
  721. [ 2 ]
  722. [0 y 2*x*y 0 ]
  723. [ ]
  724. [ 3 3 2]
  725. [0 y*z x*z 3*x*y*z ]
  726. \end{multilineoutput}
  727. \end{Examples}
  728. Related functions:
  729. \nameref{hessian}, \nameref{df}.
  730. \end{Operator}
  731. \begin{Operator}{jordan_block}
  732. \begin{Syntax}
  733. \name{jordan\_block}(\meta{expr},\meta{square\_size})
  734. \end{Syntax}
  735. \meta{expr} :- an algebraic expression or symbol.
  736. \meta{square\_size} :- a positive integer.
  737. \name{jordan\_block} computes the square jordan block matrix J of
  738. dimension \meta{square\_size}.
  739. The entries of J are:
  740. J(i,i) = \meta{expr} for i=1
  741. \ldots n, J(i,i+1) = 1 for i=1
  742. \ldots n-1, and all other entries are 0.
  743. \begin{Examples}
  744. jordan\_block(x,5); &
  745. \begin{multilineoutput}{6cm}
  746. [x 1 0 0 0]
  747. [ ]
  748. [0 x 1 0 0]
  749. [ ]
  750. [0 0 x 1 0]
  751. [ ]
  752. [0 0 0 x 1]
  753. [ ]
  754. [0 0 0 0 x]
  755. \end{multilineoutput}
  756. \end{Examples}
  757. Related functions: \nameref{diagonal}, \nameref{companion}.
  758. \end{Operator}
  759. \begin{Operator}{lu_decom}
  760. \begin{Syntax}
  761. \name{lu\_decom}(\meta{matrix})
  762. \end{Syntax}
  763. \meta{matrix} :- a \nameref{matrix} containing either numeric entries
  764. or imaginary entries with numeric coefficients.
  765. \name{lu\_decom} performs LU decomposition on \meta{matrix}, ie: it
  766. returns \{L,U\} where L is a lower diagonal \nameref{matrix}, U an
  767. upper diagonal \nameref{matrix} and A = LU.
  768. Caution:
  769. The algorithm used can swap the rows of \meta{matrix} during the
  770. calculation. This means that LU does not equal \meta{matrix} but a row
  771. equivalent of it. Due to this, \name{lu\_decom} returns \{L,U,vec\}.
  772. The call \name{convert(\meta{matrix},vec)} will return the matrix that has
  773. been decomposed, i.e: LU = convert(\meta{matrix},vec).
  774. \begin{Examples}
  775. K := mat((1,3,5),(-4,3,7),(8,6,4)); &
  776. \begin{multilineoutput}{6cm}
  777. [1 3 5]
  778. [ ]
  779. k := [-4 3 7]
  780. [ ]
  781. [8 6 4]
  782. \end{multilineoutput}\\
  783. on rounded;\\
  784. lu := lu_decom(K); &
  785. \begin{multilineoutput}{6cm}
  786. lu := \{
  787. [8 0 0 ]
  788. [ ]
  789. [-4 6.0 0 ]
  790. [ ]
  791. [1 2.25 1.125]
  792. ,
  793. [1 0.75 0.5]
  794. [ ]
  795. [0 1 1.5]
  796. [ ]
  797. [0 0 1 ]
  798. ,
  799. [3 2 3]\}
  800. \end{multilineoutput} \\
  801. first lu * second lu; &
  802. \begin{multilineoutput}{6cm}
  803. [8 6.0 4.0]
  804. [ ]
  805. [-4 3.0 7.0]
  806. [ ]
  807. [1 3.0 5.0]
  808. \end{multilineoutput}\\
  809. convert(K,third lu); &
  810. \begin{multilineoutput}
  811. [8 6 4]
  812. [ ]
  813. [-4 3 7]
  814. [ ]
  815. [1 3 5]
  816. \end{multilineoutput}\\
  817. P := mat((i+1,i+2,i+3),(4,5,2),(1,i,0)); &
  818. \begin{multilineoutput}{6cm}
  819. [i + 1 i + 2 i + 3]
  820. [ ]
  821. p := [ 4 5 2 ]
  822. [ ]
  823. [ 1 i 0 ]
  824. \end{multilineoutput}\\
  825. lu := lu_decom(P); &
  826. \begin{multilineoutput}{6cm}
  827. lu := \{
  828. [ 1 0 0 ]
  829. [ ]
  830. [ 4 - 4*i + 5 0 ]
  831. [ ]
  832. [i + 1 3 0.414634146341*i + 2.26829268293]
  833. ,
  834. [1 i 0 ]
  835. [ ]
  836. [0 1 0.19512195122*i + 0.243902439024]
  837. [ ]
  838. [0 0 1 ]
  839. ,
  840. [3 2 3]\}
  841. \end{multilineoutput}\\
  842. first lu * second lu; &
  843. \begin{multilineoutput}{6cm}
  844. [ 1 i 0 ]
  845. [ ]
  846. [ 4 5 2.0 ]
  847. [ ]
  848. [i + 1 i + 2 i + 3.0]
  849. \end{multilineoutput}\\
  850. convert(P,third lu); &
  851. \begin{multilineoutput}{6cm}
  852. [ 1 i 0 ]
  853. [ ]
  854. [ 4 5 2 ]
  855. [ ]
  856. [i + 1 i + 2 i + 3]
  857. \end{multilineoutput}\\
  858. \end{Examples}
  859. Related functions: \nameref{cholesky}.
  860. \end{Operator}
  861. \begin{Operator}{make_identity}
  862. \begin{Syntax}
  863. \name{make\_identity}(\meta{square\_size})
  864. \end{Syntax}
  865. \meta{square\_size} :- a positive integer.
  866. \name{make\_identity} creates the identity matrix of dimension
  867. \meta{square\_size}.
  868. \begin{Examples}
  869. make_identity(4); &
  870. \begin{multilineoutput}{6cm}
  871. [1 0 0 0]
  872. [ ]
  873. [0 1 0 0]
  874. [ ]
  875. [0 0 1 0]
  876. [ ]
  877. [0 0 0 1]
  878. \end{multilineoutput}
  879. \end{Examples}
  880. Related functions: \nameref{diagonal}.
  881. \end{Operator}
  882. \begin{Operator}{matrix_augment}
  883. Matrix augment, matrix stack:
  884. \begin{Syntax}
  885. \name{matrix\_augment} \{\meta{matrix\_list}\}
  886. \end{Syntax}
  887. (If you are feeling lazy then the braces can be omitted.)
  888. \meta{matrix\_list} :- matrices.
  889. \name{matrix\_augment} sticks the matrices in \meta{matrix\_list}
  890. together horizontally.
  891. \name{matrix\_stack} sticks the matrices in \meta{matrix\_list}
  892. together vertically.
  893. \begin{Examples}
  894. matrix_augment(\{A,A\}); &
  895. \begin{multilineoutput}{6cm}
  896. [1 2 3 1 2 3]
  897. [ ]
  898. [4 5 6 4 5 6]
  899. [ ]
  900. [7 8 9 7 8 9]
  901. \end{multilineoutput}\\
  902. matrix_stack(A,A); &
  903. \begin{multilineoutput}{6cm}
  904. [1 2 3]
  905. [ ]
  906. [4 5 6]
  907. [ ]
  908. [7 8 9]
  909. [ ]
  910. [1 2 3]
  911. [ ]
  912. [4 5 6]
  913. [ ]
  914. [7 8 9]
  915. \end{multilineoutput} \\
  916. \end{Examples}
  917. Related functions:
  918. \nameref{augment\_columns}, \nameref{stack\_rows}, \nameref{sub\_matrix}.
  919. \end{Operator}
  920. \begin{Operator}{matrixp}
  921. \begin{Syntax}
  922. \name{matrixp}(\meta{test\_input})
  923. \end{Syntax}
  924. \meta{test\_input} :- anything you like.
  925. \name{matrixp} is a boolean function that returns t if the input is a
  926. matrix and nil otherwise.
  927. \begin{Examples}
  928. matrixp A; &
  929. t \\
  930. matrixp(doodlesackbanana);&
  931. nil
  932. \end{Examples}
  933. Related functions: \nameref{squarep}, \nameref{symmetricp}.
  934. \end{Operator}
  935. \begin{Operator}{matrix_stack}
  936. see: \nameref{matrix\_augment}.
  937. \end{Operator}
  938. \begin{Operator}{minor}
  939. \begin{Syntax}
  940. \name{minor}(\meta{matrix},\meta{r},\meta{c})
  941. \end{Syntax}
  942. \meta{matrix} :- a \nameref{matrix}.
  943. \meta{r},\meta{c} :- positive integers.
  944. \name{minor} computes the (\meta{r},\meta{c})'th minor of \meta{matrix}.
  945. This is created by removing the \meta{r}'th row and the \meta{c}'th
  946. column from \meta{matrix}.
  947. \begin{Examples}
  948. minor(A,1,3); &
  949. \begin{multilineoutput}{6cm}
  950. [4 5]
  951. [ ]
  952. [7 8]
  953. \end{multilineoutput}
  954. \end{Examples}
  955. Related functions:
  956. \nameref{remove\_columns}, \nameref{remove\_rows}.
  957. \end{Operator}
  958. \begin{Operator}{mult_columns}
  959. Mult columns, mult rows:
  960. \begin{Syntax}
  961. \name{mult\_columns}(\meta{matrix},\meta{column\_list},\meta{expr})
  962. \end{Syntax}
  963. \meta{matrix} :- a \nameref{matrix}.
  964. \meta{column\_list} :- a positive integer or a list of positive
  965. integers.
  966. \meta{expr} :- an algebraic expression.
  967. \name{mult\_columns} returns a copy of \meta{matrix} in which the
  968. columns specified in \meta{column\_list} have been multiplied by
  969. \meta{expr}.
  970. \name{mult\_rows} performs the same task on the rows of \meta{matrix}.
  971. \begin{Examples}
  972. mult_columns(A,\{1,3\},x); &
  973. \begin{multilineoutput}{6cm}
  974. [ x 2 3*x]
  975. [ ]
  976. [4*x 5 6*x]
  977. [ ]
  978. [7*x 8 9*x]
  979. \end{multilineoutput}\\
  980. mult_rows(A,2,10); &
  981. \begin{multilineoutput}{6cm}
  982. [1 2 3 ]
  983. [ ]
  984. [40 50 60]
  985. [ ]
  986. [7 8 9 ]
  987. \end{multilineoutput}
  988. \end{Examples}
  989. Related functions: \nameref{add\_to\_columns}, \nameref{add\_to\_rows}.
  990. \end{Operator}
  991. \begin{Operator}{mult_rows}
  992. see: \nameref{mult\_columns}.
  993. \end{Operator}
  994. \begin{Operator}{pivot}
  995. \begin{Syntax}
  996. \name{pivot}(\meta{matrix},\meta{r},\meta{c})
  997. \end{Syntax}
  998. \meta{matrix} :- a matrix.
  999. \meta{r},\meta{c} :- positive integers such that \meta{matrix}(\meta{r},
  1000. \meta{c}) neq 0.
  1001. \name{pivot} pivots \meta{matrix} about it's (\meta{r},\meta{c})'th
  1002. entry.
  1003. To do this, multiples of the \meta{r}'th row are added to every other
  1004. row in the matrix.
  1005. This means that the \meta{c}'th column will be 0 except for the
  1006. (\meta{r},\meta{c})'th entry.
  1007. \begin{Examples}
  1008. pivot(A,2,3); &
  1009. \begin{multilineoutput}{6cm}
  1010. [ - 1 ]
  1011. [-1 ------ 0]
  1012. [ 2 ]
  1013. [ ]
  1014. [4 5 6]
  1015. [ ]
  1016. [ 1 ]
  1017. [1 --- 0]
  1018. [ 2 ]
  1019. \end{multilineoutput}
  1020. \end{Examples}
  1021. Related functions:
  1022. \nameref{rows\_pivot}.
  1023. \end{Operator}
  1024. \begin{Operator}{pseudo_inverse}
  1025. \begin{Syntax}
  1026. \name{pseudo\_inverse}(\meta{matrix})
  1027. \end{Syntax}
  1028. \meta{matrix} :- a \nameref{matrix}.
  1029. \name{pseudo\_inverse}, also known as the Moore-Penrose inverse,
  1030. computes the pseudo inverse of \meta{matrix}.
  1031. Given the singular value decomposition of \meta{matrix}, i.e:
  1032. A = $U*P*V^T$, then the pseudo inverse $A^{-1}$ is defined by
  1033. $A^{-1} = V^T*P^{-1}*U$.
  1034. Thus \meta{matrix} * pseudo\_inverse(A) = Id.
  1035. (Id is the identity matrix).
  1036. \begin{Examples}
  1037. R := mat((1,2,3,4),(9,8,7,6)); &
  1038. \begin{multilineoutput}{6cm}
  1039. [1 2 3 4]
  1040. r := [ ]
  1041. [9 8 7 6]
  1042. \end{multilineoutput}\\
  1043. on rounded; \\
  1044. pseudo_inverse(R); &
  1045. \begin{multilineoutput}{6cm}
  1046. [ - 0.199999999996 0.100000000013 ]
  1047. [ ]
  1048. [ - 0.0499999999988 0.0500000000037 ]
  1049. [ ]
  1050. [ 0.0999999999982 - 5.57825497203e-12]
  1051. [ ]
  1052. [ 0.249999999995 - 0.0500000000148 ]
  1053. \end{multilineoutput}
  1054. \end{Examples}
  1055. Related functions: \nameref{svd}.
  1056. \end{Operator}
  1057. \begin{Operator}{random_matrix}
  1058. \begin{Syntax}
  1059. \name{random\_matrix}(\meta{r},\meta{c},\meta{limit})
  1060. \end{Syntax}
  1061. \meta{r},\meta{c},\meta{limit} :- positive integers.
  1062. \name{random\_matrix} creates an \meta{r} by \meta{c} matrix with random
  1063. entries in the range -limit < entry < limit.
  1064. Switches:
  1065. \name{imaginary} :- if on then matrix entries are x+i*y where -limit < x,y
  1066. < \meta{limit}.
  1067. \name{not\_negative} :- if on then 0 < entry < \meta{limit}. In the imaginary
  1068. case we have 0 < x,y < \meta{limit}.
  1069. \name{only\_integer} :- if on then each entry is an integer. In the imaginary
  1070. case x and y are integers.
  1071. \name{symmetric} :- if on then the matrix is symmetric.
  1072. \name{upper\_matrix} :- if on then the matrix is upper triangular.
  1073. \name{lower\_matrix} :- if on then the matrix is lower triangular.
  1074. \begin{Examples}
  1075. on rounded; \\
  1076. random_matrix(3,3,10); &
  1077. \begin{multilineoutput}{6cm}
  1078. [ - 8.11911717343 - 5.71677292768 0.620580830035 ]
  1079. [ ]
  1080. [ - 0.032596262422 7.1655452861 5.86742633837 ]
  1081. [ ]
  1082. [ - 9.37155438255 - 7.55636708637 - 8.88618627557]
  1083. \end{multilineoutput}\\
  1084. on only_integer, not_negative, upper_matrix, imaginary; \\
  1085. random_matrix(4,4,10); &
  1086. \begin{multilineoutput}{6cm}
  1087. [70*i + 15 28*i + 8 2*i + 79 27*i + 44]
  1088. [ ]
  1089. [ 0 46*i + 95 9*i + 63 95*i + 50]
  1090. [ ]
  1091. [ 0 0 31*i + 75 14*i + 65]
  1092. [ ]
  1093. [ 0 0 0 5*i + 52 ]
  1094. \end{multilineoutput}\\
  1095. \end{Examples}
  1096. \end{Operator}
  1097. \begin{Operator}{remove_columns}
  1098. Remove columns, remove rows:
  1099. \begin{Syntax}
  1100. \name{remove\_columns}(\meta{matrix},\meta{column\_list})
  1101. \end{Syntax}
  1102. \meta{matrix} :- a \nameref{matrix}.
  1103. \meta{column\_list} :- either a positive integer or a list of positive
  1104. integers.
  1105. \name{remove\_columns} removes the columns specified in
  1106. \meta{column\_list} from \meta{matrix}.
  1107. \name{remove\_rows} performs the same task on the rows of \meta{matrix}.
  1108. \begin{Examples}
  1109. remove_columns(A,2); &
  1110. \begin{multilineoutput}{6cm}
  1111. [1 3]
  1112. [ ]
  1113. [4 6]
  1114. [ ]
  1115. [7 9]
  1116. \end{multilineoutput}\\
  1117. remove_rows(A,\{1,3\}); &
  1118. \begin{multilineoutput}{6cm}
  1119. [4 5 6]
  1120. \end{multilineoutput}\\
  1121. \end{Examples}
  1122. Related functions: \nameref{minor}.
  1123. \end{Operator}
  1124. \begin{Operator}{remove_rows}
  1125. see: \nameref{remove\_columns}.
  1126. \end{Operator}
  1127. \begin{Operator}{row_dim}
  1128. see: \nameref{column\_dim}.
  1129. \end{Operator}
  1130. \begin{Operator}{rows_pivot}
  1131. \begin{Syntax}
  1132. \name{rows\_pivot}(\meta{matrix},\meta{r},\meta{c},\{\meta{row\_list}\})
  1133. \end{Syntax}
  1134. \meta{matrix} :- a nameref{matrix}.
  1135. \meta{r},\meta{c} :- positive integers such that \meta{matrix}(\meta{r},
  1136. \meta{c}) neq 0.
  1137. \meta{row\_list} :- positive integer or a list of positive integers.
  1138. \name{rows\_pivot} performs the same task as \name{pivot} but applies
  1139. the pivot only to the rows specified in \meta{row\_list}.
  1140. \begin{Examples}
  1141. N := mat((1,2,3),(4,5,6),(7,8,9),(1,2,3),(4,5,6)); &
  1142. \begin{multilineoutput}{6cm}
  1143. [1 2 3]
  1144. [ ]
  1145. [4 5 6]
  1146. [ ]
  1147. n := [7 8 9]
  1148. [ ]
  1149. [1 2 3]
  1150. [ ]
  1151. [4 5 6]
  1152. \end{multilineoutput}\\
  1153. rows_pivot(N,2,3,{4,5}); &
  1154. \begin{multilineoutput}{6cm}
  1155. [1 2 3]
  1156. [ ]
  1157. [4 5 6]
  1158. [ ]
  1159. [7 8 9]
  1160. [ ]
  1161. [ - 1 ]
  1162. [-1 ------ 0]
  1163. [ 2 ]
  1164. [ ]
  1165. [0 0 0]
  1166. \end{multilineoutput}\\
  1167. \end{Examples}
  1168. Related functions: \nameref{pivot}.
  1169. \end{Operator}
  1170. \begin{Operator}{simplex}
  1171. \begin{Syntax}
  1172. \name{simplex}(\meta{max/min},\meta{objective function},
  1173. \{\meta{linear inequalities}\})
  1174. \end{Syntax}
  1175. \meta{max/min} :- either max or min (signifying maximize and
  1176. minimize).
  1177. \meta{objective function} :- the function you are maximizing or
  1178. minimizing.
  1179. \meta{linear inequalities} :- the constraint inequalities. Each one must
  1180. be of the form {\it sum of variables (
  1181. <=,=,>=) number}.
  1182. \name{simplex} applies the revised simplex algorithm to find the
  1183. optimal(either maximum or minimum) value of the
  1184. \meta{objective function} under the linear inequality constraints.
  1185. It returns \{optimal value,\{ values of variables at this optimal\}\}.
  1186. The algorithm implies that all the variables are non-negative.
  1187. \begin{Examples}
  1188. simplex(max,x+y,\{x>=10,y>=20,x+y<=25\}); &
  1189. ***** Error in simplex: Problem has no feasible solution\\
  1190. simplex(max,10x+5y+5.5z,\{5x+3z<=200,x+0.1y+0.5z<=12,
  1191. 0.1x+0.2y+0.3z<=9, 30x+10y+50z<=1500\}); &
  1192. \{525.0,\{x=40.0,y=25.0,z=0\}\}\\
  1193. \end{Examples}
  1194. \end{Operator}
  1195. \begin{Operator}{squarep}
  1196. \begin{Syntax}
  1197. \name{squarep}(\meta{matrix})
  1198. \end{Syntax}
  1199. \meta{matrix} :- a \nameref{matrix}.
  1200. \name{squarep} is a predicate that returns t if the \meta{matrix} is
  1201. square and nil otherwise.
  1202. \begin{Examples}
  1203. squarep(mat((1,3,5))); &
  1204. nil \\
  1205. squarep(A);
  1206. t\\
  1207. \end{Examples}
  1208. Related functions: \nameref{matrixp}, \nameref{symmetricp}.
  1209. \end{Operator}
  1210. \begin{Operator}{stack_rows}
  1211. see: \nameref{augment\_columns}.
  1212. \end{Operator}
  1213. \begin{Operator}{sub_matrix}
  1214. \begin{Syntax}
  1215. \name{sub\_matrix}(\meta{matrix},\meta{row\_list},\meta{column\_list})
  1216. \end{Syntax}
  1217. \meta{matrix} :- a matrix.
  1218. \meta{row\_list}, \meta{column\_list} :- either a positive integer or a
  1219. list of positive integers.
  1220. name{sub\_matrix} produces the matrix consisting of the intersection of
  1221. the rows specified in \meta{row\_list} and the columns specified in
  1222. \meta{column\_list}.
  1223. \begin{Examples}
  1224. sub_matrix(A,\{1,3\},\{2,3\}); &
  1225. \begin{multilineoutput}{6cm}
  1226. [2 3]
  1227. [ ]
  1228. [8 9]
  1229. \end{multilineoutput}
  1230. \end{Examples}
  1231. Related functions:
  1232. \nameref{augment\_columns}, \nameref{stack\_rows}.
  1233. \end{Operator}
  1234. \begin{Operator}{svd}
  1235. \index{singular value decomposition}
  1236. Singular value decomposition:
  1237. \begin{Syntax}
  1238. \name{svd}(\meta{matrix})
  1239. \end{Syntax}
  1240. \meta{matrix} :- a \nameref{matrix} containing only numeric entries.
  1241. \name{svd} computes the singular value decomposition of \meta{matrix}.
  1242. It returns
  1243. \{U,P,V\}
  1244. where A = $U*P*V^T$
  1245. and P = diag(sigma(1) ... sigma(n)).
  1246. sigma(i) for i= 1 ... n are the singular values of
  1247. \meta{matrix}.
  1248. n is the column dimension of \meta{matrix}.
  1249. The singular values of \meta{matrix} are the non-negative square roots
  1250. of the eigenvalues of $A^T*A$.
  1251. U and V are such that $U*U^T = V*V^T = V^T*V$ = Id.
  1252. Id is the identity matrix.
  1253. \begin{Examples}
  1254. Q := mat((1,3),(-4,3)); &
  1255. \begin{multilineoutput}{6cm}
  1256. [1 3]
  1257. q := [ ]
  1258. [-4 3]
  1259. \end{multilineoutput}\\
  1260. on rounded; \\
  1261. svd(Q); &
  1262. \begin{multilineoutput}{6cm}
  1263. \{
  1264. [ 0.289784137735 0.957092029805]
  1265. [ ]
  1266. [ - 0.957092029805 0.289784137735]
  1267. ,
  1268. [5.1491628629 0 ]
  1269. [ ]
  1270. [ 0 2.9130948854]
  1271. ,
  1272. [ - 0.687215403194 0.726453707825 ]
  1273. [ ]
  1274. [ - 0.726453707825 - 0.687215403194]
  1275. \}
  1276. \end{multilineoutput}\\
  1277. \end{Examples}
  1278. \end{Operator}
  1279. \begin{Operator}{swap_columns}
  1280. Swap columns, swap rows:
  1281. \begin{Syntax}
  1282. \name{swap\_columns} (\meta{matrix},\meta{c1},\meta{c2})
  1283. \end{Syntax}
  1284. \meta{matrix} :- a \nameref{matrix}.
  1285. \meta{c1},\meta{c1} :- positive integers.
  1286. \name{swap\_columns} swaps column \meta{c1} of \meta{matrix} with
  1287. column \meta{c2}.
  1288. \name{swap\_rows} performs the same task on two rows of \meta{matrix}.
  1289. \begin{Examples}
  1290. swap_columns(A,2,3); &
  1291. \begin{multilineoutput}{6cm}
  1292. [1 3 2]
  1293. [ ]
  1294. [4 6 5]
  1295. [ ]
  1296. [7 9 8]
  1297. \end{multilineoutput}\\
  1298. swap_rows(A,1,3); &
  1299. \begin{multilineoutput}{6cm}
  1300. [7 8 9]
  1301. [ ]
  1302. [4 5 6]
  1303. [ ]
  1304. [1 2 3]
  1305. \end{multilineoutput}
  1306. \end{Examples}
  1307. Related functions: \nameref{swap\_entries}.
  1308. \end{Operator}
  1309. \begin{Operator}{swap_entries}
  1310. \begin{Syntax}
  1311. \name{swap\_entries}(\meta{matrix},\{\meta{r1},\meta{c1}\},\{\meta{r2},
  1312. \meta{c2}\})
  1313. \end{Syntax}
  1314. \meta{matrix} :- a \nameref{matrix}.
  1315. \meta{r1},\meta{c1},\meta{r2},\meta{c2} :- positive integers.
  1316. \name{swap\_entries} swaps \meta{matrix}(\meta{r1},\meta{c1}) with
  1317. \meta{matrix}(\meta{r2},\meta{c2}).
  1318. \begin{Examples}
  1319. swap_entries(A,\{1,1\},\{3,3\}); &
  1320. \begin{multilineoutput}{6cm}
  1321. [9 2 3]
  1322. [ ]
  1323. [4 5 6]
  1324. [ ]
  1325. [7 8 1]
  1326. \end{multilineoutput}
  1327. \end{Examples}
  1328. Related functions: \nameref{swap\_columns}, \nameref{swap\_rows}.
  1329. \end{Operator}
  1330. \begin{Operator}{swap_rows}
  1331. see: \nameref{swap\_columns}.
  1332. \end{Operator}
  1333. \begin{Operator}{symmetricp}
  1334. \begin{Syntax}
  1335. \name{symmetricp}(\meta{matrix})
  1336. \end{Syntax}
  1337. \meta{matrix} :- a \nameref{matrix}.
  1338. \name{symmetricp} is a predicate that returns t if the matrix is symmetric
  1339. and nil otherwise.
  1340. \begin{Examples}
  1341. symmetricp(make_identity(11)); &
  1342. t \\
  1343. symmetricp(A); &
  1344. nil\\
  1345. \end{Examples}
  1346. Related functions: \nameref{matrixp}, \nameref{squarep}.
  1347. \end{Operator}
  1348. \begin{Operator}{toeplitz}
  1349. \begin{Syntax}
  1350. \name{toeplitz}(\meta{expr\_list})
  1351. \end{Syntax}
  1352. (If you are feeling lazy then the braces can be omitted.)
  1353. \meta{expr\_list} :- list of algebraic expressions.
  1354. \name{toeplitz} creates the toeplitz matrix from the \meta{expr\_list}.
  1355. This is a square symmetric matrix in which the first expression is
  1356. placed on the diagonal and the i'th expression is placed on the (i-1)'th
  1357. sub and super diagonals.
  1358. It has dimension n where n is the number of expressions.
  1359. \begin{Examples}
  1360. toeplitz({w,x,y,z}); &
  1361. \begin{multilineoutput}{6cm}
  1362. [w x y z]
  1363. [ ]
  1364. [x w x y]
  1365. [ ]
  1366. [y x w x]
  1367. [ ]
  1368. [z y x w]
  1369. \end{multilineoutput}
  1370. \end{Examples}
  1371. \end{Operator}
  1372. \begin{Operator}{vandermonde}
  1373. \begin{Syntax}
  1374. \name{vandermonde}(\{\meta{expr\_list}\})
  1375. \end{Syntax}
  1376. (If you are feeling lazy then the braces can be omitted.)
  1377. \meta{expr\_list} :- list of algebraic expressions.
  1378. \name{vandermonde} creates the vandermonde matrix from the
  1379. \meta{expr\_list}.
  1380. This is the square matrix in which the (i,j)'th entry is
  1381. \meta{expr\_list}$(i)^(j-1)$.
  1382. It has dimension n where n is the number of expressions.
  1383. \begin{Examples}
  1384. vandermonde({x,2*y,3*z}); &
  1385. \begin{multilineoutput}{6cm}
  1386. [ 2 ]
  1387. [1 x x ]
  1388. [ ]
  1389. [ 2]
  1390. [1 2*y 4*y ]
  1391. [ ]
  1392. [ 2]
  1393. [1 3*z 9*z ]
  1394. \end{multilineoutput}
  1395. \end{Examples}
  1396. \end{Operator}