MATLAB仿真及实验_第1页
MATLAB仿真及实验_第2页
MATLAB仿真及实验_第3页
MATLAB仿真及实验_第4页
MATLAB仿真及实验_第5页
已阅读5页,还剩34页未读 继续免费阅读

下载本文档

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

文档简介

1、习题一1、试个MATLAB的工作空间中建立以下2个矩阵:A=1 2L3 4J,求出矩阵A和B的乘积,并将结果赋给变量C。 A=1 2A = TOC o 1-5 h z 12 B=1 23 4B =1234 C=A*BC =7102、利用MATLAB提供的帮助信息,了解inv命令的调用格式,并作简要说明。help invINV Matrix inverse.INV(X) is the inverse of the square matrix X.A warning message is printed if X is badly scaled or nearly singular.See als

2、o SLASH, PINV, COND, CONDEST, LSQNONNEG LSCOV.Overloaded methodshelp gf/inv.mhelp zpk/inv.mhelp tf/inv.mhelp ss/inv.mhelp lti/inv.mhelp frd/inv.mhelp sym/inv.mhelp idmodel/inv.m3、使用help命令查询函数plot的功能以及调用方法,然后利用plot命令绘制函数y=sin(x)的图形,其中。一* 一。help plotPLOT Linear plot.PLOT(X,Y) plots vector Y versus vec

3、tor 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 scalar and Y is a vector, length(Y) disconnected points are plotted.PLOT(Y) plots the columns of Y versus their index.If Y is complex, PLOT(Y) is equivalent to PLOT(real(Y)

4、,imag(Y). In all other uses of PLOT, the imaginary part is ignored.Various line types, plot symbols and colors may be obtained with PLOT(X,Y,S) where S is a character string made from one element from any or all the following 3 columns:bblue.point-solidggreenocircle:dottedrredxx-mark-. dashdotccyan+

5、plus- dashedmmagenta*staryyellowssquarekblackddiamondvtriangle (down)Atriangle (up)triangle (right)ppentagramhhexagramFor example, PLOT(X,Y,c+:) plots a cyan dotted line with a plus at each data point; PLOT(X,Y,bd) plots blue diamond at each data point but does not draw any line.PLOT(X1,Y1,S1,X2,Y2,

6、S2,X3,Y3,S3,.) combines the plots defined by the (X,Y,S) triples, where the Xs and Ys are vectors or matrices and the Ss are strings.For example, PLOT(X,Y,y-,X,Y,go) plots the data twice, with a solid yellow line interpolating green circles at the data points.The PLOT command, if no color is specifi

7、ed, makes automatic use of the colors specified by the axes ColorOrder property. The default ColorOrder is listed in the table above for color systems where the default is blue for one line, and for multiple lines, to cycle through the first six colors in the table. For monochrome systems,PLOT cycle

8、s over the axes LineStyleOrder property.PLOT returns a column vector of handles to LINE objects, one handle per line.The X,Y pairs, or X,Y,S triples, can be followed by parameter/value pairs to specify additional properties of the lines.See also SEMILOGX, SEMILOGY, LOGLOG, PLOTYY, GRID, CLF, CLC, TI

9、TLE,XLABEL, YLABEL, AXIS, AXES, HOLD, COLORDEF, LEGEND, SUBPLOT, STEM.Overloaded methodshelp cfit/plot.mhelp fints/plot.mhelp cgrules/Plot.mhelp xregtwostage/plot.mhelp xregtransient/plot.mhelp xregmodel/plot.mhelp localmod/plot.mhelp sweepset/plot.mhelp mdevtestplan/plot.mhelp cgdatasetnode/plot.mh

10、elp cgdatadisplay/plot.mhelp idmodel/plot.mhelp iddata/plot.mhelp ntree/plot.mhelp dtree/plot.mhelp wvtree/plot.mhelp rwvtree/plot.mhelp edwttree/plot.m a=0:0.01:pi; y=sin(a); plot(y) TOC o 1-5 h z 0.9 -/-0.8 -/-07 /0.6 -/-0.5 -0.4 -0501001502002503003504、试用不同的方法建立数组A=1 1.5 2.0 2.5 3.0,了解怎样访问数组A的第二个

11、元素,然后将其更换为4.0。A=1 1.5 2.0 2.5 3.0A =1.00001.50002.00002.50003.0000 A(2) ans =1.5000 A(2)=4.0A =1.00004.00001 25、 已知矩阵B = 0 76 3的元素全改为0。2.00002.50003.000052,试用MATLAB提供的关系运算命令将B中所有大于21 B=1 2 50 7 23 1B = TOC o 1-5 h z 25072631 B(find(B2)ans =6735 B(find(B2)=0B = TOC o 1-5 h z 1200026、0012154987 flipud

12、(A)ans =8956123 size(A) ans =3324,试求其转置、逆、迹、特征值、特征向量和B对应的1B =7、已知矩阵L3行列式的值。B=1 23 4B = TOC o 1-5 h z 1234 Bans =34 inv(B) ans =-2.00001.00001.5000-0.5000eig(B)ans =-0.37235.3723 det(B)ans =-28、分别建立一个3* 3阶的单位阵、随机阵和魔方阵。eye(3)ans = TOC o 1-5 h z 100010001 rand(3)ans =0.95010.48600.45650.23110.89130.018

13、50.60680.76210.8214 magic(3)ans = TOC o 1-5 h z 165792c.a (x) = x2 + 2x - 2 b( x) = x3 + x 2 - 3 x +1 皿+祐人夕访普9、已知多项式,。试求两个多项式的和与乘积。syms x a=xA2+2*x-2xA2+2*x-2 b=xA3+xA2-3*x+1b =xA3+xA2-3*x+1 a+b ans =2*xA2-x-1+xA3 a*b ans = (xA2+2*x-2)*(xA3+xA2-3*x+1)表达,及计算n, 10、复数 = 3 + 4,七=1 + 2 Z3 = & z1=3+4*i z1

14、 =3.0000 + 4.0000i z2=1+2iz2 =1.0000 + 2.0000i z3=2*exp(pi/6*i) z3 =1.7321 + 1.0000i0.3349 + 5.5801i11、产生1X5的均布随机数组,进行如下操作:1)寻访数组的第三个元素;2)寻访 数组的第一、二、五个元素组成的子数组;3)寻访前三个元素组成的子数组;4)寻访除前2个元素外的全部其他元素。A=rand(1,5)A =0.44470.61540.79190.92180.7382 A(3) ans =0.7919 A(1 2 5) ans =0.44470.61540.7382 A(1:3) ans

15、 =0.44470.61540.7919 A(2:end) ans =0.61540.79190.92180.738212、试用两种方法用MATLAB计算七81) syms x x=solve(x3=-8,x)x =-21-i*3(1/2)1+i*3(1/2)2) x=-8(1/3)x =-2(s 2 + 2)(s + 4)(s +1)13、求 s 3 + s +1的“商”及“余”多项式。p1=conv(1,0,2,conv(1,4,1,1); p2=1 0 1 1; q,r=deconv(p1,p2)q =15 r =0054314、求方程x4+7x”3 +9x-20=0的全部根。p=1 7

16、 0 9 -20; roots(p)ans =-7.2254-0.4286 + 1.5405i-0.4286 - 1.5405i1.082615、今有多项式P1(x)=x4-2x+1,P2(x)=x2+4x-0.5,要求先求得P(x)=P1(x)+P2(x), 然后计算xi=0.2* 1各点上的P(xi)(i=0,1,2, -,5)值。p1=1.0 0.0 0.0 -2.0 1.0; p2=0.0 0.0 1.0 4.0 -0.5; p1x=poly2sym(p1);p2x=poly2sym(p2); p=p1x+p2xp =x4+2*x+1/2+x2 x=0:5; x.”4+2*x+1/2+

17、x.”2ans =0.50004.500024.500096.5000 280.5000 660.500016、已知一线性方程组如下所示:3x + x - x = 3.6x + 2 x + 4 x = 2.1x + 4 x + 5 x 1.4 甘 小 田123 ,试求其结果。 a=3.0 1.0 -1.0;1.0 2.0 4.0;-1.0 4.0 5.0a =31-1124-145 b=3.6;2.1;-1.4 b =3.60002.1000-1.4000 x=abx =1.4818-0.46060.384817、已知矩阵A =914358-891435-5-8-9143-3-5-8914-4

18、-3-5-891-1-4-3-5-89求(1)此矩阵的秩;(2)此矩阵的行列式的值;(3)此矩阵的迹;(4)此矩阵的特 征多项式的系数及多项式的根;(6)此矩阵的逆阵;(7)此矩阵的特征值与特 征向量A=9 1 4 3 5 8-8 9 1 4 3 5-5 -8 -9 1 4 3-3 -5 -8 9 1 4-4 -3 -5 -8 9 1-1 -4 -3 -5 -8 9A =914358-891435-5-8-9143-3-5-8914-4-3-5-891-1-4-3-5-89 rank(A) ans =6 det(A) ans =595024 trace(A) ans =36 poly(A)1.

19、0e+005 *Columns 1 through 60.0000-0.00040.0060-0.0760Column 75.9502 B=poly(A)B =1.0e+005 *Columns 1 through 60.0000-0.00040.0060-0.0760Column 75.95020.7135-3.55990.7135-3.5599 roots(B) ans =-0.1622 +12.0911i-0.1622 -12.0911i14.53799.3652 + 1.9707i9.3652 - 1.9707i3.0561(6) inv(A) ans =0.0038-0.0939-0

20、.35100.25920.18330.0302-0.0571-0.0215-0.48830.33880.25920.04610.08640.09560.5906-0.4883-0.3510-0.07080.01890.02160.0956-0.0215-0.0939-0.04070.04170.01890.0864-0.05710.0038-0.05150.05150.04070.0708-0.0461-0.03020.0430(7) v d=eig(A)v =Columns 1 through 40.0200 + 0.1849i-0.80840.3485 - 0.0625i0.0639 -

21、0.1206i0.2438 + 0.1483i-0.2942 - 0.0029i0.2562 + 0.3857i0.2562 - 0.3857i -0.46910.0680 + 0.4650i0.0680 - 0.4650i0.2202-0.4968-0.49680.0284-0.2618 + 0.0993i -0.2618 - 0.0993i -0.3118-0.3238 - 0.0038i -0.3238 + 0.0038i0.5385-0.3360 - 0.1475i -0.3360 + 0.1475i -0.5861Columns 5 through 60.0200 - 0.1849i

22、0.3706-0.80840.67620.3485 + 0.0625i -0.62520.0639 + 0.1206i -0.09480.2438 - 0.1483i -0.0679-0.2942 + 0.0029i0.0307 d =Columns 1 through 4-0.1622 +12.0911i000-0.1622 -12.0911i00014.53790001.9707i000000Columns 5 through 6000000009.3652 - 1.9707i003.05610009.3652 +00习题二1、编制一个函数,使得该函数能对输入的两个数值进行比较,并返回其中

23、的最 小值。function m=min(a,b)if(a min(2,1)ans =12、试编一个m程序,将一维数组x中的N个数按颠倒的次序重新存储。如N=5,原来x为:x= 13579 而经过颠倒处理后x中数据的次序应该为:x= 97531 function b=fun1(x)N=length(x)for i=1:Nb(i)=x(N-i+1);endfun1(1 3 5 7 9)N =5 ans =975313、编制一个m程序,计算阶乘n! = 1X2X3X Xn function m=fun2(n)m=1;for i=1:nm=m*i;endfun2(3)4、利用循环语句进行程序设计:假

24、设定义mxn的矩阵A。判断矩阵A的第1列元 素是否为0,若全为0,则从矩阵A中删除第1列function b=fun3(A)m,n=size(A)for i=1:mif A(i,1)=0YC=0;continue;elseYC=1;break;endendif YC=0 A(:,1)=;b=A;else b=A;end5、利用循环语句进行程序设计:在区间 2,0.75内,步长为0.25,对函数 y=f(x)=1+1/x求值,并列表。将所得x值和y值分别存入向量r和s中。for r=-2:0.25:-0.75x=ry=1+1/x;s=yendk = 2i6、编程计算i=0k=0;for i=0:

25、63k=k+2Ai;endk =1.8447e+019习题三1、用subplot命令在同一图形输出窗口中绘制以下4个函数的图形:y = x,工 e 0,3 y = x sin 兀 x g 1,1 = x 2, % E 0,1.5y = tan x, x g 0,1.3x=-3:0.01:3;y1=x;y2=x.*sin(x);y3=x.”2;y4=tan(x);subplot(2,2,1),plot(x,y1);axis(0,3,-1,3)subplot(2,2,2),plot(x,y2);axis(-1,1,-pi,pi)subplot(2,2,3),plot(x,y3);axis(0,1.

26、5,-1,3)subplot(2,2,4),plot(x,y4);axis(0,1.3,-1,3)2、绘制曲线=02x Sin x在x G0,5”区间上的阶梯图。x=0:0.1:5*pi;y=exp(-0.2*x).*sin(x);stairs(y);cos 邕 +1I 4 J 3,其中的范围为08”。3、试绘制以极坐标形式表示的图形: x=0:0.01*pi:8*pi;y=cos(5/4*x)+1/3;polar(x,y);901.5270t_的取值范围是4、画出衰减振荡曲线=3 sin3t及其它的包络线 =厂30,4兀Ox=0:0.01*pi:4*pi;y=exp(-x/3).*sin(3

27、*x);y0=exp(-x/3);plot(y);hold onplot(y0);hold off; TOC o 1-5 h z :k:-0.4 - I-.D gWiiiIIII 050100150200250300350400450sin(: x2 + y 2)Z =.5、画出 注+ y2所表示的三维曲面。乙y的取值范围是-8,8。 x=-8:0.5:8;y=x;X,Y=meshgrid(x,y);Z=sin(X.2+Y.”2).1/2)./(X.2+Y.2)1/2;surf(X,Y,Z);6、在0 2n范围内绘制二维曲线图y=sin(x)*cos(5x)。x=0:0.01:2*pi;y=s

28、in(x).*cos(5*x);plot(y);7、在0 2n范围内绘制以Y轴为对数的二维曲线图。y=|1000sin(4x)|+1x=0:0.01:2*pi;y=abs(1000*sin(4*x)+1;semilogy(x,y);10102101口口 Iiiiiii012345678、绘制z=sin(x)*cos(y)的三维网格和三维曲面图,x,y变化范围均为0 2n。 x=0:0.1:2*pi;y=x;X,Y=meshgrid(x,y);Z=sin(X).*cos(Y);subplot(2,1,1);mesh(X,Y,Z);subplot(2,1,2);surf(X,Y,Z);sin x

29、29、用简短的M AT LA B命令在一个图上绘制在0WxW7范围内的sin(2x)、(sin x )2和三条曲线,并将其一一标明。x=0:0.01:7;y1二sin(2*x);y2=sin(x.”2);y3=(sin(x).”2;plot(y1,-r);text(0,0,fontsize12ity=sin(2*x);hold onplot(y2,-b);text(1,sin(1),fontsize12ity=sin(x.2);hold onplot(y3,-g);text(pi/4,1/2,fontsize12ity=(sin(x)”2);hold off;八 .t Vr ecost 2co

30、s 4t + | sin I1210、在极坐标系中绘制曲线V )x=0:0.01*pi:2*pi;y=exp(cos(x)-2*cos(4*x) + (sin(x/12).”5;polar(y);27011、在同一张图中绘制sinx、cosx、sinx+cosx、sinxcosx和在4个子图中绘制sinx、 cosx、sinx+cosx、sinxcosx,并用隶书、24 号字标注。x=-2*pi:0.01:2*pi;y1=sin(x);y2=cos(x);y3=sin(x)+cos(x);y4=sin(x).*cos(x);plot(y1,-r);text(601/2*pi,1,fontsiz

31、e24fontname隶书 ity=sin(x);hold on;plot(y2,-g);text(0,1,fontsize24fontname隶书ity=cos(x);hold on;plot(y3,-b):text(pi,-1,fontsize24fontname 隶书 ity=sin(x)+cos(x);hold on;plot(y4,-m);text(0,0,fontsize24fontname 隶书ity=sin(x)*cos(x);hold off;1.510.50-0.5-1200400600800100012001400-1.5x=-2*pi:0.01:2*pi;y1=sin(

32、x);y2=cos(x);y3=sin(x)+cos(x);y4=sin(x).*cos(x);subplot(2,2,1),plot(x,y1);axis(0,2*pi,-2,2);text(1/2*pi,1,fontsize24fontname 隶书ity=sin(x);subplot(2,2,2),plot(x,y2);axis(0,2*pi,-2,2);text(0,1,fontsize24fontname 隶书ity=cos(x);subplot(2,2,3),plot(x,y3);axis(0,2*pi,-2,2);text(0,1,fontsize24fontname 隶书ity

33、=sin(x)+cos(x);subplot(2,2,4),plot(x,y4);axis(0,2*pi,-2,2);text(0,0,fontsize24fontname 隶书ity=sin(x)*cos(x);习题四111、aa22的仃列式值、逆和特征根 syms all a12 a21 a22;A =求矩阵a-21A=a11 a12a21 a22A =a11, a12a21, a22 det(A)ans =a11*a22-a12*a21 inv(A)ans =-a22/(-a11*a22+a12*a21),a12/(-a11*a22+a12*a21)a21/(-a11*a22+a12*a

34、21), -a11/(-a11*a22+a12*a21) eig(A) ans = 1/2*a11+1/2*a22+1/2*(a11A2-2*a11*a22+a22A2+4*a12*a21)A(1/2)1/2*a11+1/2*a22-1/2*(a11A2-2*a11*a22+a22A2+4*a12*a21)A(1/2)sin竺fT/2 Ae-itdt = At -2T/2g2、验证积分 syms A t tao w; yf=int(A*exp(-i*w*t),t,-tao/2,tao/2); Yf=simple(yf)Yf = 2*A*sin(1/2*tao*w)/w1(-1) k(2k -1

35、)2 k玄I3、求 t=0 syms k t; f1=t,kA3; f2=1/(2*k-1)A2,(-1)Ak/k; s1=simple(symsum(f1)1/2*t*(t-1), kA3*t s2=simple(symsum(f2,1,inf)s2 =da13d 2a134、求dxtcosx lnxdt2、tcosx lnx syms a t x; f=a,tA3;t*cos(x),log(x); df=diff(f)df =0,0-t*sin(x), 1/x dfdt2=diff(f,t,2)dfdt2 = 0, 6*t0,0ax5、bx 2sin xdx syms a b x; f=a*x,b*xA2;1/x,sin(x); disp(The interal of f is);The interal of f is pretty(int(f)321/2 a x1/3 b x log(x)-cos(x)上dt6、求

温馨提示

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

评论

0/150

提交评论