中南大学matlab课后习题_第1页
中南大学matlab课后习题_第2页
中南大学matlab课后习题_第3页
中南大学matlab课后习题_第4页
中南大学matlab课后习题_第5页
已阅读5页,还剩92页未读 继续免费阅读

下载本文档

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

文档简介

1、第一章 实验内容1.2.例1-1 x=0:0.5:360*pi/180;plot(x,sin(x),x,cos(x);例1-2 p=3,7,9,0,-23; x=roots(p) x = -1.8857 -0.7604 + 1.7916i -0.7604 - 1.7916i 1.0732 例1-3 quad(x.*log(1+x),0,1)ans =0.2500例 1-4 a=2,-3,1;8,3,2;45,1,-9; b=4;2;17; x=inv(a)*bx = 0.4784 -0.87930.40543.(1)help inv inv Matrix inverse. inv(X) is

2、the inverse of the square matrix X. A warning message is printed if X is badly scaled ornearly singular(2)help plot plot Linear plot. plot(X,Y) plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. If X is a sca

3、lar and Y is a vector, disconnected line objects are created and plotted as discrete points vertically at X(3)help max max Largest component. For vectors, max(X) is the largest element in X. For matrices, max(X) is a row vector containing the maximum element from each column. For N-D arrays, max(X)

4、operates along the firstnon-singleton dimension.(4)help round round Round towards nearest integer.round(X) rounds the elements of X to the nearest integers.4.(1) x=0:pi/10:2*pi;y=sin(x)y = Columns 1 through 10 0 0.3090 0.5878 0.8090 0.9511 1.0000 0.9511 0.8090 0.5878 0.3090 Columns 11 through 20 0.0

5、000 -0.3090 -0.5878 -0.8090 -0.9511 -1.0000 -0.9511 -0.8090 -0.5878 -0.3090 Column 21 -0.0000(2)根据提示操作,选择y变量,并绘制y图形,生成了如下图形,图形是一个正弦函数图像。思考练习1.与其他窗口程序的启动与退出类似,双击图标打开,单击X图标关闭2. MATLAB是矩阵实验室(Matrix Laboratory)的简称用于算法开发、数据可视化、数据分析以及数值计算的高级技术计算语言和交互式环境。它将数值分析、矩阵计算、科学数据可视化以及非线性动态系统的建模和仿真等诸多强大功能集成在一个易于使用的视

6、窗环境中,为科学研究、工程设计以及必须进行有效数值计算的众多科学领域提供了一种全面的解决方案。3.如果一个命令行很长,需要分成多行输入,可以在第一个物理行之后加上三个小黑点并按下enter键,然后接着在下一个物理航继续输入命令的其他部分。三个小黑点称为续行符,即把下面的物理行看作该行的逻辑继续。4.help命令只搜索出那些与关键字完全匹配的结果,lookfor命令对搜索范围内的小文件进行关键字搜索,条件比较宽松。5.假如建立了一个变量fac,同时在当前目录下建立了一个M文件fac.m文件。如果在命令窗口输入fac,按照MATLAB的搜索顺序,应该在屏幕上显示fac的值。如果没有建立fac变量,

7、则执行fac.m文件。第二章 实验指导 1.(1)w=sqrt(2)*(1+0.34245*10-6)w = 1.4142(2)a=3.5; b=5; c=-9.8 x=(2*pi*a+(b+c)/(pi+a*b*c)-exp(2)/(tan(b+c)+a)x =0.9829(3) a=3.32; b=-7.9; y=2*pi*a2*(1-pi/4)*b-(0.8333-pi/4)*a)y = -128.4271(4) t=2,1-3*i;5,-0.65t = 2.0000 1.0000 - 3.0000i 5.0000 -0.6500 z=0.5*exp(2*t)*log(t+sqrt(1+

8、t2)z = 1.0e+04 * 0.0057 - 0.0007i 0.0049 - 0.0027i 1.9884 - 0.3696i 1.7706 - 1.0539i2.A=-1,5,-4;0,7,8;3,61,7;B=8,3,-1;2,5,3;-3,2,0;(1)A+6*Bans = 47 23 -10 12 37 26 -15 73 7A2-B+eyeans = -18 -216 18 23 533 11022 868 526(2) A*Bans = 14 14 16 -10 51 21 125 328 180 A.*Bans = -8 15 4 0 35 24 -9 122 0 B*A

9、ans = -11 0 -15 7 228 53 3 -1 28(3) A/Bans = 1.2234 -0.9255 2.9787 -0.9468 2.3511 -0.9574 4.6170 3.8723 13.8936 BAans = -0.5106 -8.6170 -1.1277 0.7340 17.5745 1.8085 -0.8830 -21.2128 0.4043(4) A,Bans = -1 5 -4 8 3 -1 0 7 8 2 5 3 3 61 7 -3 2 0 A(1,3,:);B2ans = -1 5 -4 3 61 7 73 37 1 17 37 13 -20 1 93

10、. A=23,10,-0.778,0;41,-45,65,5;32,5,0,32;6,-9,54,3.14 23.0000 10.0000 -0.7780 0 41.0000 -45.0000 65.0000 5.0000 32.0000 5.0000 0 32.00006.0000 -9.0000 54.0000 3.1400(1) k=find(10=A&A C=A(:,1:2)C = 23 10 41 -45 32 5 6 -9 D=A(2:4,3:4)D = 65.0000 5.0000 0 32.0000 54.0000 3.1400 E=B*CE = 1.0e+03 * 0.914

11、1 -0.2239 1.2080 2.71501.1330 -0.1930(3) E E&Dans = 1 1 0 1 1 1 E|Dans = 1 1 1 1 1 1Eans = 0 0 0 0 0 0 Dans = 0 0 1 0 0 04. H=hilb(5); P=pascal(5); Hh=det(H) Hh = 3.7493e-012 Hp=det(P) Hp = 1 Th=cond(H) Th = 4.7661e+005 Tp=cond(P) Tp = 8.5175e+003 条件数越趋近于1,矩阵的性能越好,所以帕斯卡矩阵性能更好。5. A=-29,6,18;20,5,12;-

12、8,8,5A= -2961820512-885V,D=eig(A)V= 0.71300.28030.2733 -0.6084-0.78670.87250.34870.55010.4050D= -25.316900 0-10.51820 0016.8351V为A的特征向量,D为A的特征值。它们之间满足A*V=V*D思考练习1. 在MATLAB中6+7i是一个复数常量,6+7*i则是一个表达式。i是虚数单位,而I是单 位向量。 2. A.*B表示A和B单个元素之间对应相乘,A*B是按矩阵乘法的规则乘。 A./B表示A矩阵除以B矩阵的对应元素,B.A等价于A./B。 A/B表示A *inv(B)而B

13、A表示inv(B)* A,对于矩阵运算一般两式不等。 3.(1) A(7)= (2) abs(x) (3) reshape(x,3,4) (4) k=find(t=0); t(k)=0(5) ones(size(A) (6) diag(A) B= diag(diag(A) 4. 3+randn(25,20) 5.(1) A=1,-1,2,-3;5,1,-4,2;3,0,5,2;11,15,0,9A = 1 -1 2 -3 5 1 -4 2 3 0 5 2 11 15 0 9 diag(A)ans = 1 1 5 9 triu(A)ans = 1 -1 2 -3 0 1 -4 2 0 0 5 2

14、 0 0 0 9 tril(A)ans = 1 0 0 0 5 1 0 0 3 0 5 0 11 15 0 9 inv(A)ans = 0.1308 0.1395 0.0593 -0.0006 0.0785 -0.1163 -0.1244 0.0797 0.0378 -0.0930 0.1105 0.0087 -0.2907 0.0233 0.1349 -0.0209 det(A)ans = -1.7200e+03 rank(A)ans = 4 norm(A,1)ans =20 norm(A,2)ans = 21.3196 norm(A,inf)ans = 35 cond(A,1)ans =

15、10.7558 cond(A)ans = 7.6905 cond(A,inf)ans = 16.4419 trace(A)ans =16(2) B=0.43,43,2;-8.9,4,21B = 0.4300 43.0000 2.0000 -8.9000 4.0000 21.0000 diag(B)ans = 0.4300 4.0000 triu(B)ans = 0.4300 43.0000 2.0000 0 4.0000 21.0000 tril(B)ans = 0.4300 0 0 -8.9000 4.0000 0 inv(B)Error using invMatrix must be sq

16、uare. det(B)Error using detMatrix must be square. rank(B)ans = 2 norm(B,1)ans = 47 norm(B,2)ans = 43.4271 norm(B,inf)ans = 45.4300 cond(B,1)Error using cond (line 35)A is rectangular. Use the 2 norm. cond(B,2)ans = 1.9354 cond(B,inf)Error using cond (line 35)A is rectangular. Use the 2 norm.lo9 trac

17、e(B)Error using trace (line 13)Matrix must be square.6. A=34,NaN,Inf,-Inf,-pi,eps,0; all(A)ans = 0 any(A)ans = 1 isnan(A)ans = 0 1 0 0 0 0 0 isinf(A)ans = 0 0 1 1 0 0 0 isfinite(A)ans = 1 0 0 0 1 1 17.结构矩阵,结构矩阵名.成员名=表达式,其中表达式应理解为矩阵表达式 建立单元矩阵和一般矩阵相似,只是矩阵元素用大括号括起来。8用稀疏存储方式可以可以节省内存空间; 运算规则上,稀疏矩阵与普通矩阵一样

18、,只是矩阵的存储方式不同。在运算过程中,稀疏存储矩阵可以直接参与运算。当参与运算的对象不全是稀疏存储矩阵时,所得结果一般是完全存储形式。第三章 实验指导1. n = input(n请输入一个任意三位数:);if n = 1000 | fix(n) = n error(输入不合要求,请输入三位整数。)enddig = (k)rem(fix(n/10k),10);n1 = arrayfun(dig,0:2);fprintf(反向结果是:%i%i%in,n1)请输入一个任意三位数:369反向结果是:9632.(1)用if 语句实现 x=input(输入一个百分制成绩);if x=90;disp(A)

19、; elseif x=80;disp(B); elseif x=70 disp(C); elseif x=60; disp(D); else disp (E)end输入一个百分制成绩89B用switch语句实现x=input(输入一个百分制成绩); switch fix(x/10)case 9,10 disp(A);case 8disp(B)case 7disp(C)case6disp (D)otherwisedisp(E)end输入一个百分制成绩56E3、a=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20b=max(a)c=min(a)b

20、=0c=0for i=1:20 if a(i)b b=a(i); end if a(i)5 n=5 a(n,:) disp(输入超出范围);else a(n,:)end 请输入一个数:5ans = 0.8913 0.4447 0.1763 0.8936 0.1389 0.1988请输入一个数:6n = 5ans = 0.4660 0.6721 0.8318 0.1897 0.1509 0.5936输入超出范围7、f1.m 代码如下function m=f1(n)m=n+10*log(n2+5);f2.m 代码如下:function m=f2(n)m=0;for i=1:nm=m+i*(i+1)

21、;end在command界面中输入:y1=f1(40)/(f1(30)+f1(20)y1 = 0.6390 y2=f2(40)/(f2(30)+f2(20)y2 =1.76628、函数文件factor1.m代码如下:function f=factor1(k)if k=1f=1;elsef=factor1(k-1)+k;end函数文件factor2.m代码如下:function f=factor2(k)if k=1f=1;elsef=factor2(k-1)2+k2;end函数文件factor3.m代码如下:function f=factor3(k)if k=1f=1;else f=factor

22、31/(k-1)+1/k;end 思考练习1、用MATLAB语言编写的程序称为M文件。书P57下部。2、N=1,2,3,4,5N = 1 2 3 4 5 A=N.*2A = 2 4 6 8 10 B=N./4B = 0.2500 0.5000 0.7500 1.0000 1.2500 C=1./NC = 1.0000 0.5000 0.3333 0.2500 0.2000 D=1./(N./2)./(N./2)/4D =1.0000 0.2500 0.1111 0.0625 0.04003、M文件B=0;for i=1:20A(i)=fix(99-10+1)*rand(1)+10);B=A(i

23、)+B;endB=B/20;for i=1:20if A(i) factor3输入一个数1000A = 0.9995 factor3输入一个数10000A =0.9999(2)M文件A=0;n=input(输入一个数);for i=1:1000A=1/(4)i)+A;endA输出结果:输入一个数10000A = 0.9999 factor3输入一个数100A = 0.3333 factor3输入一个数1000A = 0.3333 factor3输入一个数10000A =0.33335、M文件function m,n=chengji(A,B)m=A.*B;n=A*B;输出程序及结果: a=1 2

24、 3;4 5 6;7 8 9; b=-1 0 1;1 -1 0;0 1 1m,n=chengji(a,b);disp(a.*b=);disp(m);disp(a*b= );disp(n);b = -1 0 1 1 -1 0 0 1 1a.*b= -1 0 3 4 -5 0 0 8 9a*b= 1 1 4 1 1 10 1 1 16第四章 实验指导1.(1)t=-5:0.1:5y=t-t.3/6plot(t,y)(2)t=-10:0.1:10x=sin(t)/8y=cos(t)/sqrt(32)plot(x,y)2.t=-pi:pi/50:piy=(1+exp(-t).(-1)subplot(2

25、,2,1)bar(t,y,g)title(bar(t,y,b);axis(-4,4,0,1)subplot(2,2,2);stairs(t,y,b)title(stairs(t,y,b);axis(-4,4,0,1)subplot(2,2,3);stem(t,y,k)title(stem(t,y,k);axis(-4,4,0,1) subplot(2,2,4);loglog(t,y,m);title(loglog(t,y,m)3.(1)t=-pi:pi/50:pir=5*cos(t)+4polar(t,r,-*)(2)t=-pi/3:pi/50:pi/3r=5*sin(t).*sin(t).*

26、(cos(t).(-1)polar(t,r,-*)4.(1)t=0:pi/50:2*pix=exp(-t/20).*cos(t)y=exp(-t/20).*sin(t)z=tplot3(x,y,z)title(Line in 3-D Space)xlabel(X);ylabel(Y);zlabel(Z)grid on思考练习2.(1) t=-4:0.1:4y=exp(-0.5*(t).2)plot(t,y)(2)t=-2*pi:pi/50:2*pix=t.*sin(t)y=t.*cos(t)plot(x,y)3.x=-1:0.1:1y1=2*x-0.5plot(x,y1)hold onm=0:

27、pi/50:pit=sin(3*m).*cos(m)y2=sin(3*m).*sin(m)plot(t,y2)hold off4.(1)plot格式:x=-pi:pi/50:piy=sin(1/x)y=sin(x).(-1)plot(x,y)(2) fplot格式:fplot(x).(-1),-0.01,0.01,1e-4)(3) 比较,plot格式的曲线会比较直观看到曲线在某一范围的变化以及曲线走向,但是fplot格式的曲线则是非常简化的描述了曲线的主要部分5.(1)t=-4*pi:pi/50:4*pir=12*t.(-0.5)polar(t,r,-*)(2)t=-pi/6:pi/100:p

28、i/6r=3*a*sin(t).*cos(t).*(sin(t).3+(cos(t).3)polar(t,r,-*)6.(1)x,y=meshgrid(-8:0.1:8)z=4*(x.2+y.2)/13mesh(x,y,z)(2)x,y=meshgrid(-3:0.1:3)z=-5*(1+x.2+y.2).(-1)mesh(x,y,z)第五章 实验指导1.(1)A=randn(10,5)A = 0.0983 2.2294 0.0662 0.0000 1.1921 0.0414 0.3376 0.6524 -0.0549 -1.6118 -0.7342 1.0001 0.3271 0.9111 -0.0245 -0.0308 -1.6642 1.0826 0.5946 -1.9488 0.2323 -0.5900 1.0061 0.3502 1.0205 0.4264 -0.2781 -0.6509 1.2503 0.8617 -0.3728 0.4227 0.2571 0.9298 0.0012 -0.2365 -1.6702 -0.9444 0.2398 -0.0708 2.0237 0.4716 -1.3218 -0.6904 -2.4863 -2.2584 -1.2128 0.9248 -0.6516 0.5812 mean(A

温馨提示

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

评论

0/150

提交评论