您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 能源与动力工程 > matlab题库答案
P.28ex2.1数值变量的运算formatshorteclearmuw0=1.785e-3;a=0.03368;b=0.000221;t=0:20:80;muw=muw0./(1+a*t+b*t.^2)muw=1.7850e-0031.0131e-0036.6092e-0044.6772e-0043.4940e-004p.31ex2.2数值驻足和字符串转换a=[1:5];b=num2str(a);aa=12345bb=12345b*2ans=986464100646410264641046464106P.44ex2.9比较用左除和右除分别求解恰定方程(线性方程组如果方程数等于未知数个数,叫做恰定方程组,如果方程多于未知数,叫做超定方程组,反之称为欠定。换个角度说,系数矩阵如果是方阵,就是恰定方程组)的解见课本P.48ex2.14计算矩阵的指数并比较不同函数的结果b=magic(3);expm(b)ans=1.0e+006*1.08981.08961.08971.08961.08971.08971.08961.08971.0897expmdemo2(b)ans=1.0e+006*1.08981.08961.08971.08961.08971.08971.08961.08971.0897expm1(b)ans=1.0e+003*2.98000.00170.40240.01910.14741.09560.05368.10210.0064expmdemo3(b)ans=1.0e+006*1.08981.08961.08971.08961.08971.08971.08961.08971.0897P50ex2.18计算矩阵的特征值条件数a=rand(3)a=0.96490.95720.14190.15760.48540.42180.97060.80030.9157[V,D,s]=condeig(a)V=0.49130.66960.66960.3158-0.4476+0.2831i-0.4476-0.2831i0.8117-0.2332-0.4655i-0.2332+0.4655iD=1.81460000.2757+0.3061i0000.2757-0.3061is=1.17921.23661.2366P62ex2.29矩阵的抽取、三角抽取a=pascal(4)a=1111123413610141020diag(a,-2)ans=14v=diag(diag(a))v=10000200006000020%diag简单来说就是抽取矩阵各对角线上的元素,如上是抽取主对角线以下第二条对角线之元素,其另一功能是建立对角矩阵tril(a)ans=100012001360141020triu(a)ans=111102340061000020%triu&tril用法与diag非常类似,用途是提取下、上三角矩阵P62ex2.30建立多项式之伴随矩阵这道题有点凌乱了…….求解释P64ex2.31数组的幂运算a=[21-3-1;3107;-124-2;10-15];a^3ans=32-28-1013499-12-151239-14993851-17-98139a.^3ans=81-27-12710343-1864-810-1125P66ex2.32数组之逻辑运算a=[1:3;4:6;7:9];b=[010;101;001];x=5;y=ones(3)*5;x=aans=000011111%此处小于等于,对a中元素和x注意比较,大者为假为0,不大者为1ab=a&bab=010101001%此处为与运算,就是同真才为真(同为非零数)~bans=101010110%逻辑非运算,即全都非,真变假假变真;还有逻辑或运算,看下面即懂:a|bans=111111111%总结多项式运算的函数:poly:Polynomialwithspecifiedroots特征多项式的生成p=poly(a)a为n阶特征矩阵,所得一般为n阶特征多项式;poly2sym数值2符号;polyval求多项式的值;roots求多项式的根;conv多项式的乘法(向量之卷积)conv(p,d);polyder多项式微分;polyfit多项式拟合。P71ex2.41多项式拟合,用5阶多项式对正弦函数进行最小二乘拟合x=0:pi/20:pi/2;y=sin(x);a=polyfit(x,y,5);x1=0:pi/30:pi*2;y1=sin(x1);y2=a(1)*x1.^5+a(2)*x1.^4+a(3)*x1.^2+a(4)*x1.^2+a(5)*x1+a(6);plot(x1,y1,'b-',x1,y1,'r*')legend('原曲线','拟合曲线')axis([0,7,-1.2,4])axis([0,7,-1.2,1.5])%调整坐标轴显示范围2.符号运算命名和基本运算法则P79符号矩阵的运算A=sym('[a,b;c,d]')A=[a,b][c,d]symsabcdB=[a,b;c,d]B=[a,b][c,d]B-Aans=[0,0][0,0]A/Bans=[1,0][0,1]A^2ans=[a^2+b*c,a*b+b*d][a*c+c*d,d^2+b*c]A.^2ans=[a^2,b^2][c^2,d^2]det(A)ans=a*d-b*c%行列式inv(A)ans=[d/(a*d-b*c),-b/(a*d-b*c)][-c/(a*d-b*c),a/(a*d-b*c)]%逆rank(A)ans=2%秩%SUMMARY矩阵的分解:奇异值分解[U,S,V]=svd(A);特征值分解[V,D]=eig(A);正交分解[Q,R]=qr(A);三角分解[L,U]=lu(A);P88ex3.7利用函数gradient绘制一个矢量图[x,y]=meshgrid(-2:.2:2,-2:.2:2);z=x.*exp(-x.^2-y.^2);[px,py]=gradient(z,.2,.2);contour(z),%等高线绘制函数holdonquiver(px,py)%矢量图绘制函数%绘图SUMMARY1.二维plot不解释;fplot:绘制y=f(x)图形fplot(fname,lims,’s’);ezplot:绘制隐函数图形help吧;极坐标polar,对数坐标semilogx,semilogy,loglog;bar条形图,pie饼状图;hist直方图有些疑惑!;gridon/off:控制是否画网格线。boxon/off:控制是否加边框线。holdon/off控制是否刷新当前轴及图形%2.三维:plot3;meshgrid函数:产生平面区域内的网格坐标矩阵;mesh画格子;surf面;figure(n)开窗户;subplot:割图。3.二维图形函数运用P98基本绘图命令y=rand(100,1);plot(y)x=rand(100,1);z=x+y.*i;plot(z)P101ex4.1绘制带有显示属性的二维属性x=1:0.1*pi:2*pi;y=sin(x);z=cos(x);plot(x,y,'--k',x,z,'-.rd')P104ex4.5条状图和矢量图x=1:10;y=rand(10,1);bar(x,y)x=:0.1*pi:2*pi;x=0:0.1*pi:2*pi;y=x.*sin(x);feather(x,y)P104ex4.6函数图形绘制lim=[0,2*pi,-1,1];fplot('[sin(x),cos(x)]',lim)P105ex4.7绘制饼状图x=[2,4,6,8];pie(x,{'math','english','chinese','music'})4.三维图形函数应用P107ex4.9绘制三维螺旋线x=0:pi/50:10*pi;y=sin(x);z=cos(x);plot3(x,y,z)P107ex4.10绘制参数为矩阵的三维图[x,y]=meshgrid(-2:0.1:2,-2:0.1:2);z=x.*exp(-x.^2-y.^2);plot3(x,y,z)P109ex4.11使用mesh函数绘制三维面图x=-8:0.5:8;y=x';a=ones(size(y))*x;b=y*ones(size(x));c=sqrt(a.^2+b.^2)+eps;z=sin(c)./c;mesh(z)P110ex4.13meshc函数绘制的三维面图[X,Y]=meshgrid([-4:0.5:4]);Z=sqrt(X.^2+Y.^2);meshc(Z)P111ex4.16绘制三维饼状图clearx=[2,4,6,8];pie(x)pie(x,[0,0,1,0])pie3(x,[0,0,1,0])pie3(x,[0,0,1,1])P113ex4.19绘制如图柱面图x=0:pi/20:pi*3;r=5+cos(x);[a,b,c]=cylinder(r,30);mesh(a,b,c)P113ex4.20绘制地球表面的气温分布示意图[a,b,c]=sphere(40);t=abs(c);surf(a,b,c,t);axis('equal')axis('square')colormap('hot')5.图形控制命令P118ex4.24坐标标注函数应用x=1:0.1*pi:2*pi;y=sin(x);plot(x,y)xlabel('x(0-2\pi)')ylabel('y=sin(x)')title('正弦函数','FontSize')Errorusingtitle(line29)IncorrectnumberofinputargumentsErrorintitle(line23)h=title(gca,varargin{:});title('正弦函数','FontSize',12)title('正弦函数','FontSize',12,'FontWeight',bold)%课本上不知由于版本问题还是什么,与2011b不同,最后尝试用Bold成功解决ADD已解决,用单引号引起bold即可Undefinedfunctionorvariable'bold'.title('正弦函数','FontSize',12,'FontWeight',Bold)Undefinedfunctionorvariable'Bold'.title('正弦函数','FontSize',12,'FontWeight','Bold')title('正弦函数','FontSize',12,'FontWeight','Bold','FontName','隶书')P123ex4.30在同一张途中绘制几个三角函数图x=0:0.1*pi:2*pi;y=sin(x);z=cos(x);plot(x,y,'-*')holdonplot(x,z,'-o')plot(x,y+z,'-+')legend('sin(x)','cos(x)','sin(x)+cos(x)',0)P124ex4.31在4个子图中绘制不同的三角函数x=0:0.1*pi:2*pi;subplot(2,2,1);plot(x,sin(x),'-*')title('sin(x)')subplot(2,2,2)plot(x,cos(x),'-o')title('cos(x)')subplot(2,2,3)plot(x,
本文标题:matlab题库答案
链接地址:https://www.777doc.com/doc-2887942 .html