LINALG.LOG 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688
  1. REDUCE 3.6, 15-Jul-95, patched to 6 Mar 96 ...
  2. if lisp !*rounded then rounded_was_on := t
  3. else rounded_was_on := nil;
  4. mat1 := mat((1,2,3,4,5),(2,3,4,5,6),(3,4,5,6,7),(4,5,6,7,8),(5,6,7,8,9));
  5. [1 2 3 4 5]
  6. [ ]
  7. [2 3 4 5 6]
  8. [ ]
  9. mat1 := [3 4 5 6 7]
  10. [ ]
  11. [4 5 6 7 8]
  12. [ ]
  13. [5 6 7 8 9]
  14. mat2 := mat((1,1,1,1),(2,2,2,2),(3,3,3,3),(4,4,4,4));
  15. [1 1 1 1]
  16. [ ]
  17. [2 2 2 2]
  18. mat2 := [ ]
  19. [3 3 3 3]
  20. [ ]
  21. [4 4 4 4]
  22. mat3 := mat((x),(x),(x),(x));
  23. [x]
  24. [ ]
  25. [x]
  26. mat3 := [ ]
  27. [x]
  28. [ ]
  29. [x]
  30. mat4 := mat((3,3),(4,4),(5,5),(6,6));
  31. [3 3]
  32. [ ]
  33. [4 4]
  34. mat4 := [ ]
  35. [5 5]
  36. [ ]
  37. [6 6]
  38. mat5 := mat((1,2,1,1),(1,2,3,1),(4,5,1,2),(3,4,5,6));
  39. [1 2 1 1]
  40. [ ]
  41. [1 2 3 1]
  42. mat5 := [ ]
  43. [4 5 1 2]
  44. [ ]
  45. [3 4 5 6]
  46. mat6 := mat((i+1,i+2,i+3),(4,5,2),(1,i,0));
  47. [i + 1 i + 2 i + 3]
  48. [ ]
  49. mat6 := [ 4 5 2 ]
  50. [ ]
  51. [ 1 i 0 ]
  52. mat7 := mat((1,1,0),(1,3,1),(0,1,1));
  53. [1 1 0]
  54. [ ]
  55. mat7 := [1 3 1]
  56. [ ]
  57. [0 1 1]
  58. mat8 := mat((1,3),(-4,3));
  59. [1 3]
  60. mat8 := [ ]
  61. [-4 3]
  62. mat9 := mat((1,2,3,4),(9,8,7,6));
  63. [1 2 3 4]
  64. mat9 := [ ]
  65. [9 8 7 6]
  66. poly := x^7+x^5+4*x^4+5*x^3+12;
  67. 7 5 4 3
  68. poly := x + x + 4*x + 5*x + 12
  69. poly1 := x^2+x*y^3+x*y*z^3+y*x+2+y*3;
  70. 2 3 3
  71. poly1 := x + x*y + x*y*z + x*y + 3*y + 2
  72. on errcont;
  73. % Basis matrix manipulations.
  74. add_columns(mat1,1,2,5*y);
  75. [1 5*y + 2 3 4 5]
  76. [ ]
  77. [2 10*y + 3 4 5 6]
  78. [ ]
  79. [3 15*y + 4 5 6 7]
  80. [ ]
  81. [4 5*(4*y + 1) 6 7 8]
  82. [ ]
  83. [5 25*y + 6 7 8 9]
  84. add_rows(mat1,1,2,x);
  85. [ 1 2 3 4 5 ]
  86. [ ]
  87. [x + 2 2*x + 3 3*x + 4 4*x + 5 5*x + 6]
  88. [ ]
  89. [ 3 4 5 6 7 ]
  90. [ ]
  91. [ 4 5 6 7 8 ]
  92. [ ]
  93. [ 5 6 7 8 9 ]
  94. add_to_columns(mat1,3,1000);
  95. [1 2 1003 4 5]
  96. [ ]
  97. [2 3 1004 5 6]
  98. [ ]
  99. [3 4 1005 6 7]
  100. [ ]
  101. [4 5 1006 7 8]
  102. [ ]
  103. [5 6 1007 8 9]
  104. add_to_columns(mat1,{1,2,3},y);
  105. [y + 1 y + 2 y + 3 4 5]
  106. [ ]
  107. [y + 2 y + 3 y + 4 5 6]
  108. [ ]
  109. [y + 3 y + 4 y + 5 6 7]
  110. [ ]
  111. [y + 4 y + 5 y + 6 7 8]
  112. [ ]
  113. [y + 5 y + 6 y + 7 8 9]
  114. add_to_rows(mat1,2,1000);
  115. [ 1 2 3 4 5 ]
  116. [ ]
  117. [1002 1003 1004 1005 1006]
  118. [ ]
  119. [ 3 4 5 6 7 ]
  120. [ ]
  121. [ 4 5 6 7 8 ]
  122. [ ]
  123. [ 5 6 7 8 9 ]
  124. add_to_rows(mat1,{1,2,3},x);
  125. [x + 1 x + 2 x + 3 x + 4 x + 5]
  126. [ ]
  127. [x + 2 x + 3 x + 4 x + 5 x + 6]
  128. [ ]
  129. [x + 3 x + 4 x + 5 x + 6 x + 7]
  130. [ ]
  131. [ 4 5 6 7 8 ]
  132. [ ]
  133. [ 5 6 7 8 9 ]
  134. augment_columns(mat1,2);
  135. [2]
  136. [ ]
  137. [3]
  138. [ ]
  139. [4]
  140. [ ]
  141. [5]
  142. [ ]
  143. [6]
  144. augment_columns(mat1,{1,2,5});
  145. [1 2 5]
  146. [ ]
  147. [2 3 6]
  148. [ ]
  149. [3 4 7]
  150. [ ]
  151. [4 5 8]
  152. [ ]
  153. [5 6 9]
  154. stack_rows(mat1,3);
  155. [3 4 5 6 7]
  156. stack_rows(mat1,{1,3,5});
  157. [1 2 3 4 5]
  158. [ ]
  159. [3 4 5 6 7]
  160. [ ]
  161. [5 6 7 8 9]
  162. char_poly(mat1,x);
  163. 3 2
  164. x *(x - 25*x - 50)
  165. column_dim(mat2);
  166. 4
  167. row_dim(mat1);
  168. 5
  169. copy_into(mat7,mat1,2,3);
  170. [1 2 3 4 5]
  171. [ ]
  172. [2 3 1 1 0]
  173. [ ]
  174. [3 4 1 3 1]
  175. [ ]
  176. [4 5 0 1 1]
  177. [ ]
  178. [5 6 7 8 9]
  179. copy_into(mat7,mat1,5,5);
  180. ***** Error in copy_into: the matrix
  181. [1 1 0]
  182. [ ]
  183. [1 3 1]
  184. [ ]
  185. [0 1 1]
  186. does not fit into
  187. [1 2 3 4 5]
  188. [ ]
  189. [2 3 4 5 6]
  190. [ ]
  191. [3 4 5 6 7]
  192. [ ]
  193. [4 5 6 7 8]
  194. [ ]
  195. [5 6 7 8 9]
  196. at position 5,5.
  197. diagonal(3);
  198. [3]
  199. % diagonal can take both a list of arguments or just the arguments.
  200. diagonal({mat2,mat6});
  201. [1 1 1 1 0 0 0 ]
  202. [ ]
  203. [2 2 2 2 0 0 0 ]
  204. [ ]
  205. [3 3 3 3 0 0 0 ]
  206. [ ]
  207. [4 4 4 4 0 0 0 ]
  208. [ ]
  209. [0 0 0 0 i + 1 i + 2 i + 3]
  210. [ ]
  211. [0 0 0 0 4 5 2 ]
  212. [ ]
  213. [0 0 0 0 1 i 0 ]
  214. diagonal(mat1,mat2,mat5);
  215. [1 2 3 4 5 0 0 0 0 0 0 0 0]
  216. [ ]
  217. [2 3 4 5 6 0 0 0 0 0 0 0 0]
  218. [ ]
  219. [3 4 5 6 7 0 0 0 0 0 0 0 0]
  220. [ ]
  221. [4 5 6 7 8 0 0 0 0 0 0 0 0]
  222. [ ]
  223. [5 6 7 8 9 0 0 0 0 0 0 0 0]
  224. [ ]
  225. [0 0 0 0 0 1 1 1 1 0 0 0 0]
  226. [ ]
  227. [0 0 0 0 0 2 2 2 2 0 0 0 0]
  228. [ ]
  229. [0 0 0 0 0 3 3 3 3 0 0 0 0]
  230. [ ]
  231. [0 0 0 0 0 4 4 4 4 0 0 0 0]
  232. [ ]
  233. [0 0 0 0 0 0 0 0 0 1 2 1 1]
  234. [ ]
  235. [0 0 0 0 0 0 0 0 0 1 2 3 1]
  236. [ ]
  237. [0 0 0 0 0 0 0 0 0 4 5 1 2]
  238. [ ]
  239. [0 0 0 0 0 0 0 0 0 3 4 5 6]
  240. extend(mat1,3,2,x);
  241. [1 2 3 4 5 x x]
  242. [ ]
  243. [2 3 4 5 6 x x]
  244. [ ]
  245. [3 4 5 6 7 x x]
  246. [ ]
  247. [4 5 6 7 8 x x]
  248. [ ]
  249. [5 6 7 8 9 x x]
  250. [ ]
  251. [x x x x x x x]
  252. [ ]
  253. [x x x x x x x]
  254. [ ]
  255. [x x x x x x x]
  256. find_companion(mat5,x);
  257. 2
  258. x - 2*x - 2
  259. get_columns(mat1,1);
  260. {
  261. [1]
  262. [ ]
  263. [2]
  264. [ ]
  265. [3]
  266. [ ]
  267. [4]
  268. [ ]
  269. [5]
  270. }
  271. get_columns(mat1,{1,2});
  272. {
  273. [1]
  274. [ ]
  275. [2]
  276. [ ]
  277. [3]
  278. [ ]
  279. [4]
  280. [ ]
  281. [5]
  282. ,
  283. [2]
  284. [ ]
  285. [3]
  286. [ ]
  287. [4]
  288. [ ]
  289. [5]
  290. [ ]
  291. [6]
  292. }
  293. get_rows(mat1,3);
  294. {
  295. [3 4 5 6 7]
  296. }
  297. get_rows(mat1,{1,3});
  298. {
  299. [1 2 3 4 5]
  300. ,
  301. [3 4 5 6 7]
  302. }
  303. hermitian_tp(mat6);
  304. [ - i + 1 4 1 ]
  305. [ ]
  306. [ - i + 2 5 - i]
  307. [ ]
  308. [ - i + 3 2 0 ]
  309. % matrix_augment and matrix_stack can take both a list of arguments
  310. % or just the arguments.
  311. matrix_augment({mat1,mat2});
  312. ***** Error in matrix_augment:
  313. ***** all input matrices must have the same row dimension.
  314. matrix_augment(mat4,mat2,mat4);
  315. [3 3 1 1 1 1 3 3]
  316. [ ]
  317. [4 4 2 2 2 2 4 4]
  318. [ ]
  319. [5 5 3 3 3 3 5 5]
  320. [ ]
  321. [6 6 4 4 4 4 6 6]
  322. matrix_stack(mat1,mat2);
  323. ***** Error in matrix_stack:
  324. ***** all input matrices must have the same column dimension.
  325. matrix_stack({mat6,mat((z,z,z)),mat7});
  326. [i + 1 i + 2 i + 3]
  327. [ ]
  328. [ 4 5 2 ]
  329. [ ]
  330. [ 1 i 0 ]
  331. [ ]
  332. [ z z z ]
  333. [ ]
  334. [ 1 1 0 ]
  335. [ ]
  336. [ 1 3 1 ]
  337. [ ]
  338. [ 0 1 1 ]
  339. minor(mat1,2,3);
  340. [1 2 4 5]
  341. [ ]
  342. [3 4 6 7]
  343. [ ]
  344. [4 5 7 8]
  345. [ ]
  346. [5 6 8 9]
  347. mult_columns(mat1,3,y);
  348. [1 2 3*y 4 5]
  349. [ ]
  350. [2 3 4*y 5 6]
  351. [ ]
  352. [3 4 5*y 6 7]
  353. [ ]
  354. [4 5 6*y 7 8]
  355. [ ]
  356. [5 6 7*y 8 9]
  357. mult_columns(mat1,{2,3,4},100);
  358. [1 200 300 400 5]
  359. [ ]
  360. [2 300 400 500 6]
  361. [ ]
  362. [3 400 500 600 7]
  363. [ ]
  364. [4 500 600 700 8]
  365. [ ]
  366. [5 600 700 800 9]
  367. mult_rows(mat1,2,x);
  368. [ 1 2 3 4 5 ]
  369. [ ]
  370. [2*x 3*x 4*x 5*x 6*x]
  371. [ ]
  372. [ 3 4 5 6 7 ]
  373. [ ]
  374. [ 4 5 6 7 8 ]
  375. [ ]
  376. [ 5 6 7 8 9 ]
  377. mult_rows(mat1,{1,3,5},10);
  378. [10 20 30 40 50]
  379. [ ]
  380. [2 3 4 5 6 ]
  381. [ ]
  382. [30 40 50 60 70]
  383. [ ]
  384. [4 5 6 7 8 ]
  385. [ ]
  386. [50 60 70 80 90]
  387. pivot(mat1,3,3);
  388. [ - 4 - 2 2 4 ]
  389. [------ ------ 0 --- --- ]
  390. [ 5 5 5 5 ]
  391. [ ]
  392. [ - 2 - 1 1 2 ]
  393. [------ ------ 0 --- --- ]
  394. [ 5 5 5 5 ]
  395. [ ]
  396. [ 3 4 5 6 7 ]
  397. [ ]
  398. [ 2 1 - 1 - 2 ]
  399. [ --- --- 0 ------ ------]
  400. [ 5 5 5 5 ]
  401. [ ]
  402. [ 4 2 - 2 - 4 ]
  403. [ --- --- 0 ------ ------]
  404. [ 5 5 5 5 ]
  405. rows_pivot(mat1,3,3,{1,5});
  406. [ - 4 - 2 2 4 ]
  407. [------ ------ 0 --- --- ]
  408. [ 5 5 5 5 ]
  409. [ ]
  410. [ 2 3 4 5 6 ]
  411. [ ]
  412. [ 3 4 5 6 7 ]
  413. [ ]
  414. [ 4 5 6 7 8 ]
  415. [ ]
  416. [ 4 2 - 2 - 4 ]
  417. [ --- --- 0 ------ ------]
  418. [ 5 5 5 5 ]
  419. remove_columns(mat1,3);
  420. [1 2 4 5]
  421. [ ]
  422. [2 3 5 6]
  423. [ ]
  424. [3 4 6 7]
  425. [ ]
  426. [4 5 7 8]
  427. [ ]
  428. [5 6 8 9]
  429. remove_columns(mat1,{2,3,4});
  430. [1 5]
  431. [ ]
  432. [2 6]
  433. [ ]
  434. [3 7]
  435. [ ]
  436. [4 8]
  437. [ ]
  438. [5 9]
  439. remove_rows(mat1,2);
  440. [1 2 3 4 5]
  441. [ ]
  442. [3 4 5 6 7]
  443. [ ]
  444. [4 5 6 7 8]
  445. [ ]
  446. [5 6 7 8 9]
  447. remove_rows(mat1,{1,3});
  448. [2 3 4 5 6]
  449. [ ]
  450. [4 5 6 7 8]
  451. [ ]
  452. [5 6 7 8 9]
  453. remove_rows(mat1,{1,2,3,4,5});
  454. ***** Warning in remove_rows:
  455. all the rows have been removed. Returning nil.
  456. swap_columns(mat1,2,4);
  457. [1 4 3 2 5]
  458. [ ]
  459. [2 5 4 3 6]
  460. [ ]
  461. [3 6 5 4 7]
  462. [ ]
  463. [4 7 6 5 8]
  464. [ ]
  465. [5 8 7 6 9]
  466. swap_rows(mat1,1,2);
  467. [2 3 4 5 6]
  468. [ ]
  469. [1 2 3 4 5]
  470. [ ]
  471. [3 4 5 6 7]
  472. [ ]
  473. [4 5 6 7 8]
  474. [ ]
  475. [5 6 7 8 9]
  476. swap_entries(mat1,{1,1},{5,5});
  477. [9 2 3 4 5]
  478. [ ]
  479. [2 3 4 5 6]
  480. [ ]
  481. [3 4 5 6 7]
  482. [ ]
  483. [4 5 6 7 8]
  484. [ ]
  485. [5 6 7 8 1]
  486. % Constructors - functions that create matrices.
  487. band_matrix(x,5);
  488. [x 0 0 0 0]
  489. [ ]
  490. [0 x 0 0 0]
  491. [ ]
  492. [0 0 x 0 0]
  493. [ ]
  494. [0 0 0 x 0]
  495. [ ]
  496. [0 0 0 0 x]
  497. band_matrix({x,y,z},6);
  498. [y z 0 0 0 0]
  499. [ ]
  500. [x y z 0 0 0]
  501. [ ]
  502. [0 x y z 0 0]
  503. [ ]
  504. [0 0 x y z 0]
  505. [ ]
  506. [0 0 0 x y z]
  507. [ ]
  508. [0 0 0 0 x y]
  509. block_matrix(1,2,{mat1,mat2});
  510. ***** Error in block_matrix: row dimensions of
  511. ***** matrices into block_matrix are not compatible
  512. block_matrix(2,3,{mat2,mat3,mat2,mat3,mat2,mat2});
  513. [1 1 1 1 x 1 1 1 1]
  514. [ ]
  515. [2 2 2 2 x 2 2 2 2]
  516. [ ]
  517. [3 3 3 3 x 3 3 3 3]
  518. [ ]
  519. [4 4 4 4 x 4 4 4 4]
  520. [ ]
  521. [x 1 1 1 1 1 1 1 1]
  522. [ ]
  523. [x 2 2 2 2 2 2 2 2]
  524. [ ]
  525. [x 3 3 3 3 3 3 3 3]
  526. [ ]
  527. [x 4 4 4 4 4 4 4 4]
  528. char_matrix(mat1,x);
  529. [x - 1 -2 -3 -4 -5 ]
  530. [ ]
  531. [ -2 x - 3 -4 -5 -6 ]
  532. [ ]
  533. [ -3 -4 x - 5 -6 -7 ]
  534. [ ]
  535. [ -4 -5 -6 x - 7 -8 ]
  536. [ ]
  537. [ -5 -6 -7 -8 x - 9]
  538. cfmat := coeff_matrix({x+y+4*z=10,y+x-z=20,x+y+4});
  539. cfmat := {
  540. [4 1 1]
  541. [ ]
  542. [-1 1 1]
  543. [ ]
  544. [0 1 1]
  545. ,
  546. [z]
  547. [ ]
  548. [y]
  549. [ ]
  550. [x]
  551. ,
  552. [10]
  553. [ ]
  554. [20]
  555. [ ]
  556. [-4]
  557. }
  558. first cfmat * second cfmat;
  559. [x + y + 4*z]
  560. [ ]
  561. [ x + y - z ]
  562. [ ]
  563. [ x + y ]
  564. third cfmat;
  565. [10]
  566. [ ]
  567. [20]
  568. [ ]
  569. [-4]
  570. companion(poly,x);
  571. [0 0 0 0 0 0 -12]
  572. [ ]
  573. [1 0 0 0 0 0 0 ]
  574. [ ]
  575. [0 1 0 0 0 0 0 ]
  576. [ ]
  577. [0 0 1 0 0 0 -5 ]
  578. [ ]
  579. [0 0 0 1 0 0 -4 ]
  580. [ ]
  581. [0 0 0 0 1 0 -1 ]
  582. [ ]
  583. [0 0 0 0 0 1 0 ]
  584. hessian(poly1,{w,x,y,z});
  585. [0 0 0 0 ]
  586. [ ]
  587. [ 2 3 2 ]
  588. [0 2 3*y + z + 1 3*y*z ]
  589. [ ]
  590. [ 2 3 2 ]
  591. [0 3*y + z + 1 6*x*y 3*x*z ]
  592. [ ]
  593. [ 2 2 ]
  594. [0 3*y*z 3*x*z 6*x*y*z]
  595. hilbert(4,1);
  596. [ 1 1 1 ]
  597. [ 1 --- --- ---]
  598. [ 2 3 4 ]
  599. [ ]
  600. [ 1 1 1 1 ]
  601. [--- --- --- ---]
  602. [ 2 3 4 5 ]
  603. [ ]
  604. [ 1 1 1 1 ]
  605. [--- --- --- ---]
  606. [ 3 4 5 6 ]
  607. [ ]
  608. [ 1 1 1 1 ]
  609. [--- --- --- ---]
  610. [ 4 5 6 7 ]
  611. hilbert(3,y+x);
  612. [ - 1 - 1 - 1 ]
  613. [----------- ----------- -----------]
  614. [ x + y - 2 x + y - 3 x + y - 4 ]
  615. [ ]
  616. [ - 1 - 1 - 1 ]
  617. [----------- ----------- -----------]
  618. [ x + y - 3 x + y - 4 x + y - 5 ]
  619. [ ]
  620. [ - 1 - 1 - 1 ]
  621. [----------- ----------- -----------]
  622. [ x + y - 4 x + y - 5 x + y - 6 ]
  623. jacobian({x^4,x*y^2,x*y*z^3},{w,x,y,z});
  624. [ 3 ]
  625. [0 4*x 0 0 ]
  626. [ ]
  627. [ 2 ]
  628. [0 y 2*x*y 0 ]
  629. [ ]
  630. [ 3 3 2]
  631. [0 y*z x*z 3*x*y*z ]
  632. jordan_block(x,5);
  633. [x 1 0 0 0]
  634. [ ]
  635. [0 x 1 0 0]
  636. [ ]
  637. [0 0 x 1 0]
  638. [ ]
  639. [0 0 0 x 1]
  640. [ ]
  641. [0 0 0 0 x]
  642. make_identity(11);
  643. [1 0 0 0 0 0 0 0 0 0 0]
  644. [ ]
  645. [0 1 0 0 0 0 0 0 0 0 0]
  646. [ ]
  647. [0 0 1 0 0 0 0 0 0 0 0]
  648. [ ]
  649. [0 0 0 1 0 0 0 0 0 0 0]
  650. [ ]
  651. [0 0 0 0 1 0 0 0 0 0 0]
  652. [ ]
  653. [0 0 0 0 0 1 0 0 0 0 0]
  654. [ ]
  655. [0 0 0 0 0 0 1 0 0 0 0]
  656. [ ]
  657. [0 0 0 0 0 0 0 1 0 0 0]
  658. [ ]
  659. [0 0 0 0 0 0 0 0 1 0 0]
  660. [ ]
  661. [0 0 0 0 0 0 0 0 0 1 0]
  662. [ ]
  663. [0 0 0 0 0 0 0 0 0 0 1]
  664. on rounded;
  665. % makes things a bit easier to read.
  666. random_matrix(3,3,100);
  667. [ - 28.8708957912 - 83.4775707772 - 22.5350939803]
  668. [ ]
  669. [ - 83.4775707772 35.4030294062 5.76473742166 ]
  670. [ ]
  671. [ - 22.5350939803 5.76473742166 74.9835325987 ]
  672. on not_negative;
  673. random_matrix(3,3,100);
  674. [52.1649704637 63.7238994877 0.886186275566]
  675. [ ]
  676. [63.7238994877 18.6365765396 77.194379299 ]
  677. [ ]
  678. [0.886186275566 77.194379299 4.09332974714 ]
  679. on only_integer;
  680. random_matrix(3,3,100);
  681. [49 42 67]
  682. [ ]
  683. [42 69 84]
  684. [ ]
  685. [67 84 31]
  686. on symmetric;
  687. random_matrix(3,3,100);
  688. [73 63 85]
  689. [ ]
  690. [63 5 81]
  691. [ ]
  692. [85 81 35]
  693. off symmetric;
  694. on upper_matrix;
  695. random_matrix(3,3,100);
  696. [4 70 28]
  697. [ ]
  698. [0 7 58]
  699. [ ]
  700. [0 0 19]
  701. off upper_matrix;
  702. on lower_matrix;
  703. random_matrix(3,3,100);
  704. [7 0 0 ]
  705. [ ]
  706. [46 49 0 ]
  707. [ ]
  708. [42 70 65]
  709. off lower_matrix;
  710. on imaginary;
  711. off not_negative;
  712. random_matrix(3,3,100);
  713. [ 38*i - 14 - 72*i + 19 51*i - 30 ]
  714. [ ]
  715. [ - 99*i + 72 94*i - 59 3*i - 46 ]
  716. [ ]
  717. [ 47*i - 54 - 9*i - 73*i - 28]
  718. off rounded;
  719. % toeplitz and vandermonde can take both a list of arguments or just
  720. % the arguments.
  721. toeplitz({1,2,3,4,5});
  722. [1 2 3 4 5]
  723. [ ]
  724. [2 1 2 3 4]
  725. [ ]
  726. [3 2 1 2 3]
  727. [ ]
  728. [4 3 2 1 2]
  729. [ ]
  730. [5 4 3 2 1]
  731. toeplitz(x,y,z);
  732. [x y z]
  733. [ ]
  734. [y x y]
  735. [ ]
  736. [z y x]
  737. vandermonde({1,2,3,4,5});
  738. [1 1 1 1 1 ]
  739. [ ]
  740. [1 2 4 8 16 ]
  741. [ ]
  742. [1 3 9 27 81 ]
  743. [ ]
  744. [1 4 16 64 256]
  745. [ ]
  746. [1 5 25 125 625]
  747. vandermonde(x,y,z);
  748. [ 2]
  749. [1 x x ]
  750. [ ]
  751. [ 2]
  752. [1 y y ]
  753. [ ]
  754. [ 2]
  755. [1 z z ]
  756. % kronecker_product
  757. a1 := mat((1,2),(3,4),(5,6));
  758. [1 2]
  759. [ ]
  760. a1 := [3 4]
  761. [ ]
  762. [5 6]
  763. a2 := mat((1,x,1),(2,2,2),(3,3,3));
  764. [1 x 1]
  765. [ ]
  766. a2 := [2 2 2]
  767. [ ]
  768. [3 3 3]
  769. kronecker_product(a1,a2);
  770. [1 x 1 2 2*x 2 ]
  771. [ ]
  772. [2 2 2 4 4 4 ]
  773. [ ]
  774. [3 3 3 6 6 6 ]
  775. [ ]
  776. [3 3*x 3 4 4*x 4 ]
  777. [ ]
  778. [6 6 6 8 8 8 ]
  779. [ ]
  780. [9 9 9 12 12 12]
  781. [ ]
  782. [5 5*x 5 6 6*x 6 ]
  783. [ ]
  784. [10 10 10 12 12 12]
  785. [ ]
  786. [15 15 15 18 18 18]
  787. clear a1,a2;
  788. % High level algorithms.
  789. on rounded;
  790. % makes output easier to read.
  791. ch := cholesky(mat7);
  792. ch := {
  793. [1 0 0 ]
  794. [ ]
  795. [1 1.41421356237 0 ]
  796. [ ]
  797. [0 0.707106781187 0.707106781187]
  798. ,
  799. [1 1 0 ]
  800. [ ]
  801. [0 1.41421356237 0.707106781187]
  802. [ ]
  803. [0 0 0.707106781187]
  804. }
  805. tp first ch - second ch;
  806. [0 0 0]
  807. [ ]
  808. [0 0 0]
  809. [ ]
  810. [0 0 0]
  811. tmp := first ch * second ch;
  812. [1 1 0]
  813. [ ]
  814. tmp := [1 3.0 1]
  815. [ ]
  816. [0 1 1]
  817. tmp - mat7;
  818. [0 0 0]
  819. [ ]
  820. [0 0 0]
  821. [ ]
  822. [0 0 0]
  823. off rounded;
  824. gram_schmidt({1,0,0},{1,1,0},{1,1,1});
  825. {{1,0,0},{0,1,0},{0,0,1}}
  826. gram_schmidt({1,2},{3,4});
  827. 1 2 2*sqrt(5) - sqrt(5)
  828. {{---------,---------},{-----------,------------}}
  829. sqrt(5) sqrt(5) 5 5
  830. on rounded;
  831. % again, makes large quotients a bit more readable.
  832. % The algorithm used for lu_decom sometimes swaps the rows of the input
  833. % matrix so that (given matrix A, lu_decom(A) = {L,U,vec}), we find L*U
  834. % does not equal A but a row equivalent of it. The call convert(A,vec)
  835. % will return this row equivalent (ie: L*U = convert(A,vec)).
  836. lu := lu_decom(mat5);
  837. lu := {
  838. [4 0 0 0 ]
  839. [ ]
  840. [1 0.75 0 0 ]
  841. [ ]
  842. [1 0.75 2.0 0 ]
  843. [ ]
  844. [3 0.25 4.0 4.33333333333]
  845. ,
  846. [1 1.25 0.25 0.5 ]
  847. [ ]
  848. [0 1 1 0.666666666667]
  849. [ ]
  850. [0 0 1 0 ]
  851. [ ]
  852. [0 0 0 1 ]
  853. ,
  854. [3,3,3,4]}
  855. mat5;
  856. [1 2 1 1]
  857. [ ]
  858. [1 2 3 1]
  859. [ ]
  860. [4 5 1 2]
  861. [ ]
  862. [3 4 5 6]
  863. tmp := first lu * second lu;
  864. [4 5.0 1 2.0]
  865. [ ]
  866. [1 2.0 1 1 ]
  867. tmp := [ ]
  868. [1 2.0 3.0 1 ]
  869. [ ]
  870. [3 4.0 5.0 6.0]
  871. tmp1 := convert(mat5,third lu);
  872. [4 5 1 2]
  873. [ ]
  874. [1 2 1 1]
  875. tmp1 := [ ]
  876. [1 2 3 1]
  877. [ ]
  878. [3 4 5 6]
  879. tmp - tmp1;
  880. [0 0 0 0]
  881. [ ]
  882. [0 0 0 0]
  883. [ ]
  884. [0 0 0 0]
  885. [ ]
  886. [0 0 0 0]
  887. % and the complex case...
  888. lu1 := lu_decom(mat6);
  889. lu1 := {
  890. [ 1 0 0 ]
  891. [ ]
  892. [ 4 - 4*i + 5 0 ]
  893. [ ]
  894. [i + 1 3 0.414634146341*i + 2.26829268293]
  895. ,
  896. [1 i 0 ]
  897. [ ]
  898. [0 1 0.19512195122*i + 0.243902439024]
  899. [ ]
  900. [0 0 1 ]
  901. ,
  902. [3,2,3]}
  903. mat6;
  904. [i + 1 i + 2 i + 3]
  905. [ ]
  906. [ 4 5 2 ]
  907. [ ]
  908. [ 1 i 0 ]
  909. tmp := first lu1 * second lu1;
  910. [ 1 i 0 ]
  911. [ ]
  912. tmp := [ 4 5 2.0 ]
  913. [ ]
  914. [i + 1 i + 2 i + 3.0]
  915. tmp1 := convert(mat6,third lu1);
  916. [ 1 i 0 ]
  917. [ ]
  918. tmp1 := [ 4 5 2 ]
  919. [ ]
  920. [i + 1 i + 2 i + 3]
  921. tmp - tmp1;
  922. [0 0 0]
  923. [ ]
  924. [0 0 0]
  925. [ ]
  926. [0 0 0]
  927. mat9inv := pseudo_inverse(mat9);
  928. [ - 0.199999999996 0.100000000013 ]
  929. [ ]
  930. [ - 0.0499999999988 0.0500000000037 ]
  931. mat9inv := [ ]
  932. [ 0.0999999999982 - 5.57816640101e-12]
  933. [ ]
  934. [ 0.249999999995 - 0.0500000000148 ]
  935. mat9 * mat9inv;
  936. [ 0.999999999982 - 0.0000000000557817125824]
  937. [ ]
  938. [5.54201129432e-12 1.00000000002 ]
  939. simplex(min,2*x1+14*x2+36*x3,{-2*x1+x2+4*x3>=5,-x1-2*x2-3*x3<=2});
  940. {45.0,{x1=0,x2=0,x3=1.25}}
  941. simplex(max,10000 x1 + 1000 x2 + 100 x3 + 10 x4 + x5,{ x1 <= 1, 20 x1 +
  942. x2 <= 100, 200 x1 + 20 x2 + x3 <= 10000, 2000 x1 + 200 x2 + 20 x3 + x4
  943. <= 1000000, 20000 x1 + 2000 x2 + 200 x3 + 20 x4 + x5 <= 100000000});
  944. {1.0e+8,{x1=0,x2=0,x3=0,x4=0,x5=100000000.0}}
  945. simplex(max, 5 x1 + 4 x2 + 3 x3,
  946. { 2 x1 + 3 x2 + x3 <= 5,
  947. 4 x1 + x2 + 2 x3 <= 11,
  948. 3 x1 + 4 x2 + 2 x3 <= 8 });
  949. {13.0,{x1=2.0,x2=0,x3=1.0}}
  950. simplex(min,3 x1 + 5 x2,{ x1 + 2 x2 >= 2, 22 x1 + x2 >= 3});
  951. {5.04651162791,{x1=0.093023255813953,x2=0.95348837209302}}
  952. simplex(max,10x+5y+5.5z,{5x+3z<=200,0.2x+0.1y+0.5z<=12,0.1x+0.2y+0.3z<=9,
  953. 30x+10y+50z<=1500});
  954. {525.0,{x=40.0,y=25.0,z=0}}
  955. %example of extra variables (>=0) being added.
  956. simplex(min,x-y,{x>=-3});
  957. *** Warning: variable y not defined in input. Has been defined as >=0.
  958. ***** Error in simplex: The problem is unbounded.
  959. % unfeasible as simplex algorithm implies all x>=0.
  960. simplex(min,x,{x<=-100});
  961. ***** Error in simplex: Problem has no feasible solution.
  962. % three error examples.
  963. simplex(maxx,x,{x>=5});
  964. ***** Error in simplex(first argument): must be either max or min.
  965. simplex(max,x,x>=5);
  966. ***** Error in simplex(third argument}: must be a list.
  967. simplex(max,x,{x<=y});
  968. ***** Error in simplex(third argument):
  969. ***** right hand side of each inequality must be a number
  970. simplex(max, 346 X11 + 346 X12 + 248 X21 + 248 X22 + 399 X31 + 399 X32 +
  971. 200 Y11 + 200 Y12 + 75 Y21 + 75 Y22 + 2.35 Z1 + 3.5 Z2,
  972. {
  973. 4 X11 + 4 X12 + 2 X21 + 2 X22 + X31 + X32 + 250 Y11 + 250 Y12 + 125 Y21 +
  974. 125 Y22 <= 25000,
  975. X11 + X12 + X21 + X22 + X31 + X32 + 2 Y11 + 2 Y12 + Y21 + Y22 <= 300,
  976. 20 X11 + 15 X12 + 30 Y11 + 20 Y21 + Z1 <= 1500,
  977. 40 X12 + 35 X22 + 50 X32 + 15 Y12 + 10 Y22 + Z2 = 5000,
  978. X31 = 0,
  979. Y11 + Y12 <= 50,
  980. Y21 + Y22 <= 100
  981. });
  982. {99250.0,
  983. {y21=0,
  984. y22=0,
  985. x31=0,
  986. x11=75.0,
  987. z1=0,
  988. x21=225.0,
  989. z2=5000.0,
  990. x32=0,
  991. x22=0,
  992. x12=0,
  993. y12=0,
  994. y11=0}}
  995. % from Marc van Dongen. Finding the first feasible solution for the
  996. % solution of systems of linear diophantine inequalities.
  997. simplex(max,0,{
  998. 3*X259+4*X261+3*X262+2*X263+X269+2*X270+3*X271+4*X272+5*X273+X229=2,
  999. 7*X259+11*X261+8*X262+5*X263+3*X269+6*X270+9*X271+12*X272+15*X273+X229=4,
  1000. 2*X259+5*X261+4*X262+3*X263+3*X268+4*X269+5*X270+6*X271+7*X272+8*X273=1,
  1001. X262+2*X263+5*X268+4*X269+3*X270+2*X271+X272+2*X229=1,
  1002. X259+X262+2*X263+4*X268+3*X269+2*X270+X271-X273+3*X229=2,
  1003. X259+2*X261+2*X262+2*X263+3*X268+3*X269+3*X270+3*X271+3*X272+3*X273+X229=1,
  1004. X259+X261+X262+X263+X268+X269+X270+X271+X272+X273+X229=1});
  1005. {0,
  1006. {x229=0.5,
  1007. x259=0.5,
  1008. x261=0,
  1009. x262=0,
  1010. x263=0,
  1011. x268=0,
  1012. x269=0,
  1013. x270=0,
  1014. x271=0,
  1015. x272=0,
  1016. x273=0}}
  1017. svd_ans := svd(mat8);
  1018. svd_ans := {
  1019. [ 0.289784137735 0.957092029805]
  1020. [ ]
  1021. [ - 0.957092029805 0.289784137735]
  1022. ,
  1023. [5.1491628629 0 ]
  1024. [ ]
  1025. [ 0 2.9130948854]
  1026. ,
  1027. [ - 0.687215403194 0.726453707825 ]
  1028. [ ]
  1029. [ - 0.726453707825 - 0.687215403194]
  1030. }
  1031. tmp := tp first svd_ans * second svd_ans * third svd_ans;
  1032. [ 0.99999998509 2.9999999859 ]
  1033. tmp := [ ]
  1034. [ - 4.00000004924 2.99999995342]
  1035. tmp - mat8;
  1036. [ - 0.0000000149096008872 - 0.0000000141042817425]
  1037. [ ]
  1038. [ - 0.0000000492430629606 - 0.0000000465832750152]
  1039. mat9inv := pseudo_inverse(mat9);
  1040. [ - 0.199999999996 0.100000000013 ]
  1041. [ ]
  1042. [ - 0.0499999999988 0.0500000000037 ]
  1043. mat9inv := [ ]
  1044. [ 0.0999999999982 - 5.57816640101e-12]
  1045. [ ]
  1046. [ 0.249999999995 - 0.0500000000148 ]
  1047. mat9 * mat9inv;
  1048. [ 0.999999999982 - 0.0000000000557817125824]
  1049. [ ]
  1050. [5.54201129432e-12 1.00000000002 ]
  1051. % Predicates.
  1052. matrixp(mat1);
  1053. t
  1054. matrixp(poly);
  1055. squarep(mat2);
  1056. t
  1057. squarep(mat3);
  1058. symmetricp(mat1);
  1059. t
  1060. symmetricp(mat3);
  1061. if not rounded_was_on then off rounded;
  1062. END;
  1063. (TIME: linalg 3359 3469)