MATLAB 上机 习题及答案.doc_第1页
MATLAB 上机 习题及答案.doc_第2页
MATLAB 上机 习题及答案.doc_第3页
MATLAB 上机 习题及答案.doc_第4页
MATLAB 上机 习题及答案.doc_第5页
免费预览已结束,剩余28页可下载查看

下载本文档

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

文档简介

15、今有多项式P1(x)=x4-2x+1,P2(x)=x2+4x-0.5,要求先求得P(x)=P1(x)+P2(x),然后计算xi=0.2*i各点上的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+p2x p = x4+2*x+1/2+x2 x=0:5; x.4+2*x+1/2+x.2ans = 0.5000 4.5000 24.5000 96.5000 280.5000 660.50001、试个MATLAB的工作空间中建立以下2个矩阵:A1 2 ,求出矩阵A和B的乘积,并将结果赋给变量C。 A=1 2A = 1 2 B=1 2 3 4B = 1 2 3 4 C=A*BC = 7 102、利用MATLAB提供的帮助信息,了解inv命令的调用格式,并作简要说明。help inv INV 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 also SLASH, PINV, COND, CONDEST, LSQNONNEG, LSCOV. Overloaded methods help gf/inv.m help zpk/inv.m help tf/inv.m help ss/inv.m help lti/inv.m help frd/inv.m help sym/inv.m help idmodel/inv.m3、使用help命令查询函数plot的功能以及调用方法,然后利用plot命令绘制函数y=sin(x)的图形,其中。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 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),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: b blue . point - solid g green o circle : dotted r red x x-mark -. dashdot c cyan + plus - dashed m magenta * star y yellow s square k black d diamond v triangle (down) triangle (up) triangle (right) p pentagram h hexagram For 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,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 specified, 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 cycles 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, TITLE, XLABEL, YLABEL, AXIS, AXES, HOLD, COLORDEF, LEGEND, SUBPLOT, STEM. Overloaded methods help cfit/plot.m help fints/plot.m help cgrules/Plot.m help xregtwostage/plot.m help xregtransient/plot.m help xregmodel/plot.m help localmod/plot.m help sweepset/plot.m help mdevtestplan/plot.m help cgdatasetnode/plot.m help cgdatadisplay/plot.m help idmodel/plot.m help iddata/plot.m help ntree/plot.m help dtree/plot.m help wvtree/plot.m help rwvtree/plot.m help edwttree/plot.m a=0:0.01:pi; y=sin(a); plot(y)4、试用不同的方法建立数组A1 1.5 2.0 2.5 3.0,了解怎样访问数组A的第二个元素,然后将其更换为4.0。A=1 1.5 2.0 2.5 3.0A = 1.0000 1.5000 2.0000 2.5000 3.0000 A(2)ans = 1.5000 A(2)=4.0A = 1.0000 4.0000 2.0000 2.5000 3.00005、已知矩阵,试用MATLAB提供的关系运算命令将B中所有大于2的元素全改为0。 B=1 2 5 0 7 2 6 3 1B = 1 2 5 0 7 2 6 3 1 B(find(B2)ans = 6 7 3 5 B(find(B2)=0B = 1 2 0 0 0 2 0 0 16、已知矩阵,试求矩阵A的左右翻转矩阵,上下翻转矩阵,然后在工作空间中利用size命令查看矩阵A的大小。A=1 2 3 4 5 6 7 8 9A = 1 2 3 4 5 6 7 8 9 fliplr(A)ans = 3 2 1 6 5 4 9 8 7 flipud(A)ans = 7 8 9 4 5 6 1 2 3 size(A)ans = 3 37、已知矩阵,试求其转置、逆、迹、特征值、特征向量和B对应的行列式的值。B=1 2 3 4B = 1 2 3 4 Bans = 1 3 2 4 inv(B)ans = -2.0000 1.0000 1.5000 -0.5000 trace(B)ans = 5eig(B)ans = -0.3723 5.3723 det(B)ans = -28、分别建立一个阶的单位阵、随机阵和魔方阵。eye(3)ans = 1 0 0 0 1 0 0 0 1 rand(3)ans = 0.9501 0.4860 0.4565 0.2311 0.8913 0.0185 0.6068 0.7621 0.8214 magic(3)ans = 8 1 6 3 5 7 4 9 29、已知多项式,。试求两个多项式的和与乘积。syms x a=x2+2*x-2 a = x2+2*x-2 b=x3+x2-3*x+1 b = x3+x2-3*x+1 a+b ans = 2*x2-x-1+x3 a*b ans = (x2+2*x-2)*(x3+x2-3*x+1)10、复数表达,及计算。z1=3+4*iz1 = 3.0000 + 4.0000i z2=1+2iz2 = 1.0000 + 2.0000i z3=2*exp(pi/6*i)z3 = 1.7321 + 1.0000i z=z1*z2/z3z = 0.3349 + 5.5801i11、产生15的均布随机数组,进行如下操作:1)寻访数组的第三个元素;2)寻访数组的第一、二、五个元素组成的子数组;3)寻访前三个元素组成的子数组;4)寻访除前2个元素外的全部其他元素。A=rand(1,5)A = 0.4447 0.6154 0.7919 0.9218 0.7382 A(3)ans = 0.7919 A(1 2 5)ans = 0.4447 0.6154 0.7382 A(1:3)ans = 0.4447 0.6154 0.7919 A(2:end)ans = 0.6154 0.7919 0.9218 0.738212、试用两种方法用MATLAB计算1) syms x x=solve(x3=-8,x) x = -2 1-i*3(1/2) 1+i*3(1/2)2)x=-8(1/3)x = -213、求的“商”及“余”多项式。p1=conv(1,0,2,conv(1,4,1,1); p2=1 0 1 1; q,r=deconv(p1,p2)q = 1 5r = 0 0 5 4 314、求方程 x4+7x3 +9x-20=0的全部根。p=1 7 0 9 -20; roots(p)ans = -7.2254 -0.4286 + 1.5405i -0.4286 - 1.5405i 1.0826 16、已知一线性方程组如下所示:,试求其结果。 a=3.0 1.0 -1.0;1.0 2.0 4.0;-1.0 4.0 5.0a = 3 1 -1 1 2 4 -1 4 5 b=3.6;2.1;-1.4b = 3.6000 2.1000 -1.4000 x=abx = 1.4818 -0.4606 0.384817、已知矩阵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 9求(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 = 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 9(1) rank(A)ans = 6(2) det(A)ans = 595024(3) trace(A)ans = 36(4) poly(A)ans = 1.0e+005 * Columns 1 through 6 0.0000 -0.0004 0.0060 -0.0760 0.7135 -3.5599 Column 7 5.9502 B=poly(A)B = 1.0e+005 * Columns 1 through 6 0.0000 -0.0004 0.0060 -0.0760 0.7135 -3.5599 Column 7 5.9502 roots(B)ans = -0.1622 +12.0911i -0.1622 -12.0911i 14.5379 9.3652 + 1.9707i 9.3652 - 1.9707i 3.0561 (6) inv(A)ans = 0.0038 -0.0939 -0.3510 0.2592 0.1833 0.0302 -0.0571 -0.0215 -0.4883 0.3388 0.2592 0.0461 0.0864 0.0956 0.5906 -0.4883 -0.3510 -0.0708 0.0189 0.0216 0.0956 -0.0215 -0.0939 -0.0407 0.0417 0.0189 0.0864 -0.0571 0.0038 -0.0515 0.0515 0.0407 0.0708 -0.0461 -0.0302 0.0430(7) v d=eig(A)v = Columns 1 through 4 0.2562 + 0.3857i 0.2562 - 0.3857i -0.4691 0.0200 + 0.1849i 0.0680 + 0.4650i 0.0680 - 0.4650i 0.2202 -0.8084 -0.4968 -0.4968 0.0284 0.3485 - 0.0625i -0.2618 + 0.0993i -0.2618 - 0.0993i -0.3118 0.0639 - 0.1206i -0.3238 - 0.0038i -0.3238 + 0.0038i 0.5385 0.2438 + 0.1483i -0.3360 - 0.1475i -0.3360 + 0.1475i -0.5861 -0.2942 - 0.0029i Columns 5 through 6 0.0200 - 0.1849i 0.3706 -0.8084 0.6762 0.3485 + 0.0625i -0.6252 0.0639 + 0.1206i -0.0948 0.2438 - 0.1483i -0.0679 -0.2942 + 0.0029i 0.0307 d = Columns 1 through 4 -0.1622 +12.0911i 0 0 0 0 -0.1622 -12.0911i 0 0 0 0 14.5379 0 0 0 0 9.3652 + 1.9707i 0 0 0 0 0 0 0 0 Columns 5 through 6 0 0 0 0 0 0 0 0 9.3652 - 1.9707i 0 0 3.0561 习题二1、编制一个函数,使得该函数能对输入的两个数值进行比较,并返回其中的最小值。function m=min(a,b)if(a min(2,1)ans = 12、试编一个m程序,将一维数组x中的N个数按颠倒的次序重新存储。如N=5,原来x为:x= 1 3 5 7 9 而经过颠倒处理后x中数据的次序应该为:x= 9 7 5 3 1 function b=fun1(x)N=length(x)for i=1:N b(i)=x(N-i+1);endfun1(1 3 5 7 9)N = 5ans = 9 7 5 3 13、 编制一个m程序,计算阶乘n!= 123nfunction m=fun2(n)m=1;for i=1:n m=m*i;endfun2(3)ans = 64、利用循环语句进行程序设计:假设定义mn的矩阵A。判断矩阵A的第1列元素是否为0,若全为0,则从矩阵A中删除第1列function b=fun3(A)m,n=size(A)for i=1:m if A(i,1)=0 YC=0; continue; else YC=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.75 x=r y=1+1/x; s=yend6、编程计算k=0;for i=0:63 k=k+2i;endk = 1.8447e+019习题三1、用subplot命令在同一图形输出窗口中绘制以下4个函数的图形:,。x=-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.5,-1,3)subplot(2,2,4),plot(x,y4);axis(0,1.3,-1,3)2、绘制曲线在区间上的阶梯图。x=0:0.1:5*pi;y=exp(-0.2*x).*sin(x);stairs(y);3、试绘制以极坐标形式表示的图形:,其中的范围为。x=0:0.01*pi:8*pi;y=cos(5/4*x)+1/3;polar(x,y);4、画出衰减振荡曲线及其它的包络线。的取值范围是。x=0:0.01*pi:4*pi;y=exp(-x/3).*sin(3*x);y0=exp(-x/3);plot(y);hold onplot(y0);hold off;5、画出所表示的三维曲面。的取值范围是。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 2范围内绘制二维曲线图y=sin(x)*cos(5x)。x=0:0.01:2*pi;y=sin(x).*cos(5*x);plot(y);7、在0 2范围内绘制以Y轴为对数的二维曲线图。 y=|1000sin(4x)|+1x=0:0.01:2*pi;y=abs(1000*sin(4*x)+1;semilogy(x,y);8、绘制z=sin(x)*cos(y)的三维网格和三维曲面图,x,y变化范围均为 0 2。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);9、用简短的M AT L A B命令在一个图上绘制在0x7范围内的sin(2x)、 和三条曲线,并将其一一标明。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;10、在极坐标系中绘制曲线x=0:0.01*pi:2*pi;y=exp(cos(x)-2*cos(4*x)+(sin(x/12).5;polar(y);11、在同一张图中绘制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,fontsize24fontname隶书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;x=-2*pi:0.01:2*pi;y1=sin(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=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);习题四1、求矩阵的行列式值、逆和特征根 syms a11 a12 a21 a22; A=a11 a12 a21 a22 A = a11, a12 a21, 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*a21), -a11/(-a11*a22+a12*a21) eig(A) ans = 1/2*a11+1/2*a22+1/2*(a112-2*a11*a22+a222+4*a12*a21)(1/2) 1/2*a11+1/2*a22-1/2*(a112-2*a11*a22+a222+4*a12*a21)(1/2)2、验证积分。 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)/w3、求, syms k t; f1=t,k3; f2=1/(2*k-1)2,(-1)k/k; s1=simple(symsum(f1) s1 = 1/2*t*(t-1), k3*t s2=simple(symsum(f2,1,inf) s2 = 1/8*pi2, -log(2)4、求、 syms a t x; f=a,t3;t*cos(x),log(x); df=diff(f) df = 0, 0 -t*sin(x), 1/x dfdt2=diff(f,t,

温馨提示

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

评论

0/150

提交评论