欢迎来到天天文库
浏览记录
ID:36315694
大小:267.50 KB
页数:52页
时间:2019-05-09
《matlab简介3matlabm-file程式与多项式函数》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Whatisanm-file?Anm-fileisafilewithextension.mItcanbeusedtostorecommandsMatlabreadsandexecutesthecommandsinanm-fileifyoutypethenameofthefileinthecommandwindowUseanordinarytexteditorandsavethefileasfilename.mChoose’newfile’undertheFileMenuDifferentwaysofcreatingm-filesInthefirstcasethefun
2、ctioninv(A)isusedtofindtheinverse.Thisisthenmultipliedbyb.TheMatlabcodeforthisoperationisInthesecondcaseleft-divisionisperformedstraightawaywiththecommandX=9.25004.25002.7500X=9.25004.25002.7500ExampleExamplesolvetime.mA=rand(1000,1000);%Createsarandom%matrixAb=rand(1000,1);%Createsaran
3、dom%vectorbdet(A)%CalculatesthedeterminantofAtic,%Startsthetime-watchx=inv(A)*b;%Solvesthesystemtoc%Stopsthewatchtic,y=Ab;toc%Solvesandtimesthe%systemwithleftdivisionlapsed_time=1.2820elapsed_time=0.5310以下的tutex1.m档是一个简易绘图程式做为示范使用M-file%M-file,tutex1.m%SimpleplotforillustrationofusingM
4、-file.%简易绘图以做为示范使用M-filex=linspace(0,2*pi,20);y=sin(x);plot(x,y,'r+')xlabel('x-value')ylabel('y-value')title('2Dplot')WhenyouwritesomethinginMatlab’scommandwindow,thefollowingthingsarecheckedinturn:1.Istheresuchavariableintheworkspace?2.Isthereanm-filecalledthatthinginthecurrentdirector
5、y?3.Isthereanm-filecalledthatsomewhereelse?WhenMatlabsearchesforthem-fileitlooksinspecificfolders,itssearchpath.IfthefolderisnotaddedtothepathMatlabcannotrunyourscript.HowtomakesureMatlabfindsyourm-fileChangecurrentdirectoryusingthecdcommandorbyclickingintheDirectorypanelSelectthe’SetPa
6、th’optionintheFilemenuTypeoneofthefollowingcommandsinthecommandwindow:addpathC:ProgramMatlab6k5myfilespath(path,’C:ProgramMatlab6k5myfiles’)>>cdwufilemy_work%切换至目录wufilemy_work>>cd%如果只用cd则会显示目前的目录c:WUFILEMY_WORK>>dir%列出目录下的档案.tutex1.mtutex2.m..test.txt>>deletetest.txt%删除test
7、.txt>>path(path,'c:wufilemy_work')%将自己的目录wufilemy_work加在%MATLAB的搜寻路径之后>>path('c:wufilemy_work',path)%将自己的目录wufilemy_work加在%MATLAB的搜寻路径之前WhatisafunctionAfunctionisanm-filebeginningwiththeword’function’Afunctionhasauser-specifiedinputandoutputAfunctionhasitsown’local’work
此文档下载收益归作者所有