MATLAB试验报告(8个试验)_第1页
MATLAB试验报告(8个试验)_第2页
MATLAB试验报告(8个试验)_第3页
MATLAB试验报告(8个试验)_第4页
MATLAB试验报告(8个试验)_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

本文格式为Word版,下载可任意编辑——MATLAB试验报告(8个试验)四川师范大学MATLAB语言试验报告1

系级班年月日试验名称:Intro,Expressions,Commands

姓名学号指导教师成绩1Objective

TheobjectiveofthislabistofamiliarizeyouwiththeMATLABprogramdevelopmentenvironmentandtodevelopyourfirstprogramsinthisenvironment.

2UsingMATLAB2.1StartingMATLAB

LogontoyourcomputerandstartMATLABbydouble-clickingontheicononthedesktoporbyusingtheStartProgramsmenu.MATLABDesktopwindowwillappearonthescreen.

Thedesktopconsistsofseveralsub-windows.Themostimportantonesare:

?CommandWindow(ontherightsideoftheDesktop)isusedtodocalculations,

entervariablesandrunbuilt-inandyourownfunctions.

?Workspace(ontheupperleftside)consistsofthesetofvariables(arrays)created

duringthecurrentMATLABsessionandstoredinmemory.

?CommandHistory(onthelowerleftside)logscommandsenteredinthe

CommandWindow.Youcanusethiswindowtoviewpreviouslyrunstatements,andcopyandexecuteselectedstatements.

YoucanswitchbetweentheLaunchPadwindowandtheWorkspacewindowusingthemenutabsunderthesub-windowontheupperleftside.Similarly,youcanswitchbetweentheCommandHistoryandCurrentDirectorywindowsusingthemenutabsunderthesub-windowonthelowerleftside.

2.2ExecutingCommands

YoucantypeMATLABcommandsatthecommandprompt“>>〞ontheCommandWindow.

Forexample,youcantypetheformulacos(π/6)2sin(3π/8)as>>(cos(pi/6)^2)*(sin(3*pi/8))

Trythiscommand.Afteryoufinishtyping,pressenter.ThecommandwillbeinterpretedandtheresultwillbedisplayedontheCommandWindow.

TrythefollowingbyobservinghowtheWorkspacewindowchanges:>>a=2;(Makenoteoftheusageof“;〞)>>b=3;

1

>>c=a^4?b?5+pi^3

Youcanseethevariablesa,bandcwiththeirtypesandsizesontheWorkspacewindow,andcanseethecommandsontheCommandHistorywindow.

Spendafewminutestopracticedefiningarrayvariables(i.e.vectorsandmatrices)using

thesquarebracket(“[]〞)andcolon(“:〞)operators,andzeros()andones()functions.

>>ar=[12345];>>br=[123;456];>>cr=[1:3:15];

?Setdrto?rst3elementsofar.

dr=ar(1:3);?Setertosecondrowofbr.

er=br(2,:);?Setarto[drer].Findthenumberofelementsofar.

ar=[drer];length(ar)

2.3GettingHelp

ThereareseveralwaystogethelponcommandsandfunctionsinMATLAB.FirstofallyoucanusetheHelpmenu.Youcanalsousethe“?〞button.Trytofindinformationontheplotfunctionfromthehelpindex.Alsotrytogetinformationonthesamefunctionusingthehelpcommand(i.e.typehelpplot).Finally,experimentwiththelookforcommand.Thiscommandlooksforothercommandsrelatedtoagivenkeyword.

2.4SomeUsefulCommands

Trythefollowingcommandsandobservetheirresults:Which:VersionandlocationinfoClear:Clearstheworkspace

Clc:Clearsthecommandwindow

who,whos:Listscontentoftheworkspace

3Exercises

PleasesolvethefollowingproblemsinMATLAB.Donotforgettokeepadiaryofyourcommandsandtheiroutputs.

(1)De?nethevariablesxyandzas7.6,5.5and8.1,respectively,andevaluate:

?2y?xz2???5.2x??4.785

(2)Computetheslopeofthelinethatpassesthroughthepoints(1,-2)and(5,8).(3)Quiz1.1:5

2

(4)1.6Exercises:1.1,1.4

(5)2.15Exercises:2.6,2.9,2.114QuittingMATLAB

Typingquitonthecommandwindowwillclosetheprogram.DonotforgettosendyourdiaryfileandM-filetoyourTA.

Donotforgettodeleteyour?lesfromtheharddiskofthePCyouusedinthelabattheendofthelabsession.

四川师范大学MATLAB语言试验报告2

系级班年月日

试验名称:Programming,RelationalandLogicalExpressions

姓名学号指导教师成绩1Objective

TheobjectiveofthislabistofamiliarizeyouwiththeMATLABscriptfiles(M-files),subarrays,relationalandlogicaloperators.

2ScriptFiles

ScriptfilesarecollectionsofMATLABstatementsthatarestoredinafile.InsteadoftypingcommandsdirectlyintheCommandWindow,aseriesofcommandsmaybeplacedintoafileandtheentirefilemaybeexecutedbytypingitsnameintheCommandWindow.SuchfilesarecalledscriptfilesthatarealsoknownasM-filesbecausetheyhaveanextensionof.m.Whenascriptfileisexecuted,theresultisthesameasitwouldbeifallofthecommandshadbeentypeddirectlyintotheCommandWindow.AllcommandsandscriptfilesexecutedintheCommandWindowshareacommonworkspace,sotheycanallsharevariablesintheworkspace.Notethatiftwoscriptfilesareexecutedsuccessively,thesecondscriptfilecanusethevariablescreatedbythefirstscriptfile.Inthisway,scriptfilescancommunicatewithotherscriptfilesthroughthedataleftbehindintheworkspace.AnEditWindowisusedtocreatenewM-filesortomodifyexistingones.TheEditWindowisaprogrammingtexteditor,withthefeaturesofMATLABlanguagehighlightedindifferentcolors.YoucancreateanewM-filewiththeFile/New/M-fileselectionandyoucanopenanexistingM-filewiththeFile/OpenselectionfromthedesktopmenuofMATLAB.

(1)Createanewworkingdirectoryunderthecurrentdirectoryandchangethecurrentdirectoryto?TA?ssuggest?.

3Subarrays

ItispossibletoselectandusesubsetsofMATLABarrays.Toselectasubsetofanarray,justincludealistoftheelementstobeselectedintheparenthesesafterthearrayname.MATLABhasaspecialfunctionnamedendthatisusedtocreatearray

3

subscripts.Theendfunctionalwaysreturnsthehighestvaluetakenonbyagivensubscript.Itisalsopossibletousesubarraysontheleft-handsideofanassignmentstatementtochangeonlysomeofthevaluesinanarray.Ifvaluesareassignedtoasubarray,onlythosevaluesarechangedbutifvaluesareassignedtoanarray,theentirecontentsofthearrayarereplacedbythenewvalues.(1)Definethefollowing5x5arrayarr1inMATLAB.

3?3?1??448?arr1??111532??16?1718??2154236124195745??10??51??20?22??

(2)WriteaMATLABstatementtoselectasubsetofarr1andreturnthesubarray

containingthevaluesasshown.

?365?arr11????547422?

arr11=arr1([1,5],[245]);

(3)WritetwoMATLABstatementstoselectthelastrowandlastcolumnofarr1,separately.

arr12=arr1(5,:);或arr12=arr1(end,:);arr13=arr1(:,end);或arr13=arr1(:,5);(4)WriteMATLABstatementstoobtainthefollowingarrayfromarr1.

?121??354???arr2???323???674????522??

arr2=arr1([15],:)';

4RelationalandLogicalOperators

Relationalandlogicaloperatorsarethetwotypesofoperatorsthatproducetrue/falseresultsinMATLABprograms.MATLABinterpretsazerovalueasfalseandanynonzerovalueastrue.Relationaloperators(==,=,>,>=,0;

(3)Writeanexpressionusingarr4andarelationaloperatortoproducethefollowingresult.

?1?0arr6???0??00100

001000010?0??0??0?

arr6=arr4==1;

(4)WriteaMATLABprogramwhichwillgeneratean(n-1)x(n-1)matrixfromagivennxnmatrixwhichwillbeequaltogivenmatrixwithfirstrowandfirstcolumndeleted.

arr44=rand(5);arr444=arr35(2:end,2:end);(5)Generalizeyourprogramabovesothattheprogramshouldasktherowandcolumnnumberstobedeletedandthengeneratenew(n-1)x(n-1)matrix.n=input('inputn:');matrixn=rand(n)

delrow=input('inputrownumberstobedeleted:');

delcolumn=input('inputcolumnnumberstobedeleted:');

matrixn_1=matrixn([1:delrow-1delrow+1:end],[1:delcolumn-1delcolumn+1:end])(6)Quiz3.1(P88)5QuittingMATLAB

Typingquitonthecommandwindowwillclosetheprogram.DonotforgettosendyourdiaryfileandM-filetoyourTA.

DonotforgettodeleteyourfilesfromtheharddiskofthePCyouusedinthelabat

5

>p=find_closest(1,0,'points.txt');>>disp(p);

4

>>p=find_closest(-1,4,'points.txt');>>disp(p);

2

wherethefilepoints.txtcontains:-12032-21121

5QuittingMATLAB

Typingquitonthecommandwindowwillclosetheprogram.DonotforgettosendyourdiaryfileandM-filetoyourTA.

DonotforgettodeleteyourfilesfromtheharddiskofthePCyouusedinthelabattheendofthelabsession.

四川师范大学MATLAB语言试验报告7

系级班年月日

试验名称:ConvolutionandFFTcomputation

姓名学号指导教师成绩1Objective

TheobjectiveofthislabistofamiliarizeyouconvolutionandfftcomputationwiththeMATLAB

2Convolutioncomputation

TheconvfunctionofMATLABcansupportconvolutionandpolynomialmutiplicationoperation.Writeaprogramthatcomputeconvolutionbetweeninputsignalandsystemimpulseresponse.Yourprogramshouldgivethefigureofinputsignal,system,outputsignal.Exampleofinputsignalandsystemimpulseresponseis:System:h(n)??(n)?2.5?(n?1)?2.5?(n?2)??(n?3)

13

Inputsignal:x(n)?2sin(?0nT),T?0.001,0?n?50

0?0?10?Hint:stemfunctionofMATLABisusefulforplottingfigureofdiscretesignaland

system.

3SpectrumanalysisusingFFT

Writeaspectrumanalysisprogramfortwokindsofsequence.ThefftfunctionofMATLABcanbeusedforspectrumanalysisofsignal.Spectrumfigureofgivensequencemustbeconsideredinprogram.Sequenceisgivenbelow:(1)gausssequence

??(n?p)q?,0?n?15x(n)??e??0,others

2(2)attenuatedsinesequence

?e??nsin2?fn,0?n?15x(n)???0,others

4QuittingMATLAB

Typingquitonthecommandwindowwillclosetheprogram.DonotforgettosendyourdiaryfileandM-filetoyourTA.

DonotforgettodeleteyourfilesfromtheharddiskofthePCyouusedinthelabattheendofthelabsession.

四川师范大学MATLAB语言试验报告8

系级班年月日

试验名称:digitalfilterdesign

姓名学号指导教师成绩1Objective

TheobjectiveofthislabistofamiliarizeyouwiththeMATLABdigitalfilterdesign.

2FIRfilterdesign

WriteaprogramthatcompleteFIRfilterdesignusingwindowmethod.Programmustreturnmagnitude-frequencyandphase-frequencyfigureoffilteryoudesigned.Designspecificationislistedbelow:

(1)designalinearphaseFIRfilterwhichapproachidealmagnitude-frequencycharacteristic:

14

?1,0???0.4?Hd(j?)???0,else,Itslengthis8.

(2)de

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论