当前位置:文档之家› 实验一 MATLAB基本操作及运算(含实验报告)

实验一 MATLAB基本操作及运算(含实验报告)

实验一 MATLAB 基本操作及运算一、 实验目的1、 理解Matlab 数据对象的特点;2、 掌握基本Matlab 运算规则;3、 掌握Matlab 帮助的使用方法;二、 实验的设备及条件计算机一台(带有MATLAB7.0以上的软件环境)。

三、 实验内容要求建立一个名为experiment01.m 的,把与实验内容1-7相关的实验命令都放入该文件中,题与题之间用相应注释分割。

注意对实验中出现的相关函数或变量,请使用help 或doc 查询相关帮助文档,学习函数的用法。

1、 建立以下标量:1) a=102) b=2.5×10233) c=2+3i ,(i 为虚数单位)4) d=3/2πj e ,(j 为虚数单位,这里要用到exp ,pi )2、 建立以下向量:1) aVec=[3.14 15 9 26]2) bVec=⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎣⎡18228871.2 3) cVec=[5 4.8 … -4.8 -5 ] (向量中的数值从5到-5,步长为-0.2)4) dVec=[100 100.01 … 100.99 101] (产生1到10之间的等对数间隔向量,参考logspace ,注意向量的长度)3、 建立以下矩阵:1)⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡=2222 aMat aMat 一个9×9的矩阵,其元素全为2;(参考ones 或zeros )2)⎥⎥⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎢⎢⎣⎡=1000005000001 bMat bMat 是一个9×9的矩阵,除主对角上的元素为[1 2 3 4 5 4 3 2 1]外,其余元素均为0。

(参考diag )。

3)10020109212291111=cMatcMat 为一个10×10的矩阵,可有1:100的向量来产生(参考reshape )4)⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡=NaN NaN NaN NaN NaN NaN NaN NaNNaN NaN NaN NaNdMatdMat 为3×4的NaN 矩阵,(参考nan )5)⎥⎦⎤⎢⎣⎡---=8710225113eMat 6)产生一个5×3随机整数矩阵fMat ,其值的范围在-3到3之间。

(参考rand 和floor 或ceil )4、 使用题1中的变量计算下列等式的x,y,z 的值:1) )6/)15((11--+=a e x 2) g g h h b a y /121,)(=+=提示π,参考sqrt 。

3) cc ad c d c R z ))3/sin()]))([(log(π-+=,其中R 表示取括号内复数的实数部分,c 表示c 的共轭复数,log 是自然对数。

(参考real ,conj ,log )5、 使用题2中的向量求解一下等式: 1))25.2/(2225.221cVec e xVec -=π,其中cVec 指的是题2 中定义的向量cVec ,一下雷同。

2)22)(bVec aVec yVec T +=,T aVec 表示aVec 的转置3))/1(log 10dVec zVec =,10log 表示已10为底的对数,参考log106、 使用题2和题3中所产生的向量和矩阵计算以下等式,注意本题的操作均采用矩阵间的运算。

1)2)(aMat bVec aVec xMat ⋅⋅=2)aVec bVec yMat ⋅=,注意这里与bVec aVec ⋅是不一样的3)TbMat aMat cMat zMat )(⋅=,这里cMat 为cMat 所对应行列式的值,参考det 。

7、 函数的使用和矩阵的访问。

1) 计算矩阵cMat 每一列的和,结果应为行向量形式。

(参考sum )2) 计算eMat 每一行的平均值,结果应为列向量形式。

(参考mean )3) 用向量[1 1 1] 替换eMat 的最上一行的值4) 将cMat 的第2~9行,第2到9列的元素所构成的矩阵赋值给cSub 。

5) 使用函数rand 产生一个1×5的向量r ,并将r 中值小于0.5的元素设置为0。

(参考find )四、实验报告要求(包含预习报告要求和最终报告要求)1.实验名称2.实验目的3.实验设备及条件4.实验内容及要求5.实验程序设计指程序代码。

6.实验结果及结果分析实验结果要求必须客观,有数据的可以记录数据,没有数据的简单描述实验现象。

结果分析是对实验结果的理论评判。

7.实验中出现的问题及解决方法8. 思考题的回答四、 实验报告的提交方式Word 文档,命名方式:实验号_你的学号_姓名;例如本次实验:实验一_000000001_张三.docE_mail: matlab_xx01@下一次课前提交,过期不收!五、 参考文献预习报告要求 最终报告要求参考教材和Matlab帮助文件。

1.实验名称MATLAB基本操作及运算2.实验目的(1)理解Matlab数据对象的特点;(2)掌握基本Matlab运算规则;(3)掌握Matlab帮助的使用方法;3.实验设备及条件计算机一台(带有MATLAB7.0以上的软件环境)4.实验内容及要求要求建立一个名为experiment01.m的,把与实验内容1-7相关的实验命令都放入该文件中,题与题之间用相应注释分割。

注意对实验中出现的相关函数或变量,请使用help或doc查询相关帮助文档,学习函数的用法。

5.实验程序设计clcformat compactformat long g%1.1A=10%1.2b=2.5*10^23%1.3c=2+3*id=exp((j*2*pi)/3)%2.1aVec=[3.14 15 9 26]%2.2bVec=[2.71 8 28 182]'%2.3cVec=[5:-0.2:-5]%2.4dVec=logspace(0,1,100)%3.1aMat=2*ones+zeros(9)%3.2bMat=diag([1,2,3,4,5,4,3,2,1])%3.3x=[1:1:100]cMat=reshape(x,10,10)%3.4dMat=zeros(3,4)+nan%3.5eMat=[13,-1,5;-22,10,-87]fMat=unifrnd(-2,5,4,3)%4.1x=1/(1+exp(-(A-15)/6))%4.2y=(sqrt(A)+b^(1/21))^pi%4.3z=(log(real((c+d)*(c-d))*sin(A*pi/3)))/(c*conj(c))%5.1xVec=exp(-cVec.^2/2.25^2)/sqrt(2*pi*2.5^2)%5.2yVec1=sqrt((aVec').^2/2+bVec.^2)%5.3zVec=log10(1./dVec)%6.1xMat=(aVec*bVec)*aMat.^2%6.2yMat=bVec*aVec%6.3zMat=det(cMat)*(aMat*bMat)'%7.1cMat_sum=sum(cMat,2)%7.2eMat_mean=mean(eMat,2)%7.3eMat_replace=eMat./[eMat(1,:);ones(1,3)]%7.4cSub=cMat(cMat(2:9,:))%7.5fina=rand(5,1)fina1=find(fina<0.5)fina(fina1)=06.实验结果及结果分析第一大题A =10b =2.5e+023c =2 + 3id =-0.5 + 0.866025403784439i_____________________________________________________________________ 第二大题aVec =Columns 1 through 23.14 15 Columns 3 through 49 26 bVec =2.71828182cVec =Columns 1 through 25 4.8 Columns 3 through 44.6 4.4 Columns 5 through 64.2 4 Columns 7 through 83.8 3.6 Columns 9 through 103.4 3.2 Columns 11 through 123 2.8 Columns 13 through 142.6 2.4 Columns 15 through 162.2 2 Columns 17 through 181.8 1.6 Columns 19 through 201.4 1.2Columns 21 through 221 0.8 Columns 23 through 240.6 0.399999999999999 Columns 25 through 260.199999999999999 0 Columns 27 through 28-0.199999999999999 -0.399999999999999 Columns 29 through 30-0.6 -0.8 Columns 31 through 32-1 -1.2 Columns 33 through 34-1.4 -1.6 Columns 35 through 36-1.8 -2 Columns 37 through 38-2.2 -2.4 Columns 39 through 40-2.6 -2.8 Columns 41 through 42-3 -3.2 Columns 43 through 44-3.4 -3.6 Columns 45 through 46-3.8 -4 Columns 47 through 48-4.2 -4.4 Columns 49 through 50-4.6 -4.8 Column 51-5dVec =Columns 1 through 21 1.02353102189903 Columns 3 through 41.04761575278966 1.07226722201032 Columns 5 through 61.09749876549306 1.12332403297803 Columns 7 through 81.14975699539774 1.176811952435 Columns 9 through 101.20450354025878 1.23284673944207 Columns 11 through 121.26185688306602 1.29154966501488 Columns 13 through 141.32194114846603 1.35304777457981 Columns 15 through 161.38488637139387 1.41747416292681 Columns 17 through 181.45082877849594 1.48496826225447 Columns 19 through 201.51991108295293 1.55567614393047 Columns 21 through 221.59228279334109 1.62975083462064 Columns 23 through 241.66810053720006 1.70735264747069 Columns 25 through 261.74752840000768 1.78864952905743 Columns 27 through 281.83073828029537 1.87381742286038 Columns 29 through 301.91791026167249 1.96304065004027 Columns 31 through 322.00923300256505 2.05651230834865 Columns 33 through 342.10490414451202 2.15443469003188 Columns 35 through 362.20513073990305 2.25701971963392 Columns 37 through 382.31012970008316 2.36448941264541 Columns 39 through 402.42012826479438 2.47707635599171 Columns 41 through 422.53536449397011 2.59502421139974 Columns 43 through 442.65608778294669 2.71858824273294 Columns 45 through 462.78255940220712 2.8480358684358 Columns 47 through 482.91505306282518 2.98364724028334 Columns 49 through 503.05385550883342 3.12571584968824 Columns 51 through 523.19926713779738 3.27454916287773 Columns 53 through 543.35160265093884 3.43046928631492 Columns 55 through 563.51119173421513 3.59381366380463 Columns 57 through 583.67837977182863 3.76493580679247 Columns 59 through 603.85352859371053 3.94420605943766Columns 61 through 624.03701725859655 4.13201240011534 Columns 63 through 644.2292428743895 4.32876128108306 Columns 65 through 664.43062145758388 4.53487850812858 Columns 67 through 684.64158883361278 4.7508101621028 Columns 69 through 704.86260158006535 4.97702356433211 Columns 71 through 725.09413801481638 5.21400828799968 Columns 73 through 745.33669923120631 5.46227721768434 Columns 75 through 765.59081018251222 5.72236765935022 Columns 77 through 785.85702081805667 5.99484250318941 Columns 79 through 806.13590727341317 6.28029144183425 Columns 81 through 826.42807311728432 6.57933224657568 Columns 83 through 846.73415065775082 6.8926121043497 Columns 85 through 867.05480231071864 7.22080901838546 Columns 87 through 887.39072203352578 7.56463327554629 Columns 89 through 907.74263682681127 7.92482898353917 Columns 91 through 928.11130830789687 8.30217568131975Columns 93 through 948.49753435908644 8.69749002617784Columns 95 through 968.90215085445039 9.11162756115489Columns 97 through 989.3260334688322 9.54548456661834Columns 99 through 1009.77009957299225 10_____________________________________________________________________ 第三大题aMat =2 2 2 2 2 2 2 2 22 2 2 2 2 2 2 2 22 2 2 2 2 2 2 2 22 2 2 2 2 2 2 2 22 2 2 2 2 2 2 2 22 2 2 2 2 2 2 2 22 2 2 2 2 2 2 2 22 2 2 2 2 2 2 2 22 2 2 2 2 2 2 2 2bMat =1 0 0 0 0 0 0 0 00 2 0 0 0 0 0 0 00 0 3 0 0 0 0 0 00 0 0 4 0 0 0 0 00 0 0 0 5 0 0 0 00 0 0 0 0 4 0 0 00 0 0 0 0 0 3 0 00 0 0 0 0 0 0 2 0x =Columns 1 through 91 2 3 4 5 6 7 8 9 Columns 10 through 1810 11 12 13 14 15 16 17 18 Columns 19 through 2719 20 21 22 23 24 25 26 27 Columns 28 through 3628 29 30 31 32 33 34 35 36 Columns 37 through 4537 38 39 40 41 42 43 44 45 Columns 46 through 5446 47 48 49 50 51 52 53 54 Columns 55 through 6355 56 57 58 59 60 61 62 63 Columns 64 through 7264 65 66 67 68 69 70 71 72 Columns 73 through 8173 74 75 76 77 78 79 80 81 Columns 82 through 9082 83 84 85 86 87 88 89 90 Columns 91 through 9991 92 93 94 95 96 97 98 99 Column 100100cMat =Columns 1 through 91 11 21 31 41 51 61 71 812 12 22 32 42 52 62 72 823 13 23 33 43 53 63 73 835 15 25 35 45 55 65 75 856 16 26 36 46 56 66 76 867 17 27 37 47 57 67 77 878 18 28 38 48 58 68 78 889 19 29 39 49 59 69 79 8910 20 30 40 50 60 70 80 90 Column 10919293949596979899100dMat =NaN NaN NaN NaNNaN NaN NaN NaNNaN NaN NaN NaNeMat =13 -1 5-22 10 -87fMat =Columns 1 through 24.65090499603023 4.23909276304231 -0.382030404979985 3.33467783119176 2.24789808479251 1.19527365617839 1.4018772809651 -1.87047449726243Column 33.749850150066771.112923550472362.308026436700663.54355926198925_____________________________________________________________________ 第四大题x =0.302940716034593y =6269.60314420271z =0.104633566196183_____________________________________________________________________ 第五大题xVec =Columns 1 through 20.0011436837460341 0.00168440923977891Columns 3 through 40.00244189145989572 0.00348451366324844Columns 5 through 60.004894350444668 0.00676682628990691Columns 7 through 80.00920899141861331 0.0123360517753163Columns 9 through 100.0162658728660145 0.0211113321391906Columns 11 through 120.026970622986521 0.033915903649967Columns 13 through 140.0419810099474893 0.0511492707968797Columns 15 through 160.061342728003881 0.0724142104534477 Columns 17 through 180.0841436968344532 0.096240185732909 Columns 19 through 200.10834986912344 0.120070800079053 Columns 21 through 220.130973517949181 0.14062633423639 Columns 23 through 240.148623297923735 0.154612359137343 Columns 25 through 260.158321025606789 0.159576912160573 Columns 27 through 280.158321025606789 0.154612359137343 Columns 29 through 300.148623297923735 0.14062633423639 Columns 31 through 320.130973517949181 0.120070800079053 Columns 33 through 340.10834986912344 0.096240185732909 Columns 35 through 360.0841436968344532 0.0724142104534477 Columns 37 through 380.061342728003881 0.0511492707968797 Columns 39 through 400.0419810099474893 0.033915903649967 Columns 41 through 420.026970622986521 0.0211113321391906 Columns 43 through 440.0162658728660145 0.0123360517753163 Columns 45 through 460.00920899141861331 0.00676682628990691 Columns 47 through 480.004894350444668 0.00348451366324844 Columns 49 through 500.00244189145989572 0.00168440923977891 Column 510.0011436837460341yVec1 =3.5034126220015813.285330255586428.7141080307225182.926214633114zVec =Columns 1 through 20 -0.0101010101010101 Columns 3 through 4-0.0202020202020202 -0.0303030303030304 Columns 5 through 6-0.0404040404040404 -0.0505050505050505 Columns 7 through 8-0.0606060606060606 -0.0707070707070707 Columns 9 through 10-0.0808080808080809 -0.0909090909090909 Columns 11 through 12-0.101010101010101 -0.111111********* Columns 13 through 14-0.121212********* -0.131313131313131 Columns 15 through 16-0.141414141414141 -0.151515151515152 Columns 17 through 18-0.161616161616162 -0.171717171717172Columns 19 through 20-0.181818181818182 -0.191919191919192 Columns 21 through 22-0.202020202020202 -0.212121212121212 Columns 23 through 24-0.222222222222222 -0.232323232323232 Columns 25 through 26-0.242424242424242 -0.252525252525253 Columns 27 through 28-0.262626262626263 -0.272727272727273 Columns 29 through 30-0.282828282828283 -0.292929292929293 Columns 31 through 32-0.303030303030303 -0.313131313131313 Columns 33 through 34-0.323232323232323 -0.333333333333333 Columns 35 through 36-0.343434343434343 -0.353535353535354 Columns 37 through 38-0.363636363636364 -0.373737373737374 Columns 39 through 40-0.383838383838384 -0.393939393939394 Columns 41 through 42-0.404040404040404 -0.414141414141414 Columns 43 through 44-0.424242424242424 -0.434343434343434 Columns 45 through 46-0.444444444444444 -0.454545454545455 Columns 47 through 48-0.464646464646465 -0.474747474747475 Columns 49 through 50-0.484848484848485 -0.494949494949495 Columns 51 through 52-0.505050505050505 -0.515151515151515 Columns 53 through 54-0.525252525252525 -0.535353535353535 Columns 55 through 56-0.545454545454545 -0.555555555555556 Columns 57 through 58-0.565656565656566 -0.575757575757576 Columns 59 through 60-0.585858585858586 -0.595959595959596 Columns 61 through 62-0.606060606060606 -0.616161616161616 Columns 63 through 64-0.626262626262626 -0.636363636363636 Columns 65 through 66-0.646464646464647 -0.656565656565657 Columns 67 through 68-0.666666666666667 -0.676767676767677 Columns 69 through 70-0.686868686868687 -0.696969696969697 Columns 71 through 72-0.707070707070707 -0.717171717171717 Columns 73 through 74-0.727272727272727 -0.737373737373737 Columns 75 through 76-0.747474747474747 -0.757575757575758 Columns 77 through 78-0.767676767676768 -0.777777777777778 Columns 79 through 80-0.787878787878788 -0.797979797979798-0.808080808080808 -0.818181818181818 Columns 83 through 84-0.828282828282828 -0.838383838383838 Columns 85 through 86-0.848484848484848 -0.858585858585859 Columns 87 through 88-0.868686868686869 -0.878787878787879 Columns 89 through 90-0.888888888888889 -0.898989898989899 Columns 91 through 92-0.909090909090909 -0.919191919191919 Columns 93 through 94-0.929292929292929 -0.939393939393939 Columns 95 through 96-0.94949494949495 -0.95959595959596 Columns 97 through 98-0.96969696969697 -0.97979797979798 Columns 99 through 100-0.98989898989899 -1 xMat =Columns 1 through 220450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.037620450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 Columns 5 through 620450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 Columns 7 through 820450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 20450.0376 Column 920450.037620450.037620450.037620450.037620450.037620450.037620450.037620450.037620450.0376yMat =Columns 1 through 28.5094 40.65 25.12 120 87.92 420 571.48 2730 Columns 3 through 424.39 70.46 72 208 252 728 1638 4732 zMat =0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 cMat_sum =470480490500510520530540550eMat_mean =5.66666666666667-33eMat_replace =1 1 1-22 10 -87cSub =Columns 1 through 92 12 22 32 42 52 62 72 823 13 23 33 43 53 63 73 834 14 24 34 44 54 64 74 845 15 25 35 45 55 65 75 856 16 26 36 46 56 66 76 867 17 27 37 47 57 67 77 878 18 28 38 48 58 68 78 889 19 29 39 49 59 69 79 89 Column 1092939495979899fina =0.9218129707448030.7382072458106650.1762661444946180.4057062130620950.935469699107605fina1 =34fina =0.9218129707448030.7382072458106650.9354696991076057.实验中出现的问题及解决方法问题:题3.6中,仅依靠提示所给的参考函数rand、floor或ceil,很难解决问题。

相关主题