您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 经营企划 > MATLAB最早的发展理念是提供一套非常完善的矩阵运算指..
1IntroductiontoMATLABCheng-HsiungChiangDepartmentofComputerScienceHsuanChuangUniversity2OutlineThehistoryofMATLABThetoolboxesofMATLABHowtouseMATLABsoftware?ProgrammingusingMATLABBasiccommandsWriteafunctionofMATLABArraysandmatrixesOperationsofarraysandmatrixesMatlabfunctionsControlproceduresInputandoutputPlottingExamplesofMATLABprograms3TheHistoryofMATLABMATLAB(MatrixLaboratory)isdevelopedbyTheMathWorks,Inc.,1984.MATLAB最早的發展理念是提供一套非常完善的矩陣運算指令,但隨著數值運算需求的演變,matlab已成為系統模擬,數位訊號處理,科學目視的標準語言4MATLABistheleadingcomputationalsoftwareforProductdesignanddevelopmentResearchinindustryandacademiaTechnicaleducationOver400,000MATLABusersworldwideUsedinover100countries5HowpowerfultheMATLABcanbe?“Forthepurposesofanengineerorscientist,MATLABhasthemostfeaturesandisthebestdevelopedprograminitsclass.”-IEEESpectrum,SoftwareReview,February1997“IhavebeenamazedathowMATLABcanboostone’sproductivity.Anythingfromsimpleanalysistocomplexmodelingandsimulationcanbedoneinafractionofthetimeitwouldtaketowriteyourowncode.”GregoryE.Chamitoff,Ph.D.NASA,JohnsonSpaceCenter6TheToolboxesofMATLABCommunicationsToolboxControlSystemToolboxDataAcquisitionToolboxDatabaseToolboxDatafeedToolboxFilterDesignToolboxFinancialDerivativesToolboxFinancialDerivativesToolboxFinancialToolboxFuzzyLogicToolboxGARCHToolboxImageProcessingToolboxInstrumentControlToolboxModelPredictiveControlToolboxMappingToolboxMuAnalysisAndSynthesisToolboxNeuralNetworkToolboxOptimizationToolboxPartialDifferentialEquations(PDE)ToolboxRobustControlToolboxSignalProcessingToolboxSplineToolboxStatisticsToolboxSymbolicMathToolboxSystemIdentificationToolboxWaveletToolbox7HowtouseMATLAB?InstallMATLABExecuteMATLABTheMATLABwindowsDemosofMATLAB8ProgrammingUsingMATLABFiletypesofMATLAB.mfile.figfiles.matfilesBasicCommandsincommandwindowsavefilenameloadfilenamehelpcommandwhoclearclcexit/quit9MathematicalOperationsDeclaringavariableA=5;%the“;”isfornotdisplayB=6;MATLABMath&AssignmentOperatorsPower^or.^a^bora.^bMultiplication*or.*a*bora.*bDivision/or./a/bora./bor\or.\b\aorb.\aNOTE:56/88\56Addition+a+bSubtraction-a-b10WriteaFunctionofMATLABHowtoeditafunctionforMATLAB?AnexampleofaMATLABfunctionfunction[total]=sum(n)%Thisprogramistocalculatethesummationsum=0;fori=1:10,sum=sum+I;end;%endofforloopend;%endoffunctionHowtocallafunction?11ArraysandMatrixesArray:ex.1x6arrayA=[123456];orA=[1,2,3,4,5,6];Matrix:ex.2x3matrixB=[123;456;789];orB=[123456789];A(1)=?A(6)=?B(1,2)=?B(1,:)=?B(:,1)=?Examples:12OperationsofArraysandMatrixesThemathematicaloperationsofarrayandmatrix13MatlabFunctionsTheMATLABfunctions14Flowcontrol-selectionTheif-elseif-elseconstructioniflogicalexpressioncommandselseiflogicalexpressioncommandselsecommandsendifheight170disp(’tall’)elseifheight150disp(’small’)elsedisp(’average’)end15LogicalexpressionsRelationaloperators(comparearraysofsamesizes)==(equalto)~=(notequal)(lessthan)=(lessthanorequalto)(greaterthan)=(greaterthanorequalto)Logicaloperators(combinationsofrelationaloperators)&(and)|(or)~(not)Logicalfunctionsxorisemptyanyallif(x=0)&(x=10)disp(‘xisinrange[0,10]’)elsedisp(‘xisoutofrange’)end16Flowcontrol-repetitionRepeatsacodesegmentafixednumberoftimesforindex=vectorstatementsendThestatementsareexecutedrepeatedly.Ateachiteration,thevariableindexisassignedanewvaluefromvector.fork=1:12kfac=prod(1:k);disp([num2str(k),’‘,num2str(kfac)])end17Example–selectionandrepetitionfunctiony=fact(n)%FACT–Displayfactorialsofintegers1..nifnargin1error(’Noinputargumentassigned’)elseifn0error(’Inputmustbenon-negative’)elseifabs(n-round(n))epserror(’Inputmustbeaninteger’)endfork=1:nkfac=prod(1:k);disp([num2str(k),’’,num2str(kfac)])y(k)=kfac;end;18Repetition:AnimationdemoThefunctionmoviereplaysasequenceofcapturedframesConstructamovieofa360°touraroundtheMatlablogo%logomovie–makemovieof360degreelogotourlogo;no_frames=40;dtheta=360/no_frames;forframe=1:no_frames,camorbit(dtheta,0)M(frame)=getframe(gcf);end%nowdisplaycapturedmoviemovie(gcf,M);19Flowcontrol–conditionalrepetitionwhile-loopsstatementsareexecutedrepeatedlyaslongasthelogicalexpressionevaluatestotruewhilelogicalexpressionstatementsendk=1;whileprod(1:k)~=Inf,k=k+1;enddisp([‘LargestfactorialinMatlab:’,num2str(k-1)]);20InputandOutputX=input(‘enteryourname’,’s’)Y=input(‘enteryourage’,a)Disp(X)fprintf(fid,'%6.2f\n',y)21PlottingPolarplot:t=0:.01:2*pi;polar(t,abs(sin(2*t).*cos(2*t)));Lineplot:x=0:0.05:5;,y=sin(x.^2);,plot(x,y);Stemplot:x=0:0.1:4;,y=sin(x.^2).*exp(-x);stem(x,y)22Meshplot:z=peaks(25);,mesh(z);Surfaceplot:z=peaks(25);,surf(z);,colormap(jet);Contourplot:z=peaks(25);,contour(z,16);Quiverplot:23PlottingInstructions2Dplot12Dplot23Dplotmesh24AnyQuestions?ThankYouandHaveagoodtime!
本文标题:MATLAB最早的发展理念是提供一套非常完善的矩阵运算指..
链接地址:https://www.777doc.com/doc-514542 .html