您好,欢迎访问三七文档
Anale.SeriaInformatică.Vol.VIIfasc.1–2009Annals.ComputerScienceSeries.7thTome1stFasc.–200971IItteerraattiivveeMMeetthhooddssffoorrSSyysstteemmss’’SSoollvviinngg--aaCC##aapppprrooaacchhCCllaauuddiiuuCChhiirriilloovv“Tibiscus”UniversityofTimişoara,RomâniaABSTRACT.Thisworkwishestosupportvariousmathematicalissuesconcerningtheiterativemethodswiththehelpofnewprogramminglanguages.Weconsiderawaytoshowhowproblemsinmathhaveananswerbyusingdifferentacademicresourcesanddifferentthoughts.HerewetreatmethodslikeGauss-Seidel’s,Cramer’sandGauss-Jordan’s.KEYWORDS:iterativemethods,CSML,arraysIntroductionNowadays,itseemsthatadeveloper’sproblemisnottosolvemathematicalissuesratherthanfindingsolutionfortheproblemsinreallife.Forthatreason,manyofusdonotknowthatnewtechnologiescomingintoourlifewillnotjustsolvethingslikehowtokeeptrackofeventsorhowtoimproveawebsite’sdesign.Therefore,intheendallproblemshaveamathematicalbackground.Thisarticlewilltreatsomemathematicalstuff,suchasiterativemethodsusinganewprogramminglanguage.Asweallshouldknow,C#isveryflexibleprogramminglanguagethatcombinesfeaturesfrompreviouslanguagesinsuchmannerthatitissoeasytodigestandfuntoworkwith.C#isreallyabetterplaygroundfromthosecomingfromotherprogramminglanguages.Itisthebaseofthe.NETPlatform.1.MathematicalbackgroundInthisarticlewewillstudyandtoanalyzehowsomeoftheclassicaliterativemethodscanbeimplementedinC#forsolvingsystemsoflinearAnale.SeriaInformatică.Vol.VIIfasc.1–2009Annals.ComputerScienceSeries.7thTome1stFasc.–200972equations,liketheCramer’smethod,Gauss-JordanorGauss-Seidell’smethod.Aniterativemethod,incomputationalmathematics,isabouttheattempttosolveaproblembyfindingsuccesiveapproximationstothesolutionstartingfromaninitialguess.Thistypeofsolvingrefersnotjusttononlinearequationsbutitalsoappliestolinearsystemsofequations.Asystemoflinearequations,inmathematics,isacollectionoflinearequationsinwichasetofvariablesverifiesalltheequationsattheend.Let’ssaywehavethefolowingsystemoflinearequations:Thesolutionofthissystemmustsatisfyinthesametimealltheequations.Wewanttosolvethesystembyapplyingdifferentmethodsandalgoritmsforfindingthesolution.Cramer’smethodisbasedonthedeterminantsofthesystemmatrixandtransformedmatrices.Hereishowthemethodworks:a)Computethedeterminantofthesystemmatrix.b)Buildthetransformedmatricesbyreplacingeachcolumnofthesystemmatrixwiththeresultsmatrix.c)Nowforeachtransformedmatrixdivideitsdeterminantbythedeterminantofthesystemmatrix.TheGauss-Jordan’smethodhasmorestepstofollowandperformselementaryoperationsontherowsofthematrix.Thealgorithmsays:a)Iftheyarezero-rows,pushthemtothebottomofthematrix,bysuccesiverowinterchanges.b)Findthefirstcolumncontainingatleastonenonzeroentry.c)Eventuallyinterchangetworowssothatthisnonzeroentrywillbethefirstinthiscolumn.d)Ifthereisanotherrowhavinganon-zeroentryinthiscolumn,sayRi,performthefolowingoperation:RaaRRkikii11−←.Thisreplacesaikby0.e)Iteratethisstepuntilyoureplaceallentriesbelowa1kbyzeros.Anale.SeriaInformatică.Vol.VIIfasc.1–2009Annals.ComputerScienceSeries.7thTome1stFasc.–200973f)Ifthematrixisstillnotinrow-echelonform,movetothenextcolumnhavinganonzeroentry,belowtheleveloftheleadingentryyouworkedwithandperformsimilaroperations.g)Afteryougotarow-echelonformforyourmatrix,performelementaryoperationstoputtheleadingentriesto1andtoforcetheentriesabovethemtozeros.TheGauss-SeideliterativemethodrepresentsanimprovementoftheJacobiiterationanditisalsocalledthemethodofsuccesivedisplacements.Briefly,thealgorithmconsistsinthefollowingsteps:•Verificationofthecoefficientmatrixvalues,themethodbeingusedonlyformatrixwithnonzerodiagonalentries•Rewriteeachequationsolvingforthecorrespondingunknown•Userewrittenequationstosolveforeachvalueofxi•Theiterationsarestoppedwhentheabsoluterelativeapproximateerrorislessthananearly-specifiedtoleranceforallunknowns.2.C#(Theoreticalaspects)Forourpurposewechoosedoneexternallibraryinordertohelpusdoingsomematrixoperations.TheCSML(CSharpMatrixLibrary)hasthetoolweneedtodooperationsliketheinverseofamatrix,calculatethedeterminantandsoon.Asweknowallprogramminglanguagesmusthaveacommonmathfunctionslibrary.C#hasitwithnoexception.YoucanaccessthemathematicalfunctionsinC#byimportingthenamespaceSystem.Mathatthebeginningofthesourcecode:usingSystem.Math;.Mostofthevariablesdefinedinthesourcearesingleprecisionfloating-pointtype(System.Single)andinteger-typevariables(System.Int32).Thescopewastorepresenttheresultsasaccurateaswecan.Wechoosetocreateasimpleconsoleapplicationforourmean.WeusedtheAcademicResourceKitttoolstosolvethesemethodsinC#.3.InsidethecodeAnotherinterestingmethodinwichtheuseofCSML(CsharpMatrixLibrary)isimperativeistheCramermethod.IthelpssolvinglinearAnale.SeriaInformatică.Vol.VIIfasc.1–2009Annals.ComputerScienceSeries.7thTome1stFasc.–200974systemsofequations.Beforestartingtoseehowthecodelooks,it’snecessarytoaddareferencetothislibrary,toimportitinyourproject.Youcandothisbyaddingthislinetothebeginningofyoursourcefile:usingCSML;.TheconstructoroftheMatrixclassintheCSMLlibraryisoverloadedandweoptfortheoneinwichwepass
本文标题:C#-外文文献
链接地址:https://www.777doc.com/doc-5607562 .html