Unformatted text preview:

mma.txt Mathematica Sessions Math 1b prac Jan 13, 2010 You can copy and paste material from these notes into Mathematica, like the definition of pivot. There are two sessions, each four pages. To enter a matrix into Mathematica, use A = {{1,2,3,4}, {5,6,7,8}} , and press <shift-Enter>. This is a 2 x 4 matrix. Use MatrixForm[A] and <shift-Enter> if you want to see it displayed as an array. Page 1Mathematica Session 1Math 1b January 7, 2009At In[35], we teach Mathematica to generate "random" matrices of a given size.The entries aill be integers between 0 and 10.At Out[37] and Out[38], we show the results of a row operation and the inverse rowoperation on the matrix in Out[36]. We use row operations on the matrix at Out[38] to obtain a matrix at Out[46] whosefirst column is [1,0,0].At In[47], we teach Mathematica to do a pivot operation on a gIven matrix at a given position.Do not try to pivot on a position with a zero entry, or YOU'LL BE SORRY!We generate a 5 by 8 matrix at In[49] and use pivot operations until we obtainthe matrix at Out[54], which is in echelon form.THEN we remember that Mathematica already knows how to calculate echelon formsof matrices (so our work in writing a pivot operation routine was perhaps unnecessary,but it was fun). Just use RowReduce[M]. At Out[55], Out[56], and Out[57], we show theechelon form of the three matrices shown just above the outputs.In[35]:=rand@m_,n_D :=Table@RandomInteger@10D, 8i, m<, 8j, n<DIn[36]:=MatrixForm@M = rand@3, 5DDOut[36]//MatrixForm=471822211605343In[37]:=M@@1DD = M@@1DD + 23 M@@2 DD; MatrixForm@MDOut[37]//MatrixForm=50 53 24 31 1402211605343In[38]:=M@@1DD = M@@1DD − 23 M@@2 DD; MatrixForm@MDOut[38]//MatrixForm=471822211605343In[39]:=M@@1DD = M@@1DD − 2M@@2DD; MatrixForm@MDOut[39]//MatrixForm=03−16−10221 16053 43In[40]:=temp = M@@1DD;M@@1DD = M@@2DD;M@@2DD = temp ; MatrixForm@MDOut[40]//MatrixForm=221 1603−16−10053 43In[46]:=M@@1DD = H1 ê 2L M@@1DD; MatrixForm@MDOut[46]//MatrixForm=111212303−16 −10053 43In[47]:=pivot@M_,i_,j_D := Block@8m<,m= M; m@@iDD = m@@iDD ê m@@i, jDD;Do@If@k  i, , m@@kDD = m@@kDD − m@@k, jDD m@@iDDD, 8k, Length@mD<D;mD In[49]:=M = rand@5, 8D ; MatrixForm@MDOut[49]//MatrixForm=36083406193098945538367102430878479661518In[50]:=M = pivot@M, 1, 1D; MatrixForm@MDOut[50]//MatrixForm=12 0831430207 3−838203920 −53−163−2 −237000 3−1636133800 −56−383−6 −1331 −6In[51]:=M = pivot@M, 2, 2D; MatrixForm@MDOut[51]//MatrixForm=10−67247−97−47−1871070137−821872021972700367−152212678621947107003 −16361338000577−1027−2737527−327In[52]:=M = pivot@M, 3, 3D; MatrixForm@MDOut[52]//MatrixForm=100209−2319−1353010295611181616001−3827131843544718518000−109236351816−56000−289−376−10918−836−416In[53]:=M = pivot@M, 4, 4D; MatrixForm@MDOut[53]//MatrixForm=10007 4 0 001008511500010−6215−53125430001−6920−74−320340000−16910−232−14310−92In[54]:=M = pivot@M, 5, 5D; MatrixForm@MDOut[54]//MatrixForm=10000−129169−7713−31516901000−15169−1513−7216900100581507230391234507000101011693613282169000011151691113451692 Untitled-2In[55]:=M = rand@5, 8D; Print@MatrixForm@MDD; MatrixForm@RowReduce@MDD3101 9193250 0 65741082 109103724 1 6838654 9 55971Out[55]//MatrixForm=1000028 6545467−4385467854970100015 238546711825467−98399400100−7841546712945467−20849700010−205515467−275467635497000015237816927812171In[56]:=M = rand@5, 8D; Print@MatrixForm@MDD; MatrixForm@RowReduce@MDD39 4107 1 71094 74 0 0 0911092985706 15 10106968 34 108 55Out[56]//MatrixForm=1000041612213−103531−10401221301000−26 98112 213205531−36 35812 213001001415612 213−795312567512 21300010424407155177708240710000126 35012 21312153119 61612 213In[57]:=M = rand@5, 8D; Print@MatrixForm@MDD; MatrixForm@RowReduce@MDD0959995 74900301034128897 13786482 20591583 7Out[57]//MatrixForm=10000978617356396173−3987617301000−349512 34618826173198361730010016 31724 692−523112 346985617300010686324692−882312346−32696173000017877123467412617355406173Untitled-2 3mma2.txtMathematica Session 2Math 1b January 16, 2009On the next page, we calculate the inverse of a "random" 5 by 5 matrix.On the following pages, we try to find a nonnegative solution to a system of linear equations Ax = b . We fail. But by carrying along an identitymatrix in our computations, we produce a vector y so that yA >= 0 but yb < 0 .Page 1rand@m_,n_D :=Table@RandomInteger@10D, 8i, m<, 8j, n<DAA = A = rand@5, 5D; MatrixForm@AD8108458164731064910 1 3 8 220554Do@ AA@@iDD = Join@ AA@@iDD, IdentityMatrix@5D@@iDD D, 8i, 5<D ; MatrixForm@AAD8 10845100008 1 647010003 1064900100101 382000102 0 55400001AA = RowReduce@AAD; MatrixForm@AAD1000038916 115153816 115−61116 115621465−214416 1150100071116 115−137316 11599616 115381465−93616 115001002631161158716115−243416115−187146530641611500010−2013223−4553223208322335293387322300001−222716 115196616 115204816 115−161465−114816 115B = AA@@ 81, 2, 3, 4, 5<, 86, 7, 8, 9, 10<DD; MatrixForm@BD38916 115153816 115−61116 115621465−214416 11571116 115−137316 11599616 115381465−93616 115263116 1158716 115−243416 115−1871465306416 115−2013223−45532232083223352933873223−222716115196616115204816115−161465−114816115B.A881, 0, 0, 0, 0<, 80, 1, 0, 0, 0<, 80, 0, 1, 0, 0<, 80, 0, 0, 1, 0<, 80, 0, 0, 0, 1<<A.B881, 0, 0, 0, 0<, 80, 1, 0, 0, 0<, 80, 0, 1, 0, 0<, 80, 0, 0, 1, 0<, 80, 0, 0, 0, 1<<pivot@M_,i_,j_D :=Block@8m<,m= M; m@@iDD = m@@iDD ê m@@i, jDD;Do@If@k  i, , m@@kDD = m@@kDD − m@@k, jDD m@@iDDD, 8k, Length@mD<D;mDrand@m_,n_D := Table@RandomInteger@10D, 8i, m <, 8j, n<DA = AA = rand@5, 9D; MatrixForm@AD281 31 10493232 01 7 88512104105 597945 75 2 687534 16 9 559Do@ A@@iDD = Join@ A@@iDD, 88<<, IdentityMatrix@5D@@iDD D, 8i, 5<D ; MatrixForm@AD281 31 104938< 10000232 01 7 8858< 0100012104105 5978< 00100945 75 2 6878< 00010534 16 9 5598< 00001A = pivot@A, 1, 1D; MatrixForm@AD141232125292328<1200000 −51−30−34 −12 8< −1 10000 −21925219203921128< −1201000 −3212−13212−43 −12 −652−1328< −9200100 −1732−13272−16 −5 −352328< −520001A = pivot@A, 2, 2D;A= pivot@A, 3, 3D;A= pivot@A, 4, 4D;A= pivot@A, 5, 5D; MatrixForm@AD1000040112064214022566033714028<


View Full Document
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?