资源描述:
《实验二MATLAB基础知识(二).doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Experiment1.FundamentalKnowledgeofMatlab(II>【ExperimentalPurposes】1、熟悉并掌握MATLAB的工作环境。2、运行简单命令,实现数组及矩阵的输入输出,了解在MATLAB下如何绘图。【ExperimentalPrinciple】1.VectorsLet'sstartoffbycreatingsomethingsimple,likeavector.Entereachelementofthevector(separatedbyaspace>betweenbrackets,andsetitequaltoavariable.For
2、example,tocreatethevectora,enterintotheMATLABcommandwindow(youcan"copy"and"paste"fromyourbrowserintoMATLABtomakeiteasy>:b5E2RGbCAPa=[123456987]MATLABshouldreturn:a=123456987Togenerateaseriesthatdoesnotusethedefaultofincrementingby1,specifyanadditionalvaluewiththecolonoperator(first:step:last>.I
3、nbetweenthestartingandendingvalueisastepvaluethattellsMATLABhowmuchtoincrement(ordecrement,ifstepisnegative>betweeneachnumberitgenerates.Togenerateavectorwithelementsbetween0and20,incrementingby2(thismethodisfrequentlyusedtocreateatimevector>,usep1EanqFDPwt=0:2:20t=02468101214161820Manipulating
4、vectorsisalmostaseasyascreatingthem.First,supposeyouwouldliketoadd2toeachoftheelementsinvector'a'.Theequationforthatlookslike:DXDiTa9E3db=a+2b=34567811109Nowsuppose,youwouldliketoaddtwovectorstogether.Ifthetwovectorsarethesamelength,itiseasy.Simplyaddthetwoasshownbelow:RTCrpUDGiTc=a+bc=46810121
5、4201816Subtractionofvectorsofthesamelengthworksexactlythesameway.5PCzVD7HxAMATLABsometimesstoressuchalistinamatrixwithjustonerow,andothertimesinamatrixwithjustonecolumn.Inthefirstinstance,sucha1-rowmatrixiscalledarow-vector。inthe7/7secondinstance,sucha1-columnmatrixiscalledacolumn-vector.Either
6、way,thesearemerelydifferentwaysforstoringvectors,notdifferentkindsofvectors.jLBHrnAILg2.MatricesandArraysThemostbasicMATLABdatastructureisthematrix:atwo-dimensional,rectangularlyshapeddatastructurecapableofstoringmultipleelementsofdatainaneasilyaccessibleformat.Thesedataelementscanbenumbers,cha
7、racters,logicalstatesoftrueorfalse,orevenotherMATLABstructuretypes.MATLABusesthesetwo-dimensionalmatricestostoresinglenumbersandlinearseriesofnumbersaswell.Inthesecases,thedimensionsare1-by-1and1-by-nrespectively,wherenisthelength