213 - A10 - Row Reduction

27 days ago by Professor213

Row Reduction using Gauss-Jordan Elimination - In this worksheet, the user enters the coefficients for a $MxN$ linear system.  The intermediate steps for perfoming Gauss-Jordan Elimination are output.  The user can choose a random matrix of given dimension or enter a specific matrix.  The user can also choose to perform only regular echelon form where only the entries below the main diagonal are zeroed out.

John Travis

Mississippi College

Assignment...using the cells below, create a 4x5 problem where the worksheet creates the matrix randomly.  Then, write out the elimination commands needed for each of step along the way in reducing the original matrix to reduced row echelon form--RREF.  Put your answers at the bottom of this worksheet with the commands for each stage in a different text box.

For example, you might write:

Step 1:

$-3*R_1+R_3\rightarrow R_3$ , or without using latex and just using text, -3 R1 + R3 -> R3

blah, blah, blah

Step 2:

blah, blah, blah

%hide %auto M=3 N=3 print html("<font size=+2 color=blue>For your system, first select the number of rows and columns.</font> <br><p>") @interact def _(Rows=[3,4,5,6],Cols=[3,4,5,6,7],auto_update=True): global M,N M = Rows N = Cols return M,N 
       
<font size=+2 color=blue>For your system, first select the number of rows and columns.</font> <br><p>
Rows 
Cols 
auto_update 

Click to the left again to hide and once more to show the dynamic interactive window

print M,N # Or you can uncomment the two lines below and set rows/columns manually 
       
3 4
3 4
%auto # You may need to evaluate this cell to implement the remainder of this assignment # This cell takes an input (or randomly created rational) matrix and outputs the Gauss-Jordan result # following each step in the process. pretty_print(html("<font size=+2 color=blue>Enter your data below. You can tab to navigate between cells. Click Update when you are finished. If you want a random matrix, click the box and then update.</font><p>")) global Astart,A Astart = zero_matrix(QQ,M,N) @interact def _(Input_Matrix=Astart,reduced_echelon_form=True, auto_update=False,Make_it_random=False): if Make_it_random: A = random_matrix(QQ,M,N,num_bound=20, den_bound=4) else: A = Input_Matrix # if A.det()==0: # print html("<font size=+1 color=red>Matrix is Singular. Please pick another!</font>") pretty_print(html("<font size=+2 color=blue>Using the matrix</font>")) show(A) global Astart,A Astart = copy(A) # Now, let's start the step by step Gauss-Jordan routine ROWS = range(M) COLS = range(N) PIVOTS = range(min(M,N)) for i in PIVOTS: # Gauss-Jordan on column i # First, make the pivot element equal to 1 k = i # Need to fix this when a column is skipped when finding nonzero pivots # That is, if the remainder of a column is zero, go on to the next column till you reach the end. if A[i][i]==0: # swap for non-zero pivot # start looking in rows below the i-th while (k<M and A[k][i]==0): k += 1 if k==M: print 'All of the remaining rows are zero. Move to next columns or finish.' else: A.swap_rows(i,k) # So, now we should have a non-zero in the pivot position or k=M which means we are done. # Should consider using the function "nonzero_positions_in_column(i)" and use the min position > i. # Start zeroing out the rest of column i. if A[i][i]<>0: A[i]=A[i]/A[i][i] if reduced_echelon_form: for k in ROWS: if i<>k: A[k] = A[k]-A[i]*A[k][i] else: for k in ROWS: if i<k: A[k] = A[k]-A[i]*A[k][i] print '\n After',i+1,'step(s) the matrix is equivalent to:' show(A) 
       
/tmp/tmpTZWMIJ/___code___.py:22: SyntaxWarning: name 'A' is assigned to before global declaration global Astart,A Enter your data below. You can tab to navigate between cells. Click Update when you are finished. If you want a random matrix, click the box and then update.

Input_Matrix 
reduced_echelon_form 
Make_it_random 

Click to the left again to hide and once more to show the dynamic interactive window

A[:,6] 
       
[-143517328496/53053689231]
[ -73736537192/17684563077]
[414748958461/212214756924]
[  71825344772/17684563077]
[ -80902442762/53053689231]
[  -4684159075/11789708718]
[-143517328496/53053689231]
[ -73736537192/17684563077]
[414748958461/212214756924]
[  71825344772/17684563077]
[ -80902442762/53053689231]
[  -4684159075/11789708718]
Astart[:,0:6]*A[:,6] 
       
[   2]
[-7/2]
[17/4]
[ -19]
[   7]
[  -1]
[   2]
[-7/2]
[17/4]
[ -19]
[   7]
[  -1]
# In decimal form, the final column for k in range(M): n(A[k][N-1],digits=6) 
       
0.0723788
-0.220401
0.767584
0.152657
-1.01164
0.0723788
-0.220401
0.767584
0.152657
-1.01164
show(Astart) 
       

                                
                            

                                
# The matrix you eventually used above was Astart 
       
[  3/2  -7/2  -7/2    -3  -5/4    -1]
[ -7/4    -1     3  -3/4  11/4  -1/2]
[    0 -13/4    -4   -16    -4  -3/4]
[   -5    -3  -5/2    10    -8     8]
[  -19    -3    -6 -20/3  -1/3    -6]
[  3/2  -7/2  -7/2    -3  -5/4    -1]
[ -7/4    -1     3  -3/4  11/4  -1/2]
[    0 -13/4    -4   -16    -4  -3/4]
[   -5    -3  -5/2    10    -8     8]
[  -19    -3    -6 -20/3  -1/3    -6]
# For saving your matrix for later use, cut and paste the result from above into the correct spot below. # To use this again, you will need to add the correct number of commas in the right places. My_A = matrix([ [ 1, -34/9, -1, 1/2, 2, -2], [ -1, -2, 3, -1, 1, 1/2], [ -3/4, 1/2, 1/3, -1/2, 1/6, 3/2], [ 3, 1/4, -1/14, 7/361, -4/3, -4] ]) 
       

STEP 1:

Double click on this text to enter step 1:

STEP 2:

Double click on this text to enter step 2:

STEP 3:

Double click on this text to enter step 3:

STEP 4:

Double click on this text to enter step 4:

pi.n(digits=10000) 
       
3.1415926535897932384626433832795028841971693993751058209749445923078164\
062862089986280348253421170679821480865132823066470938446095505822317253\
594081284811174502841027019385211055596446229489549303819644288109756659\
334461284756482337867831652712019091456485669234603486104543266482133936\
072602491412737245870066063155881748815209209628292540917153643678925903\
600113305305488204665213841469519415116094330572703657595919530921861173\
819326117931051185480744623799627495673518857527248912279381830119491298\
336733624406566430860213949463952247371907021798609437027705392171762931\
767523846748184676694051320005681271452635608277857713427577896091736371\
787214684409012249534301465495853710507922796892589235420199561121290219\
608640344181598136297747713099605187072113499999983729780499510597317328\
160963185950244594553469083026425223082533446850352619311881710100031378\
387528865875332083814206171776691473035982534904287554687311595628638823\
537875937519577818577805321712268066130019278766111959092164201989380952\
572010654858632788659361533818279682303019520353018529689957736225994138\
912497217752834791315155748572424541506959508295331168617278558890750983\
817546374649393192550604009277016711390098488240128583616035637076601047\
101819429555961989467678374494482553797747268471040475346462080466842590\
694912933136770289891521047521620569660240580381501935112533824300355876\
402474964732639141992726042699227967823547816360093417216412199245863150\
302861829745557067498385054945885869269956909272107975093029553211653449\
872027559602364806654991198818347977535663698074265425278625518184175746\
728909777727938000816470600161452491921732172147723501414419735685481613\
611573525521334757418494684385233239073941433345477624168625189835694855\
620992192221842725502542568876717904946016534668049886272327917860857843\
838279679766814541009538837863609506800642251252051173929848960841284886\
269456042419652850222106611863067442786220391949450471237137869609563643\
719172874677646575739624138908658326459958133904780275900994657640789512\
694683983525957098258226205224894077267194782684826014769909026401363944\
374553050682034962524517493996514314298091906592509372216964615157098583\
874105978859597729754989301617539284681382686838689427741559918559252459\
539594310499725246808459872736446958486538367362226260991246080512438843\
904512441365497627807977156914359977001296160894416948685558484063534220\
722258284886481584560285060168427394522674676788952521385225499546667278\
239864565961163548862305774564980355936345681743241125150760694794510965\
960940252288797108931456691368672287489405601015033086179286809208747609\
178249385890097149096759852613655497818931297848216829989487226588048575\
640142704775551323796414515237462343645428584447952658678210511413547357\
395231134271661021359695362314429524849371871101457654035902799344037420\
073105785390621983874478084784896833214457138687519435064302184531910484\
810053706146806749192781911979399520614196634287544406437451237181921799\
983910159195618146751426912397489409071864942319615679452080951465502252\
316038819301420937621378559566389377870830390697920773467221825625996615\
014215030680384477345492026054146659252014974428507325186660021324340881\
907104863317346496514539057962685610055081066587969981635747363840525714\
591028970641401109712062804390397595156771577004203378699360072305587631\
763594218731251471205329281918261861258673215791984148488291644706095752\
706957220917567116722910981690915280173506712748583222871835209353965725\
121083579151369882091444210067510334671103141267111369908658516398315019\
701651511685171437657618351556508849099898599823873455283316355076479185\
358932261854896321329330898570642046752590709154814165498594616371802709\
819943099244889575712828905923233260972997120844335732654893823911932597\
463667305836041428138830320382490375898524374417029132765618093773444030\
707469211201913020330380197621101100449293215160842444859637669838952286\
847831235526582131449576857262433441893039686426243410773226978028073189\
154411010446823252716201052652272111660396665573092547110557853763466820\
653109896526918620564769312570586356620185581007293606598764861179104533\
488503461136576867532494416680396265797877185560845529654126654085306143\
444318586769751456614068007002378776591344017127494704205622305389945613\
140711270004078547332699390814546646458807972708266830634328587856983052\
358089330657574067954571637752542021149557615814002501262285941302164715\
509792592309907965473761255176567513575178296664547791745011299614890304\
639947132962107340437518957359614589019389713111790429782856475032031986\
915140287080859904801094121472213179476477726224142548545403321571853061\
422881375850430633217518297986622371721591607716692547487389866549494501\
146540628433663937900397692656721463853067360965712091807638327166416274\
888800786925602902284721040317211860820419000422966171196377921337575114\
959501566049631862947265473642523081770367515906735023507283540567040386\
743513622224771589150495309844489333096340878076932599397805419341447377\
441842631298608099888687413260472156951623965864573021631598193195167353\
812974167729478672422924654366800980676928238280689964004824354037014163\
149658979409243237896907069779422362508221688957383798623001593776471651\
228935786015881617557829735233446042815126272037343146531977774160319906\
655418763979293344195215413418994854447345673831624993419131814809277771\
038638773431772075456545322077709212019051660962804909263601975988281613\
323166636528619326686336062735676303544776280350450777235547105859548702\
790814356240145171806246436267945612753181340783303362542327839449753824\
372058353114771199260638133467768796959703098339130771098704085913374641\
442822772634659470474587847787201927715280731767907707157213444730605700\
733492436931138350493163128404251219256517980694113528013147013047816437\
885185290928545201165839341965621349143415956258658655705526904965209858\
033850722426482939728584783163057777560688876446248246857926039535277348\
030480290058760758251047470916439613626760449256274204208320856611906254\
543372131535958450687724602901618766795240616342522577195429162991930645\
537799140373404328752628889639958794757291746426357455254079091451357111\
369410911939325191076020825202618798531887705842972591677813149699009019\
211697173727847684726860849003377024242916513005005168323364350389517029\
893922334517220138128069650117844087451960121228599371623130171144484640\
903890644954440061986907548516026327505298349187407866808818338510228334\
508504860825039302133219715518430635455007668282949304137765527939751754\
613953984683393638304746119966538581538420568533862186725233402830871123\
282789212507712629463229563989898935821167456270102183564622013496715188\
190973038119800497340723961036854066431939509790190699639552453005450580\
685501956730229219139339185680344903982059551002263535361920419947455385\
938102343955449597783779023742161727111723643435439478221818528624085140\
066604433258885698670543154706965747458550332323342107301545940516553790\
686627333799585115625784322988273723198987571415957811196358330059408730\
681216028764962867446047746491599505497374256269010490377819868359381465\
741268049256487985561453723478673303904688383436346553794986419270563872\
931748723320837601123029911367938627089438799362016295154133714248928307\
220126901475466847653576164773794675200490757155527819653621323926406160\
136358155907422020203187277605277219005561484255518792530343513984425322\
341576233610642506390497500865627109535919465897514131034822769306247435\
363256916078154781811528436679570611086153315044521274739245449454236828\
860613408414863776700961207151249140430272538607648236341433462351897576\
645216413767969031495019108575984423919862916421939949072362346468441173\
940326591840443780513338945257423995082965912285085558215725031071257012\
668302402929525220118726767562204154205161841634847565169998116141010029\
960783869092916030288400269104140792886215078424516709087000699282120660\
418371806535567252532567532861291042487761825829765157959847035622262934\
860034158722980534989650226291748788202734209222245339856264766914905562\
842503912757710284027998066365825488926488025456610172967026640765590429\
099456815065265305371829412703369313785178609040708667114965583434347693\
385781711386455873678123014587687126603489139095620099393610310291616152\
881384379099042317473363948045759314931405297634757481193567091101377517\
210080315590248530906692037671922033229094334676851422144773793937517034\
436619910403375111735471918550464490263655128162288244625759163330391072\
253837421821408835086573917715096828874782656995995744906617583441375223\
970968340800535598491754173818839994469748676265516582765848358845314277\
568790029095170283529716344562129640435231176006651012412006597558512761\
785838292041974844236080071930457618932349229279650198751872127267507981\
255470958904556357921221033346697499235630254947802490114195212382815309\
114079073860251522742995818072471625916685451333123948049470791191532673\
430282441860414263639548000448002670496248201792896476697583183271314251\
702969234889627668440323260927524960357996469256504936818360900323809293\
459588970695365349406034021665443755890045632882250545255640564482465151\
875471196218443965825337543885690941130315095261793780029741207665147939\
425902989695946995565761218656196733786236256125216320862869222103274889\
218654364802296780705765615144632046927906821207388377814233562823608963\
208068222468012248261177185896381409183903673672220888321513755600372798\
394004152970028783076670944474560134556417254370906979396122571429894671\
543578468788614445812314593571984922528471605049221242470141214780573455\
105008019086996033027634787081081754501193071412233908663938339529425786\
905076431006383519834389341596131854347546495569781038293097164651438407\
007073604112373599843452251610507027056235266012764848308407611830130527\
932054274628654036036745328651057065874882256981579367897669742205750596\
834408697350201410206723585020072452256326513410559240190274216248439140\
359989535394590944070469120914093870012645600162374288021092764579310657\
92295524988727584610126483699989225695968815920560010165525637568
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796782354781636009341721641219924586315030286182974555706749838505494588586926995690927210797509302955321165344987202755960236480665499119881834797753566369807426542527862551818417574672890977772793800081647060016145249192173217214772350141441973568548161361157352552133475741849468438523323907394143334547762416862518983569485562099219222184272550254256887671790494601653466804988627232791786085784383827967976681454100953883786360950680064225125205117392984896084128488626945604241965285022210661186306744278622039194945047123713786960956364371917287467764657573962413890865832645995813390478027590099465764078951269468398352595709825822620522489407726719478268482601476990902640136394437455305068203496252451749399651431429809190659250937221696461515709858387410597885959772975498930161753928468138268683868942774155991855925245953959431049972524680845987273644695848653836736222626099124608051243884390451244136549762780797715691435997700129616089441694868555848406353422072225828488648158456028506016842739452267467678895252138522549954666727823986456596116354886230577456498035593634568174324112515076069479451096596094025228879710893145669136867228748940560101503308617928680920874760917824938589009714909675985261365549781893129784821682998948722658804857564014270477555132379641451523746234364542858444795265867821051141354735739523113427166102135969536231442952484937187110145765403590279934403742007310578539062198387447808478489683321445713868751943506430218453191048481005370614680674919278191197939952061419663428754440643745123718192179998391015919561814675142691239748940907186494231961567945208095146550225231603881930142093762137855956638937787083039069792077346722182562599661501421503068038447734549202605414665925201497442850732518666002132434088190710486331734649651453905796268561005508106658796998163574736384052571459102897064140110971206280439039759515677157700420337869936007230558763176359421873125147120532928191826186125867321579198414848829164470609575270695722091756711672291098169091528017350671274858322287183520935396572512108357915136988209144421006751033467110314126711136990865851639831501970165151168517143765761835155650884909989859982387345528331635507647918535893226185489632132933089857064204675259070915481416549859461637180270981994309924488957571282890592323326097299712084433573265489382391193259746366730583604142813883032038249037589852437441702913276561809377344403070746921120191302033038019762110110044929321516084244485963766983895228684783123552658213144957685726243344189303968642624341077322697802807318915441101044682325271620105265227211166039666557309254711055785376346682065310989652691862056476931257058635662018558100729360659876486117910453348850346113657686753249441668039626579787718556084552965412665408530614344431858676975145661406800700237877659134401712749470420562230538994561314071127000407854733269939081454664645880797270826683063432858785698305235808933065757406795457163775254202114955761581400250126228594130216471550979259230990796547376125517656751357517829666454779174501129961489030463994713296210734043751895735961458901938971311179042978285647503203198691514028708085990480109412147221317947647772622414254854540332157185306142288137585043063321751829798662237172159160771669254748738986654949450114654062843366393790039769265672146385306736096571209180763832716641627488880078692560290228472104031721186082041900042296617119637792133757511495950156604963186294726547364252308177036751590673502350728354056704038674351362222477158915049530984448933309634087807693259939780541934144737744184263129860809988868741326047215695162396586457302163159819319516735381297416772947867242292465436680098067692823828068996400482435403701416314965897940924323789690706977942236250822168895738379862300159377647165122893578601588161755782973523344604281512627203734314653197777416031990665541876397929334419521541341899485444734567383162499341913181480927777103863877343177207545654532207770921201905166096280490926360197598828161332316663652861932668633606273567630354477628035045077723554710585954870279081435624014517180624643626794561275318134078330336254232783944975382437205835311477119926063813346776879695970309833913077109870408591337464144282277263465947047458784778720192771528073176790770715721344473060570073349243693113835049316312840425121925651798069411352801314701304781643788518529092854520116583934196562134914341595625865865570552690496520985803385072242648293972858478316305777756068887644624824685792603953527734803048029005876075825104747091643961362676044925627420420832085661190625454337213153595845068772460290161876679524061634252257719542916299193064553779914037340432875262888963995879475729174642635745525407909145135711136941091193932519107602082520261879853188770584297259167781314969900901921169717372784768472686084900337702424291651300500516832336435038951702989392233451722013812806965011784408745196012122859937162313017114448464090389064495444006198690754851602632750529834918740786680881833851022833450850486082503930213321971551843063545500766828294930413776552793975175461395398468339363830474611996653858153842056853386218672523340283087112328278921250771262946322956398989893582116745627010218356462201349671518819097303811980049734072396103685406643193950979019069963955245300545058068550195673022921913933918568034490398205955100226353536192041994745538593810234395544959778377902374216172711172364343543947822181852862408514006660443325888569867054315470696574745855033232334210730154594051655379068662733379958511562578432298827372319898757141595781119635833005940873068121602876496286744604774649159950549737425626901049037781986835938146574126804925648798556145372347867330390468838343634655379498641927056387293174872332083760112302991136793862708943879936201629515413371424892830722012690147546684765357616477379467520049075715552781965362132392640616013635815590742202020318727760527721900556148425551879253034351398442532234157623361064250639049750086562710953591946589751413103482276930624743536325691607815478181152843667957061108615331504452127473924544945423682886061340841486377670096120715124914043027253860764823634143346235189757664521641376796903149501910857598442391986291642193994907236234646844117394032659184044378051333894525742399508296591228508555821572503107125701266830240292952522011872676756220415420516184163484756516999811614101002996078386909291603028840026910414079288621507842451670908700069928212066041837180653556725253256753286129104248776182582976515795984703562226293486003415872298053498965022629174878820273420922224533985626476691490556284250391275771028402799806636582548892648802545661017296702664076559042909945681506526530537182941270336931378517860904070866711496558343434769338578171138645587367812301458768712660348913909562009939361031029161615288138437909904231747336394804575931493140529763475748119356709110137751721008031559024853090669203767192203322909433467685142214477379393751703443661991040337511173547191855046449026365512816228824462575916333039107225383742182140883508657391771509682887478265699599574490661758344137522397096834080053559849175417381883999446974867626551658276584835884531427756879002909517028352971634456212964043523117600665101241200659755851276178583829204197484423608007193045761893234922927965019875187212726750798125547095890455635792122103334669749923563025494780249011419521238281530911407907386025152274299581807247162591668545133312394804947079119153267343028244186041426363954800044800267049624820179289647669758318327131425170296923488962766844032326092752496035799646925650493681836090032380929345958897069536534940603402166544375589004563288225054525564056448246515187547119621844396582533754388569094113031509526179378002974120766514793942590298969594699556576121865619673378623625612521632086286922210327488921865436480229678070576561514463204692790682120738837781423356282360896320806822246801224826117718589638140918390367367222088832151375560037279839400415297002878307667094447456013455641725437090697939612257142989467154357846878861444581231459357198492252847160504922124247014121478057345510500801908699603302763478708108175450119307141223390866393833952942578690507643100638351983438934159613185434754649556978103829309716465143840700707360411237359984345225161050702705623526601276484830840761183013052793205427462865403603674532865105706587488225698157936789766974220575059683440869735020141020672358502007245225632651341055924019027421624843914035998953539459094407046912091409387001264560016237428802109276457931065792295524988727584610126483699989225695968815920560010165525637568