1、Matlab实验报告终极版(此文档为word格式,下载后您可任意编辑修改!)实验一 Matlab的基本操作一、验证所有例题内容例11: Time = 11 12 1 2 3 4 5 6 7 8 9 10Time = 11 12 1 2 3 4 5 6 7 8 9 10 X_Data = 2.32 3.43;4.37 5.98X_Data = 2.3200 3.43004.3700 5.9800例1.2: g = 1 2 3 4;(85360)(1+(exp(1)2)z1 =0.0558 x=2 1+2*i;-0.45 5x = 2.0000 + 0.0000i 1.0000 + 2.0000i
2、 -0.4500 + 0.0000i 5.0000 + 0.0000i(2) z2=(log(x+sqrt(1+x2)2z2 = 0.7114 - 0.0253i 0.8968 + 0.3658i 0.2139 + 0.9343i 1.1541 - 0.0044i(3) a=-3:0.1:3a =Columns 1 through 9-3.0000 -2.9000 -2.8000 -2.7000 -2.6000 -2.5000 -2.4000 -2.3000 -2.2000Columns 10 through 18-2.1000 -2.0000 -1.9000 -1.8000 -1.7000
3、-1.6000 -1.5000 -1.4000 -1.3000Columns 19 through 27 -1.2000 -1.1000 -1.0000 -0.9000 -0.8000 -0.7000 -0.6000 -0.5000 -0.4000 Columns 28 through 36-0.3000 -0.2000 -0.1000 0 0.1000 0.2000 0.3000 0.4000 0.5000Columns 37 through 450.6000 0.7000 0.8000 0.9000 1.0000 1.1000 1.2000 1.3000 1.4000Columns 46
4、through 541.5000 1.6000 1.7000 1.8000 1.9000 2.0000 2.1000 2.2000 2.3000Columns 55 through 612.4000 2.5000 2.6000 2.7000 2.8000 2.9000 3.0000 m1=linspace(0.3,0.3,61)m1 =Columns 1 through 90.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000Columns 10 through 180.3000 0.3000 0.3000 0.3000 0
5、.3000 0.3000 0.3000 0.3000 0.3000Columns 19 through 270.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000Columns 28 through 360.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000Columns 37 through 450.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000Columns 46 through
6、 540.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000Columns 55 through 610.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 m2=linspace(-0.3,-0.3,61)m2 =Columns 1 through 9-0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000Columns 10 through 18 -0.3000 -0.3000 -0.3000
7、-0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000Columns 19 through 27-0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000Columns 28 through 36-0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000Columns 37 through 45-0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000
8、-0.3000 -0.3000 -0.3000Columns 46 through 54-0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000Columns 55 through 61-0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000 -0.3000 z2=(power(exp(1),m1.*a)-power(exp(1),m2.*a)2.*sin(a+m1)+log(a+m1)2)z2 =Columns 1 through 40.7388 + 3.1416i 0
9、.7696 + 3.1416i 0.7871 + 3.1416i 0.7913 + 3.1416iColumns 5 through 80.7822 + 3.1416i 0.7602 + 3.1416i 0.7254 + 3.1416i 0.6784 + 3.1416iColumns 9 through 120.6196 + 3.1416i 0.5496 + 3.1416i 0.4688 + 3.1416i 0.3780 + 3.1416iColumns 13 through 160.2775 + 3.1416i 0.1680 + 3.1416i 0.0497 + 3.1416i -0.077
10、1 + 3.1416iColumns 17 through 20-0.2124 + 3.1416i -0.3566 + 3.1416i -0.5104 + 3.1416i -0.6752 + 3.1416iColumns 21 through 24-0.8536 + 3.1416i -1.0497 + 3.1416i -1.2701 + 3.1416i -1.5271 + 3.1416iColumns 25 through 28-1.8436 + 3.1416i -2.2727 + 3.1416i -2.9837 + 3.1416i -37.0245 + 0.0000iColumns 29 t
11、hrough 32-3.0017 + 0.0000i -2.3085 + 0.0000i -1.8971 + 0.0000i -1.5978 + 0.0000iColumns 33 through 36-1.3575 + 0.0000i -1.1531 + 0.0000i -0.9723 + 0.0000i -0.8083 + 0.0000iColumns 37 through 40-0.6567 + 0.0000i -0.5151 + 0.0000i -0.3819 + 0.0000i -0.2561 + 0.0000iColumns 41 through 44-0.1374 + 0.000
12、0i -0.0255 + 0.0000i 0.0792 + 0.0000i 0.1766 + 0.0000iColumns 45 through 480.2663 + 0.0000i 0.3478 + 0.0000i 0.4206 + 0.0000i 0.4841 + 0.0000iColumns 49 through 520.5379 + 0.0000i 0.5815 + 0.0000i 0.6145 + 0.0000i 0.6366 + 0.0000iColumns 53 through 560.6474 + 0.0000i 0.6470 + 0.0000i 0.6351 + 0.0000
13、i 0.6119 + 0.0000iColumns 57 through 600.5777 + 0.0000i 0.5327 + 0.0000i 0.4774 + 0.0000i 0.4126 + 0.0000iColumn 610.3388 + 0.0000i6、已知:, 求下列表达式的值。(1),其中I为单位矩阵;(2)和(3)和(4)和(5)和答: A=12 34 -4;34 7 87;3 65 7;B=1 3 -1;2 0 3;3 -2 7; A+6*Bans = 18 52 -10 46 7 105 21 53 49 I=eye(3); A-B+Ians =12 31 -3 32 8
14、 84 0 67 1 A*Bans = 68 44 62 309 -72 596 154 -5 241 A.*Bans = 12 102 4 68 0 261 9 -130 49 A3ans = 37226 233824 48604 247370 149188 600766 78688 454142 118820 A.3ans = 1728 39304 -64 39304 343 658503 27 274625 343 ABans = 16.4000 -13.6000 7.6000 35.8000 -76.2000 50.2000 67.0000 -134.0000 68.0000 ABan
15、s = -0.0313 0.3029 -0.3324 0.0442 -0.0323 0.1063 0.0317 -0.1158 0.1558 A,Bans = 12 34 -4 1 3 -134 7 87 2 0 3 3 65 7 3 -2 7 A(1,3,:);B2ans = 12 34 -4 3 65 7 4 5 1 11 0 19 20 -5 40实验二 Matlab的数值计算和符号运算一、上机验证实验A、开启PC机,进入MATLAB语言B、帮助命令的使用,查找 sqrt函数的使用方法答: returns the square root of each element of the ar
16、ray X.B = sqrt(X) C、矩阵运算(1)已知A=1 2;3 4;B=5 5;7 8;求A2*B答:ans =105 115229 251(2)矩阵除法。已知A=1 2 3;4 5 6;7 8 9;B=1 0 0;0 2 0;0 0 3; 求AB,AB答:A=1 2 3;4 5 6;7 8 9;B=1 0 0;0 2 0;0 0 3;ABans = 1.0000 1.0000 1.0000 4.0000 2.5000 2.0000 7.0000 4.0000 3.0000AB警告: 矩阵接近奇异值,或者缩放错误。结果可能不准确。RCOND = 1.541976e-18。 ans =
17、1.0e+16 * -0.4504 1.8014 -1.3511 0.9007 -3.6029 2.7022 -0.4504 1.8014 -1.3511(3)矩阵的转置及共轭转置。已知A=15+i, 2-i ,1;6*i,4,9-i;求A.,A答: A=15+i, 2-i ,1;6*i,4,9-i; A.ans =15.0000 + 1.0000i 0.0000 + 6.0000i 2.0000 - 1.0000i 4.0000 + 0.0000i 1.0000 + 0.0000i 9.0000 - 1.0000i Aans =15.0000 - 1.0000i 0.0000 - 6.000
18、0i 2.0000 + 1.0000i 4.0000 + 0.0000i 1.0000 + 0.0000i 9.0000 + 1.0000i(4)使用冒号选出指定元素。已知A=1 2 3;4 5 6;7 8 9; 求A中第3列前2个元素;A中所有第2行的元素;答: A=1 2 3;4 5 6;7 8 9; A(1:2,3) ans = 3 6 A(2,1:3)ans = 4 5 6(5)方括号。用magic函数生成一个4阶魔术矩阵,删除该矩阵的第四列。答: A=magic(4)A = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 A( : ,4)=A =16 2
19、 3 5 11 10 9 7 6 4 14 15D、多项式(1)求多项式的根答: P=; roots(P)ans = 2.0000 + 0.0000i -1.0000 + 1.0000i -1.0000 - 1.0000i(2)已知A1.2 3 5 0.9;5 1.7 5 6;3 9 0 1;1 2 3 4, 求矩阵A的特征多项式;答: A=1.2 3 5 0.9;5 1.7 5 6;3 9 0 1;1 2 3 4; B=poly(A)B = 1.0000 -6.9000 -77.2600 -86.1300 604.5500(3)P(s)=1.0000s4-6.9000s3-77.2600s2
20、-86.1300s+604.5500求矩阵多项式中未知数为20时的值;答: C=polyval(B,20)C = 7.2778e+04(4)把矩阵A作为未知数代入到多项式中;答: D=polyval(B,A)D = 1.0e+03 * 0.3801 -0.4545 -1.9951 0.4601 -1.9951 0.2093 -1.9951 -2.8880 -0.4545 -4.8978 0.6045 0.4353 0.4353 0.0841 -0.4545 -1.16172.上机练习实验(1)利用 returns a column vector whose elements are the r
21、oots of the polynomial c. r = roots(c) P=; roots(P)ans = 0.5917 + 0.4864i 0.5917 - 0.4864i -0.2167 + 0.6158i -0.2167 - 0.6158i(2)令 A 是一个维度m x n的矩陣. 解释max(A) 和 min(max(A) 分別是什么意思?答:max(A):表示由A矩阵每一列最大值组成的一横向量;min(max(A):表示得到的横向量之中的最小值。 A=rand(3,4)A = 0.8147 0.9134 0.2785 0.9649 0.9058 0.6324 0.5469 0.
22、1576 0.1270 0.0975 0.9575 0.9706 max(A)ans = 0.9058 0.9134 0.9575 0.9706 min(max(A)ans = 0.9058(3)令 x 是一个维度 n 的向量. 解释find(x 0.8*max(x) 是什么意思?答:find(x 0.8*max(x)的意思是从向量中找出大于最大值0.8倍的所有数据得位置。 x=1;2;3;4;5;6; a=find(x 0.8*max(x) a = 5 6(4)令 x=2 3 5 6 和 y=-1:2 而 z = x.y ,解释z 的值是什么?答: x=2 3 5 6 ; y=-1:2y =
23、 -1 0 1 2 z = x.yz =0.5000 1.0000 5.0000 36.0000(5)试用解析解和数值解的方法求解微分方程x (t)= -2x(t)-3x(t)+exp(-5t)y(t)=2x(t)-3y(t)-4x(t)-4y(t)-sintx(0)=1,x(0)=2,y(0)=3,y(0)=4 解析解:x,y=dsolve(D2x=(-2)*x-3*Dx+exp(-5*t),D2y=2*x-3*y-4*Dx-4*Dy-sint,x(0)=1,Dx(0)=2,y(0)=3,Dy(0)=4)x = -(exp(-2*t)*(20*exp(t)*(3*exp(-4*t)4 - 5
24、14) - 20*exp(-3*t) + 200)60y = -(exp(-3*t)*(sint - (21*exp(-2*t)2 - sint*exp(3*t) + 3*exp(t)*(20*exp(-3*t)3 - 2003) + 6*exp(2*t)*(3*exp(-4*t)4 - 514) - 6*exp(2*t)*(sint2 + (exp(-4*t)*(12*t - 8*sint*exp(5*t) + 41)16 - 46516) + 6*t*exp(2*t)*(3*exp(-4*t)4 - 514) + 1712)6(6)计算y=sinx+sin2x+sin3x,在x=6处得值。
25、答: syms x; f=sin(x)+sin(2*x)+sin(3*x); subs(f,x,pi6)ans =3(12)2 + 32(7)用符号方法求积分答: syms x; f=1(1+(x4)+(x8); int(f,x) ans = -(3(12)*(atan(2*3(12)*x)(3*(2*x2)3 - 23) - atanh(2*3(12)*x)(3*(2*x2)3 + 23)6(8)用符号方法求下列极限: 答: syms x; f=(x*(power(exp(1),sin(x)+1)-2*(power(exp(1),tan(x)-1)(power(sin(x),3); limi
26、t(f,x,0)ans = -Inf(9)用3次多项式方法插值计算1-100之间整数的平方根。N149162536496481100平方根12345678910答:n=(1:10).2;f=sqrt(n);interp1(n,f,(1:100),cubic)ans =Columns 1 through 71.0000 1.3729 1.7125 2.0000 2.2405 2.4551 2.6494Columns 8 through 14 2.8292 3.0000 3.1636 3.3186 3.4661 3.6069 3.7422Columns 15 through 213.8729 4.
27、0000 4.1237 4.2435 4.3599 4.4730 4.5832Columns 22 through 284.6907 4.7958 4.8988 5.0000 5.0993 5.1966 5.2921Columns 29 through 355.3857 5.4777 5.5681 5.6570 5.7446 5.8309 5.9160Columns 36 through 426.0000 6.0829 6.1647 6.2454 6.3249 6.4035 6.4810Columns 43 through 496.5577 6.6334 6.7082 6.7823 6.855
28、6 6.9281 7.0000Columns 50 through 567.0712 7.1416 7.2113 7.2804 7.3487 7.4164 7.4835Columns 57 through 637.5500 7.6159 7.6812 7.7459 7.8102 7.8739 7.9372Columns 64 through 708.0000 8.0623 8.1242 8.1855 8.2464 8.3068 8.3668Columns 71 through 778.4263 8.4854 8.5441 8.6024 8.6603 8.7178 8.7749Columns 7
29、8 through 848.8317 8.8881 8.9442 9.0000 9.0555 9.1107 9.1655Columns 85 through 919.2201 9.2744 9.3284 9.3821 9.4354 9.4884 9.5412Columns 92 through 989.5935 9.6456 9.6973 9.7486 9.7996 9.8502 9.9005Columns 99 through 1009.9505 10.0000(10)有3个多项式,试进行下列操作: 求P(x)=P1(x)P2(x)。求的根。当x取矩阵A的每一元素时,求的值。其中:答: P1=1 2 4 0 5;P2=1 2 3; P=conv(P1,P2)P = 1 4 11 14 17 10 15 poly2sym(P)ans =x6 + 4*x5 + 11*x4 + 14*x3 + 17*x2 + 10*x + 15 roots(P)ans = -1.3156 + 1.6837i -1.3156 - 1.6837i -1.0000 + 1.4142i -1.0000 - 1.4142i 0.3156 + 0.9978i 0.3156 - 0.9978i A=-1,1.2,-1.4;0.75,2,3.5;0,5,2.5; polyva
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1