2022年MATLAB程序设计与应用第二课后题答案.docx
精品学习资源封面欢迎下载精品学习资源作者: PanHongliang仅供个人学习其次章3.设矩阵 A 为A=24 23 9 21 6 ;65 74 24 11 21 ;34 5 98 75 21 ;8 42 42 53 121 ;43 21 45 64 21;( 1) B=A2:5,1:2:5B =欢迎下载精品学习资源652421349821842121434521( 2) A7=A =24 65 34 8 43 23 5 42 21 9 24 98 42 45 21 11 75 53 64 6 21 21 121 21( 3) A+30(4) ) sizeA;ndimsA(5) )题目有误(6) ) reshapex,3,4(7) ) absx(8) ) charx4. L1 =000010000L2 =1L3 =11110000000111000L4 =4565.1B=A1:3,:C=A:,1:2D=A2:4,3:4 E=B*CB =23.000010.0000-0.7780041.0000-45.000065.00005.000032.00005.0000032.0000C =23.000010.000041.0000-45.000032.00005.00006.0000-9.5400D =65.00005.0000032.000054.00003.1400E =1.0e+003 *0.9141-0.22391.20802.71231.1330-0.21032E<D欢迎下载精品学习资源ans =010001E&D ans =110111E|D ans =111111D|E ans =001000findA>=10&A<25 ans =156.allAans =0anyA ans =1isnanA ans =0100000isinfA ans =0011000isfiniteA ans =10001117.A1.x1= 学 号 ; A1.x2= 姓 名 ; A1.x3= 专 业 ; A1.x4.x41= 成 绩1; .A2.x1= 学 号 ; A2.x2= 姓 名 ; A2.x3= 专 业 ; A2.x4.x41= 成 绩1; .欢迎下载精品学习资源A3.x1= 学 号 ; A3.x2= 姓 名 ; A3.x3= 专 业 ; A3.x4.x41= 成 绩1; .A4.x1= 学 号 ; A4.x2= 姓 名 ; A4.x3= 专 业 ; A4.x4.x41= 成 绩1; .A5.x1= 学 号 ; A5.x2= 姓 名 ; A5.x3= 专 业 ; A5.x4.x41= 成 绩1; .8.1sizeB ans =22ndimsB ans =22B2ans =3x3 doubleB4ans =3x3 cell 3B3= B =1 3x3 double3x3 cell B3=B =13x3 double第三章1.1A=eye32 A=100+100*rand5,63A=1+sqrt0.2*randn10,50 4B=onessizeA 5A+30*eyesizeA 6B=diagdiagA2.B=rot90A C=rot90A,-1 3.B=invA;A 地逆矩阵C=detA;A 地行列式地值D=A*B E=B*A欢迎下载精品学习资源D=E 因此 A 与 A -1 是互逆地 .4.A=4 2 -1 ;3 -1 2;12 3 0;b=2;10;8;x=invA*bx =-6.000026.666727.33335.1diagA;主对角线元素ans =1159triuA;上三角阵ans =1-12301-4200520009trilA;下三角阵ans =100051003050111509rankAans =;秩4normA;范数ans =21.3005condA;条件数ans =11.1739traceA;迹ans =16( 2)略6.A=1 1 0.5;1 1 0.25;0.5 0.25 2欢迎下载精品学习资源A =1.00001.00000.50001.00001.00000.25000.50000.25002.00000.72120.44430.5315-0.68630.56210.4615-0.0937-0.69760.7103=-0.01660001.48010002.5365V,D=eigA V =D第四章1.a=input'请输入一个 4 位数:'; while a<1000|a>9999a=input'输入错误 , 请重新输入一个 4位数:';endb=fixa/1000;c=remfixa/100,10;d=remfixa/10,10;e=rema,10 ;b=b+7; c=c+7; d=d+7; e=e+7;b=remb,10 ;c=remc,10 ;d=remc,10 ;e=reme,10 ;g=b;b=d;d=g;g=c;c=e;e=g;a=1000*d+100*e+10*b+c;disp'加密后: ',num2stra 2.a=input'请输入a: ';b=input'请输入 b: ';c=input'请输入c: ';x=0.5:1:5.5;x1=x>=0.5&x<1.5 ;x2=x>=1.5&x<3.5 ;x3=x>=3.5&x<=5.5 ;y1=a.*x.2+b.*x+c;y2=a*sinbc+x;y3=logabsb+c./x;欢迎下载精品学习资源y=y1.*x1+y1.*x2+y3.*x3;dispy 3.x=fixrand1,20*89+10;x1=fixsumx/20;disp'平均数是: ',num2strx1m=remx,2=0&x<x1 ;n=findm ;disp'小于平均数地数是: ',num2strxn;4.A=input'请输入20个数地一个行向量: ' ;m=A;a=m;b=m;for m=A if a>=m a=m;elseif b<=mb=m;end enddisp'最小数是: ',num2stradisp'最大数是: ',num2strb 5.s=0 ;a=0; for b=1:64 c=2a;a=a+1;s=s+c;enddisp'2地0次方到63次方地和是: ',num2strs6,sum1=0;for n=1:100x=-1n+1*1/n;sum1=sum1+;x enddisp'当n取100时: sum=',num2strsum1 sum2=0;for n=1:1000x=-1n+1*1/n;sum2=sum2+;x enddisp'当n取1000时: sum=',num2strsum2sum3=0; for n=1:10000x=-1n+1*1/n;欢迎下载精品学习资源sum3=sum3+;x enddisp'当n取10000时: sum=',num2strsum3 8.clear alla=input'请输入一个矩阵: ' ;b=input'请再输入一个矩阵: 留意:两矩阵要可以相乘 ';f1,f2=juzhenjia,b;9.clear ally=qiuhe100,1+qiuhe50,2+qiuhe10,-1;dispy 10.1S=108 2x=4 12 20y=24 6第五章1. 1 x=-10:0.1:10;y=100./1+x.2;plotx,y2 x=-10:0.1:10;y=1/2*pi*exp-x.2/2 ;plotx,y3 ezplot'x2+y2=1' 4t=-10:0.1:10;x=t.2;y=5*t.3 ;plotx,y2.1theta=0:0.01:2*pi;rho=5*costheta+4;polartheta,rho2theta=0.001:0.1:2*pi;rho=12./sqrttheta;polartheta,rho3 theta=0.001:0.1:2*pi;rho=5./costheta-7;polartheta,rho4theta=0.001:0.1:2*pi;rho=pi/3.*theta.2;polartheta,rho3.1欢迎下载精品学习资源t=0:pi/100:2*pi ;x=cost;y=sint;z=t;plot3x,y,z 2u=0:pi/100:2*pi ;v=0:pi/100:2*pi ;x=1+cosu.*cosv;y=1+cosu.*sinv ;z=sinu; plot3x,y,z345.plot 函数:>> x=linspace-10,10,200;>> y= ;>> for x0=x if x0>0y=y,x0.2+1+x0.1/4+5 ;elseif x0=0 y=y,0 ;elseif x0<0y=y,x0.3+sqrt1-x0-5 ;endend>> plotx,y fplot 函数:fplot'x<0.*x.3+sqrt1-x-5+x=0.*0+x>0.*x.2+1+x.1/4+5',-10,10第六章1.A=randn10,5(1) ) meanA;均值stdA;标准方差(2) ) maxmaxA;最大元素minminA;最小元素(3) ) B=sumA,2;A 每行元素地和sumB;A 全部元素之和(4) ) sortA;A 地每列元素按升序排列sortA,2,descend;A 地每行元素按将序排列2.( 1)( 2)X=1 4 9 16 25 36 49 64 81 100;Y=1:10;X1=1:100;欢迎下载精品学习资源Y1=interp1X,Y ,X1,'cubic'3.x=165 123 150 123 141;y=187 126 172 125 148;P=polyfitx,y,3 P =1.0e+003 *-0.00000.0013-0.17798.4330所以它地线性拟合曲线为: px=1.3x2177.9x+84334.1P1=0 3 2;P2=5 -1 2;P3=1 0 -0.5;P=convconvP1,P2,P3 P =015.00007.0000-3.50000.5000-2.0000-2.0000所以 Px=15x5+7x4-3.5x3+0.5x2-2x-2 2rootsP ans =0.70710.1000 + 0.6245i0.1000 - 0.6245i-0.7071-0.66673 i=0:10;xi=0.2*i ;polyvalP,xi ans =-2.0000-2.3920-2.6112-1.70242.710415.000042.112094.1408184.9056 332.5264560.00005.1建立函数文件:function f=fxyux=u1;y=u2;f=3.*x.2+2*x.*y+y.2在命令窗口中输入以下命令: U,fmin=fminsearch'fxy',1,1 结果:U =1.0e-004 *-0.06750.1715fmin = 1.9920e-010欢迎下载精品学习资源( 2)f=inline'-sinx-cosx.2' ;fmax=fminbndf,0,pi fmax =0.73106.( 1) x=pi/6 pi/4 pi/3 ;f=inline'sinx.2+cosx.2' ;dx=difffx,5*pi/12/pi/12可参见第 157 页例题 6.19 dx =000x=pi/2 时单独运算:x=pi/2 ;f=inline'sinx.2+cosx.2' ;difffx,pi/pi/2 ans =0( 2)x=1:3;f=inline'sqrtx.2+1' ;dx=difffx,4结果:dx =0.82190.92620.96087.( 1) f=inline'sinx.5.*sin5*x' ;quadf,0,pians =0.0982( 2) f=inline'1+x.2./1+x.4' ;quadf,-1,1ans =2.2214( 3) f=inline'x.*sinx./1+cosx.2' ;quadf,0,pians =2.4674( 4) f=inline'abscosx+y';dblquadf,0,pi,0,pians =6.2832欢迎下载精品学习资源8.N=64;%采样点数T=5;%采样时间终点t=linspace0,T,N;%给出 N 个采样时间 ti(i=1:N )y=exp-t;%求各采样点样本值 y dt=t2-t1;%采样周期f=1/dt ;% 采样频率Y=ffty ;%运算 y 地快速傅里叶变换 Y F=Y1:N/2+1 ;%Fk=Ykf=f*0:N/2/N ;%使频率轴 f 从 0 开头plotf,absF%绘制振幅 -频率图9.( 1)矩阵求逆法:A=2 3 5 ;3 7 4;1 -7 1;b=10;3;5;x=invA*bx =-1.8060-0.53733.0448矩阵除法法:A=2 3 5 ;3 7 4;1 -7 1;b=10;3;5;x=Abx =-1.8060-0.53733.0448矩阵分解法:A=2 3 5 ;3 7 4;1 -7 1;b=10;3;5;L,U=luA ;x=ULb x =-1.8060-0.53733.0448( 2)方法同( 1)10.函数文件: line_solutionA,b function x,y=line_solutionA,bm,n=sizeA;欢迎下载精品学习资源y=;if normb>0if rankA=rankA,b if rankA=ndisp'原方程组有唯独解 x';x=Ab ;elsedisp'原方程组有无穷个解 , 特解为 x, 齐次方程组地基础解系为 y';x=Ab ;y=nullA,'r';enddisp'方程组无解 ';x=;end elsedisp'原方程组有零解 x';x=zerosn,1;if rankA<ndisp'方程组有无穷个解 , 基础解系为 y';y=nullA,'r';end end程序:A=2 1 -1 1;4 2 -2 1;2 1 -1 -1;b=1;2;1;x,y=line_solutionA,b 结果:原方程组有无穷个解 ,特解为 x,齐次方程组地基础解系为 y Warning: Rank deficient, rank = 2, tol =4.3512e-015.> In line_solution at 11方程组无解x =欢迎下载精品学习资源y =-0.50000.50001.0000001.00000011.( 1)f=inline'x-sinx./x' ;x=fzerof,0.5 x =0.87672f=inline'sinx.2.*exp-0.1.*x-0.5.*absx' ;x=fzerof,1.5 x =1.673812.函数文件: function f=fxyu x=u1y=u2f1=x-0.6*sinx-0.3*cosyf2=y-0.6*cosx+0.3*siny在命令窗口输入以下命令: x=fsolve'fxy',0.5,0.5,optimset'Display','off' 结果:x =0.63540.373415.A=-1 2 0 ;-1 2 -1;-1 2 -1;-1 2 -1;0 2 -1 ;d=-1;0;1;B=spdiagsA,d,5,5;b=1 0 0 0 0';x=invB*b' x =0.83330.66670.50000.33330.1667版权申明本文部分内容,包括文字、图片、以及设计等在网上搜集整理;版权为潘宏亮个人全部This article includes some parts, including text,欢迎下载精品学习资源pictures, and design. Copyright is Pan Hongliang's personal ownership.用户可将本文的内容或服务用于个人学习、争论或观看,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵害本网站及相关权益人的合法权益;除此以 外,将本文任何内容或服务用于其他用途时,须征得本人及相关权益人的书面许可,并支付酬劳;Users may use the contents or services of this article for personal study, research or appreciation, and other non-commercial or non-profit purposes, but at the same time, they shall abide by the provisions of copyright law and other relevant laws, and shall not infringe upon the legitimate rights of this website and its relevant obligees. In addition, when any content or service of this article is used for other purposes, written permission and remuneration shall be obtained from the person concerned and the relevant obligee.转载或引用本文内容必需是以新闻性或资料性公共免费信息为使用目的的合理、善意引用,不得对本文内容原意进行曲解、修 改,并自负版权等法律责任;Reproduction or quotation of the content of this欢迎下载精品学习资源article must be reasonable and good-faith citation for theuse of news or informative public free information. Itshall not misinterpret or modify the original intention ofthe content of this article, and shall bear legal liabilitysuch as copyright.欢迎下载