MATLAB程序设计与应用(刘卫国编)课后实验答案
MATLAB程序设计与应用刘卫国第二版实验六答案

实验六 高层绘图操作1.一、设23sin 0.5cos 0~21011x y x x x π⎡⎤=+=⎢⎥+⎣⎦,在区间取点,绘制函数的曲线。
2.二、 已知213)2cos(212y y y x y x y ⨯===,,,完成下列操作:(1)在同一坐标系下用不同的颜色和线型绘制三条曲线。
(2)以子图形式绘制三条曲线。
(3)分别用条形图、阶梯图、杆图和填充图绘制三条曲线。
三、已知 ⎪⎪⎩⎪⎪⎨⎧>++≤+=0)1ln(21022x x x x e x y ,,π 在55≤≤-x 区间绘制函数曲线。
四、绘制极坐标曲线)sin(θρn b a +=,并分析参数n b a 、、对曲线形状的影响。
五、 绘制函数的曲面图和等高线。
422cos cos y x ye x z +-=其中x 的21个值均匀分布在[-5,5]范围,y 的31个值均匀分布在[0,10],要求使用s ubplot(2,1,1)和subplot(2,1,2)将生产的曲面图和等高线图画在同一窗口上。
答案:1. x=0:pi/100:2*pi;y=(0.5+3*sin(x)/(1+x.^2))*cos(x);plot(x,y)2.(1) y1=x.^2;y2=cos(2*x);y3=y1.*y2;plot(x,y1,'b-',x,y2,'r:',x,y3,'y--');(2)1,y1=x.^2;plot(x,y1);2,y2=cos(2*x);plot(x,y2);3,y1=x.^2;Y2=cos(2*x);y3=y1.*y2;plot(x,y3);(3)1,x=0:0.5:6;y1=x.^2;subplot(2,2,1);bar(x,y1,'b')title('bar(x,y,"b")');axis([0,6,0,40])subplot(2,2,2);stairs(x,y1,'r')title('stairs(x,y,"r")');axis([0,6,0,40])subplot(2,2,3);stem(x,y1,'g')title('stem(x,y,"g")');axis([0,6,0,40])subplot(2,2,4);fill(x,y1,'y')title('fill(x,y,"y")');axis([0,6,0,40])2.x=0:2*pi/100:2*pi;y2=cos(2*x);subplot(2,2,1);bar(x,y2,'b')title('bar(x,y,"b")');axis([0,2*pi,0,1])subplot(2,2,2);stairs(x,y2,'r')title('stairs(x,y,"r")');axis([0,2*pi,0,1]) subplot(2,2,3);stem(x,y2,'g')title('stem(x,y,"g")');axis([0,2*pi,0,1])subplot(2,2,4);fill(x,y2,'y')title('fill(x,y,"y")');axis([0,2*pi,0,1])3.x=0:0.05:6;y1=x.^2;y2=cos(2*x);y3=y1.*y2;subplot(2,2,1);bar(x,y3,'b')title('bar(x,y,"b")');axis([0,6,0,1])subplot(2,2,2);stairs(x,y3,'r')title('stairs(x,y,"r")');axis([0,6,0,1])subplot(2,2,3);stem(x,y3,'g')title('stem(x,y,"g")');axis([0,6,0,1])subplot(2,2,4);fill(x,y3,'y')title('fill(x,y,"y")');axis([0,6,0,1])3.x=-5:0.1:5;if x<=0y=(x+pi.^0.5)/exp(2);elsey=0.5*log(x+(1+x.^2).^0.5);endplot(x,y)4. a=input('please input a:')b=input('please input b:')n=input('please input n:')theta=0:0.05:2*pi;rho=a.*sin(b+n.*theta);polar(theta,rho,'g')5.x=-5:0.5:5;y=0:0.3:10;[x,y]=meshgrid(x);z=cos(x).*cos(y).*exp(-0.25.*(x.^2+y.^2).^0.5); subplot(2,1,1)xlabel('x-axis'),ylabel('y-axis'),zlabel('z-axis') plot3(x,y,z,'b')title('surf')subplot(2,1,2)xlabel('x-axis'),ylabel('y-axis'),zlabel('z-axis') contour3(x,y,z,12,'y')title('contour')。
MATLAB程序设计与应用 实验答案 第六章 刘卫国

1.(1)A=randn(10,5)A =-0.4326 -0.1867 0.2944 -0.3999 -1.6041 -1.6656 0.7258 -1.3362 0.6900 0.2573 0.1253 -0.5883 0.7143 0.8156 -1.0565 0.2877 2.1832 1.6236 0.7119 1.4151 -1.1465 -0.1364 -0.6918 1.2902 -0.8051 1.1909 0.1139 0.8580 0.6686 0.5287 1.1892 1.0668 1.2540 1.1908 0.2193 -0.0376 0.0593 -1.5937 -1.2025 -0.9219 0.3273 -0.0956 -1.4410 -0.0198 -2.1707 0.1746 -0.8323 0.5711 -0.1567 -0.0592 B=mean(A)B =0.0013 0.2310 0.0253 0.3588 -0.4197 C=std(A)C =0.9034 0.8829 1.1898 0.7832 1.0821 (2)D=max(max(A))D =2.1832E=min(min(A))E =-2.1707(3)F=sum(A,2)F =-2.3288-1.32870.01056.2215-1.48953.36024.9201-3.6964-3.3998-0.3025G=sum(sum(A))G =1.9666(4)H=sort(A)H =-1.6656 -0.8323 -1.5937 -1.2025 -2.1707-1.1465 -0.5883 -1.4410 -0.3999 -1.6041-0.4326 -0.1867 -1.3362 -0.1567 -1.0565-0.0376 -0.1364 -0.6918 -0.0198 -0.92190.1253 -0.0956 0.2944 0.6686 -0.80510.1746 0.0593 0.5711 0.6900 -0.05920.2877 0.1139 0.7143 0.7119 0.21930.3273 0.7258 0.8580 0.8156 0.25731.1892 1.0668 1.2540 1.1908 0.52871.19092.1832 1.6236 1.2902 1.4151L=-sort(-A,2,'descend')L =-1.6041 -0.4326 -0.3999 -0.1867 0.2944-1.6656 -1.3362 0.2573 0.6900 0.7258-1.0565 -0.5883 0.1253 0.7143 0.81560.2877 0.7119 1.4151 1.6236 2.1832-1.1465 -0.8051 -0.6918 -0.1364 1.29020.1139 0.5287 0.6686 0.8580 1.19090.2193 1.0668 1.1892 1.1908 1.2540-1.5937 -1.2025 -0.9219 -0.0376 0.0593-2.1707 -1.4410 -0.0956 -0.0198 0.3273-0.8323 -0.1567 -0.0592 0.1746 0.57112.(1)x=[0 15 30 45 60 75 90];y=[0 0.2588 0.5000 0.7071 0.8660 0.9659 1.0000];x1=0:90;y1=interp1(x,y,x1,'spline')y1 =Columns 1 through 110 0.0175 0.0349 0.0524 0.0698 0.0872 0.1045 0.1219 0.1392 0.1564 0.1737Columns 12 through 220.1908 0.2079 0.2249 0.2419 0.2588 0.2756 0.2923 0.3090 0.3255 0.3420 0.3583Columns 23 through 330.3746 0.3907 0.4067 0.4226 0.4384 0.4540 0.4695 0.4848 0.5000 0.5150 0.5299Columns 34 through 440.5446 0.5592 0.5736 0.5878 0.6018 0.6157 0.6293 0.6428 0.6561 0.6691 0.6820Columns 45 through 550.6947 0.7071 0.7193 0.7313 0.7431 0.7547 0.7660 0.7771 0.7880 0.7986 0.8090Columns 56 through 660.8191 0.8290 0.8387 0.8480 0.8571 0.8660 0.8746 0.8829 0.8910 0.8987 0.9062Columns 67 through 770.9135 0.9204 0.9271 0.9335 0.9396 0.9454 0.9510 0.9563 0.9612 0.9659 0.9703Columns 78 through 880.9744 0.9782 0.9817 0.9849 0.9878 0.9904 0.9927 0.9946 0.9963 0.9977 0.9987Columns 89 through 910.9995 0.9999 1.0000x=[0 15 30 45 60 75];y=[0 0.2679 0.5774 1.0000 1.7320 3.7320];x1=0:75;y1=interp1(x,y,x1,'spline')y1 =Columns 1 through 110 0.0184 0.0365 0.0545 0.0724 0.0902 0.1079 0.1255 0.1431 0.1607 0.1784Columns 12 through 220.1961 0.2138 0.2317 0.2497 0.2679 0.2863 0.3048 0.3236 0.3427 0.3620 0.3817Columns 23 through 330.4017 0.4221 0.4429 0.4641 0.4858 0.5079 0.5305 0.5537 0.5774 0.6017 0.6266Columns 34 through 440.6520 0.6780 0.7046 0.7317 0.7593 0.7876 0.8163 0.8456 0.8754 0.9058 0.9367Columns 45 through 550.9681 1.0000 1.0325 1.0658 1.1003 1.1364 1.17431.2145 1.2572 1.3028 1.3516Columns 56 through 661.4041 1.4604 1.5211 1.5863 1.6565 1.7320 1.8131 1.9002 1.99362.0937 2.2008Columns 67 through 762.3152 2.4374 2.5675 2.7060 2.85323.0095 3.17523.3506 3.5361 3.7320x=[0 15 30 45 60 75 90];y=[0 0.2588 0.5000 0.7071 0.8660 0.9659 1.0000];y1=polyfit(x,y,5)y1 =0.0000 0.0000 -0.0000 0.0000 0.0174 0.0000x=[0 15 30 45 60 75];y=[0 0.2679 0.5774 1.0000 1.7320 3.7320];y1=polyfit(x,y,5)y1 =0.0000 -0.0000 0.0000 -0.0010 0.0245 0.0000(2)x=[1 4 9 16 25 36 49 64 81 100];y=1:10;x1=1:100;y1=interp1(x,y,x1,'cubic')y1 =Columns 1 through 111.0000 1.3729 1.71252.0000 2.2405 2.4551 2.64942.82923.0000 3.1636 3.3186Columns 12 through 223.4661 3.6069 3.7422 3.87294.0000 4.1237 4.24354.3599 4.4730 4.5832 4.6907Columns 23 through 334.7958 4.89885.0000 5.0993 5.1966 5.2921 5.38575.4777 5.5681 5.6570 5.7446Columns 34 through 445.8309 5.91606.0000 6.0829 6.1647 6.2454 6.32496.4035 6.4810 6.5577 6.6334Columns 45 through 556.7082 6.7823 6.8556 6.92817.0000 7.0712 7.14167.2113 7.2804 7.3487 7.4164Columns 56 through 667.4835 7.5500 7.6159 7.6812 7.7459 7.8102 7.8739 7.9372 8.0000 8.0623 8.1242Columns 67 through 778.1855 8.2464 8.3068 8.3668 8.4263 8.4854 8.5441 8.6024 8.6603 8.7178 8.7749Columns 78 through 888.8317 8.8881 8.9442 9.0000 9.0555 9.1107 9.16559.2201 9.2744 9.3284 9.3821Columns 89 through 999.4354 9.4884 9.5412 9.5935 9.6456 9.6973 9.7486 9.7996 9.8502 9.9005 9.9505Column 10010.00003.xi=[165 123 150 123 141];yi=[187 126 172 125 148];P=polyfit(xi,yi,3)P =1.0e+003 *-0.0000 0.0013 -0.1779 8.4330线性拟合曲线为:p(x)=1.3x^2—177.9x+84334.(1)P1=[0,3,2];P2=[5,-1,2];P3=[1,0,-0.5];P=conv(P1,conv(P2,P3))P =0 15.0000 7.0000 -3.5000 0.5000 -2.0000 -2.0000 (2)P1=[0,3,2];P2=[5,-1,2];P3=[1,0,-0.5];P=conv(P1,conv(P2,P3));Y=roots(P)Y =0.70710.1000 + 0.6245i0.1000 - 0.6245i-0.7071-0.6667(3)P1=[0,3,2];P2=[5,-1,2];P3=[1,0,-0.5];P=conv(P1,conv(P2,P3));k=0:10;xi=0.2*k;Y=polyval(P,xi)Y =-2.0000 -2.3920 -2.6112 -1.7024 2.7104 15.0000 42.1120 94.1408 184.9056 332.5264 560.00005.(1)[U,fmin]=fminsearch('xiti651',[1,1])U =1.0e-004 *-0.0675 0.1715fmin =1.9920e-010(2)f=inline('-sin(x)-cos(x.^2)');fminbnd(f,0,pi)ans =0.73106.(1)x=[pi/6 pi/4 pi/3 pi/2];f=inline('sin(x).^2+cos(x).^2');dx=diff(f([x,5*pi/12]))/(pi/12)dx =0 0 0 0(2)x=1:3;f=inline('sqrt(x.^2+1)');dx=diff(f([x,4]))dx =0.8219 0.9262 0.96087.(1)g=inline('sin(x).^5.*sin(5*x)');I=quadl(g,0,pi)I =0.0982(2)g=inline('(1+x.^2)./(1+x.^4)');I=quad(g,-1,1)I =2.2214(3)g=inline('(x.*sin(x))./(1+cos(x).^2)'); I=quadl(g,0,pi)I =2.4674(4)f=inline('abs(cos(x+y))');dblquad(f,0,pi,0,pi)ans =6.28329.(1)矩阵求逆法:A=[2,3,5;3,7,4;1,-7,1];b=[10;3;5];x=inv(A)*bx =-1.8060-0.53733.0448矩阵除法:A=[2,3,5;3,7,4;1,-7,1];b=[10;3;5];x=A\bx =-1.8060-0.53733.0448矩阵分解法:A=[2,3,5;3,7,4;1,-7,1];b=[10;3;5];[Q,R]=qr(A);x=R\(Q\b)x =-1.8060-0.53733.0448(2)矩阵求逆法:A=[5,1,-1,0;1,0,3,-1;-1,-1,0,5;0,0,2,4]; b=[1;2;3;-1];x=inv(A)*bx =1.4000-5.90000.1000-0.3000矩阵除法:A=[5,1,-1,0;1,0,3,-1;-1,-1,0,5;0,0,2,4]; b=[1;2;3;-1];x=A\bx =1.4000-5.90000.1000-0.3000矩阵分解法:A=[5,1,-1,0;1,0,3,-1;-1,-1,0,5;0,0,2,4];b=[1;2;3;-1];[Q,R]=qr(A);x=R\(Q\b)x =1.4000-5.90000.1000-0.300010.A=[2 1 -1 1;4 2 -2 1;2 1 -1 -1];b=[1;2;1];[x,y]=line_solution(A,b)原方程组有无穷个解,特解为x,齐次方程组的基础解系为yWarning: Rank deficient, rank = 2, tol = 4.3512e-015. > In line_solution at 11方程组无解x =[]y =-0.5000 0.50001.0000 00 1.00000 011.(1)f=inline('x-sin(x)./x');x=fzero(f,0.5)x =0.8767(2)f=inline('(sin(x).^2).*exp(-0.1.*x)-0.5.*abs(x)');x=fzero(f,1.5)x =1.673812.x=fsolve('xiti612',[0.5,0.5],optimset('Display','off')) x =0.5000y =0.5000f =-0.0509f =-0.0509 0.1173 x =0.5000y =0.5000f =-0.0509f =-0.0509 0.1173 x =0.5000y =0.5000f =-0.0509f =-0.0509 0.1173 x =0.6459y =0.3739f =0.0055f =0.0055 0.0044 x =0.6459y =0.3739f =0.0055f =0.0055 0.0044 x =0.6459y =0.3739f =0.0055f =0.0055 0.0044 x =0.6355y =0.3734f =1.9417e-005f =1.0e-004 *0.1942 0.2589 x =0.6355y =0.3734f =1.9425e-005f =1.0e-004 *0.1942 0.2589x =0.6355y =0.3734f =1.9419e-005f =1.0e-004 *0.1942 0.2591x =0.6354y =0.3734f =2.3754e-010f =1.0e-009 *0.2375 0.2957x =0.6354y =0.3734f =7.9432e-009f =1.0e-008 *0.7943 0.5602x =0.6354y =0.3734f =1.8684e-009f =1.0e-007 *0.0187 0.1936x =0.6354 0.373413.x0=0;xf=20;y1=0;[x,y]=ode45('xiti6131',[x0,xf],y1) x =0.50001.00001.50002.00002.50003.00003.50004.00004.50005.00005.50006.00006.50007.00007.50008.00008.50009.00009.500010.000010.500011.000011.500012.000012.500013.000013.500014.000014.500015.000015.500016.000016.500017.000017.500018.000018.500019.000019.500020.0000 y =NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN(2)x0=0;xf=20;[x,y]=ode45('xiti6132',[x0,xf],[-3,2])[x,y]此题结果过长,疑似错误或不会做。
MATLAB程序设计与应用(刘卫国编)课后实验答案

实验一 MATLAB 运算基础1. 先求以下表达式的值,然后显示MATLAB 工作空间的利用情形并保留全数变量。
(1) 0122sin851z e=+(2) 21ln(2z x =+,其中2120.455i x +⎡⎤=⎢⎥-⎣⎦ (3) 0.30.330.3sin(0.3)ln , 3.0, 2.9,,2.9,3.022a a e e a z a a --+=++=-- (4) 2242011122123t t z t t t t t ⎧≤<⎪=-≤<⎨⎪-+≤<⎩,其中t =0:: 解:2. 已知:1234413134787,2033657327A B --⎡⎤⎡⎤⎢⎥⎢⎥==⎢⎥⎢⎥⎢⎥⎢⎥-⎣⎦⎣⎦求以下表达式的值:(1) A+6*B 和A-B+I (其中I 为单位矩阵)(2) A*B 和A.*B(3) A^3和A.^3(4) A/B 及B\A(5) [A,B]和[A([1,3],:);B^2]解:运算结果:3. 设有矩阵A 和B1234530166789101769,111213141502341617181920970212223242541311A B ⎡⎤⎡⎤⎢⎥⎢⎥-⎢⎥⎢⎥⎢⎥⎢⎥==-⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎣⎦⎣⎦ (1) 求它们的乘积C 。
(2) 将矩阵C的右下角3×2子矩阵赋给D。
(3) 查看MATLAB工作空间的利用情形。
解:. 运算结果:4. 完成以下操作:(1) 求[100,999]之间能被21整除的数的个数。
(2) 成立一个字符串向量,删除其中的大写字母。
解:(1) 结果:(2). 成立一个字符串向量例如:ch='ABC123d4e56Fg9';那么要求结果是:实验二 MATLAB 矩阵分析与处置1. 设有分块矩阵33322322E R A O S ⨯⨯⨯⨯⎡⎤=⎢⎥⎣⎦,其中E 、R 、O 、S 别离为单位矩阵、随机矩阵、零矩阵和对角阵,试通过数值计算验证22E R RS A O S +⎡⎤=⎢⎥⎣⎦。
MATLAB程序设计与应用 刘卫国主编 高等教育出版社课后答案

y='A'; elseif x>=80
y='B'; elseif x>=70
y='C'; elseif x>=60
y='D'; else
y='E'; end y
3:
x=input('请输入工作小时数');
天天learn
if 84*x-700<=0 y=0;
1、 A=rand(100,300)
(1) mean(A) std(A,0,1);
(2) [B,C]=max(A) [E,F]=max(B)
[B1,C1]=min(A)
(3) Length(find(A>0.5))/30000
[E1,F2]=min(B1)
2、 P=45+(95-45)*rand(100,5) (1) [Y,U]=max(P) [Y1,U1]=min(P) (2) mean(P) std(P,0,1) (3) K=sum(P,2) [E,F]=max(K) [E1,F1]=min(K) (4) [zcj,xsxh]=-sort(-K,1)
break end end format long y=y-1/(2*k-1) k=k-1 3:a=input('a='); b=input('b='); n=1; x0=1; x1=a/(x0+b); while abs(x0-x1)>=10^(-5)|n<=500 k=a/(x1+b); x0=x1; x1=k; n=n+1; end x1
《MATLAB_程序设计与应用》刘卫国高等教育出版社-第4章课后答案

第四章1.a=input('请输入一个4位数:');while (a<1000|a>9999)a=input('输入错误,请重新输入一个4位数:'); endb=fix(a/1000);c=rem(fix(a/100),10);d=rem(fix(a/10),10);e=rem(a,10);b=b+7;c=c+7;d=d+7;e=e+7;b=rem(b,10);c=rem(c,10);d=rem(c,10);e=rem(e,10);g=b;b=d;d=g;g=c;c=e;e=g;a=1000*b+100*c+10*d+e;disp(['加密后:',num2str(a)])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*(sin(b)^c)+x;y3=log(abs(b+c./x));y=y1.*x1+y1.*x2+y3.*x3; disp(y)if语句法:a=input('请输入a: ');b=input('请输入b: ');c=input('请输入c: ');for x=0.5:1:5.5if x>=0.5 & x<1.5y=a.*(x.^2)+b.*x+celseif x>=1.5 & x<3.5y=a*(sin(b)^c)+xelseif x>=3.5 & x<5.5y=log(abs(b+c./x))endendswitch语句法:a=input('请输入a: ');b=input('请输入b: ');c=input('请输入c: ');for x=0.5:1:5.5switch floor(x/0.5)case {1,2}y=a.*(x.^2)+b.*x+c;case {3,4,5,6}y=a*(sin(b)^c)+x;case {7,8,9,10}y=log(abs(b+c./x)); enddisp(y)end3.x=fix(rand(1,20)*89)+10;x1=mean(x);n=find(rem(x,2)==0 & x<x1);disp(['小于平均数的偶数是:',num2str(x(n))]);4.(1)A=input('请输入20个数的一个行向量:');a=A(1);b=A(1);for m=Aif a>=ma=m;elseif b<=mb=m;endenddisp(['最小数是:',num2str(a)])disp(['最大数是:',num2str(b)])(2)A=input('请输入20个数的一个行向量:'); maxval=max(A)minval=min(A)5.s=0;for a=0:63c=2^a;s=s+c;enddisp(['2的0次方到63次方的和是:',num2str(s)])k=0:63n=2.^ks=sum(n)6.(1)sum1=0;for n=1:100x=(-1)^(n+1)*(1/n);sum1=sum1+x;enddisp(['当n取100时: sum=',num2str(sum1)])sum2=0;for n=1:1000x=(-1)^(n+1)*(1/n);sum2=sum2+x;enddisp(['当n取1000时: sum=',num2str(sum2)])sum3=0;for n=1:10000x=(-1)^(n+1)*(1/n);sum3=sum3+x;enddisp(['当n取10000时:sum=',num2str(sum3)])(2)sum1=0;n1=0;for n=1:2:100x=(-1)^n1*(1/n);sum1=sum1+x;n1=n1+1;enddisp(['当n取100时: sum=',num2str(sum1)])sum2=0;n2=0;for n=1:2:1000x=(-1)^n2*(1/n);sum2=sum2+x;n2=n2+1;enddisp(['当n取1000时: sum=',num2str(sum2)])sum3=0;n3=0;for n=1:2:10000x=(-1)^n3*(1/n);sum3=sum3+x;n3=n3+1;enddisp(['当n取10000时:sum=',num2str(sum3)])(3)sum1=0;for n=1:100x=1/(4^n);sum1=sum1+x;enddisp(['当n取100时: sum=',num2str(sum1)])sum2=0;for n=1:1000x=1/(4^n);sum2=sum2+x;enddisp(['当n取1000时: sum=',num2str(sum2)])sum3=0;for n=1:10000x=1/(4^n);sum3=sum3+x;enddisp(['当n取10000时:sum=',num2str(sum3)])(4)sum1=1;for n=1:100x=4*n*n/(2*n-1)/(2*n+1);sum1=sum1*x;enddisp(['当n取100时: sum=',num2str(sum1)])sum2=1;for n=1:1000x=4*n*n/(2*n-1)/(2*n+1);sum2=sum2*x;enddisp(['当n取1000时: sum=',num2str(sum2)])sum3=1;for n=1:10000x=4*n*n/(2*n-1)/(2*n+1);sum3=sum3*x;enddisp(['当n取10000时:sum=',num2str(sum3)])7.函数文件function f=fibnacci(n)if n==1 | n==2f=1;elsef=fibnacci(n-1)+fibnacci(n-2);end命令文件:shulie=[];for k=1:nshulie=[shulie fibnacci(k)];endshulie8.function [f1,f2]=juzhenji(x1,x2)f1=x1*x2;f2=x1.*x2;命令文件:clear alla=input('请输入一个矩阵:');b=input('请再输入一个矩阵:(注意:两矩阵要可以相乘)'); [f1,f2]=juzhenji(a,b);disp(f1)disp(f2)9.function sum=qiuhe(n,m)if n<=1sum=0;elsesum=n^m+qiuhe(n-1,m);end命令文件:clear ally=qiuhe(100,1)+qiuhe(50,2)+qiuhe(10,-1);disp(y)10.s=0;a=[12,13,14;15,16,17;18,19,20;21,22,23];for k=afor j=1:4if rem(k(j),2)~=0 s=s+k(j);endendendss =108(2)global xx=1:2:5;y=2:2:6;sub(y);xyfunction fun=sub(z) global xz=3*x;x=x+z;x =4 12 20 y =2 4 6。
matlab程序设计与应用刘卫国编课后实验答案8

实验一 MATLAB 运算基础1. 先求下列表达式的值,然后显示MATLAB 工作空间的使用情况并保存全部变量。
(1) 0122sin851z e =+ (2) 221ln(1)2z x x =++,其中2120.455i x +⎡⎤=⎢⎥-⎣⎦ (3) 0.30.330.3sin(0.3)ln , 3.0, 2.9,,2.9,3.022a a e e a z a a --+=++=--L (4) 2242011122123t t z t t t t t ⎧≤<⎪=-≤<⎨⎪-+≤<⎩,其中t =0:0.5:2.5 解: M 文件:z1=2*sin(85*pi/180)/(1+exp(2))x=[2 1+2*i;-.45 5];z2=1/2*log(x+sqrt(1+x^2))a=-3.0:0.1:3.0;z3=(exp(0.3.*a)-exp(-0.3.*a))./2.*sin(a+0.3)+log((0.3+a)./2)t=0:0.5:2.5;z4=(t>=0&t<1).*(t.^2)+(t>=1&t<2).*(t.^2-1)+(t>=2&t<3) .*(t.^2-2*t+1)运算结果:z1=2*sin(85*pi/180)/(1+exp(2))x=[2 1+2*i;-.45 5];z2=1/2*log(x+sqrt(1+x^2))a=-3.0:0.1:3.0;z3=(exp(0.3.*a)-exp(-0.3.*a))./2.*sin(a+0.3)+log((0.3+a)./2)t=0:0.5:2.5;z4=(t>=0&t<1).*(t.^2)+(t>=1&t<2).*(t.^2-1)+(t>=2&t<3) .*(t.^2-2*t+1) z1 =0.2375z2 =0.7114 - 0.0253i 0.8968 + 0.3658i0.2139 + 0.9343i 1.1541 - 0.0044iz3 =0.7388 + 3.1416i 0.7696 + 3.1416i 0.7871 + 3.1416i 0.7913 + 3.1416iColumns 5 through 80.7822 + 3.1416i 0.7602 + 3.1416i 0.7254 + 3.1416i 0.6784 + 3.1416iColumns 9 through 120.6196 + 3.1416i 0.5496 + 3.1416i 0.4688 + 3.1416i 0.3780 + 3.1416iColumns 13 through 160.2775 + 3.1416i 0.1680 + 3.1416i 0.0497 + 3.1416i -0.0771 + 3.1416iColumns 17 through 20-0.2124 + 3.1416i -0.3566 + 3.1416i -0.5104 + 3.1416i -0.6752 + 3.1416iColumns 21 through 24-0.8536 + 3.1416i -1.0497 + 3.1416i -1.2701 + 3.1416i -1.5271 + 3.1416i-1.8436 + 3.1416i -2.2727 + 3.1416i -2.9837 + 3.1416i -37.0245 Columns 29 through 32-3.0017 -2.3085 -1.8971 -1.5978 Columns 33 through 36-1.3575 -1.1531 -0.9723 -0.8083 Columns 37 through 40-0.6567 -0.5151 -0.3819 -0.2561 Columns 41 through 44-0.1374 -0.0255 0.0792 0.1766 Columns 45 through 480.2663 0.3478 0.4206 0.4841 Columns 49 through 520.5379 0.5815 0.6145 0.6366 Columns 53 through 560.6474 0.6470 0.6351 0.61190.5777 0.5327 0.4774 0.4126 Column 610.3388z4 =0 0.2500 0 1.2500 1.0000 2.25002. 已知:求下列表达式的值:(1) A+6*B和A-B+I(其中I为单位矩阵)(2) A*B和A.*B(3) A^3和A.^3(4) A/B及B\A(5) [A,B]和[A([1,3],:);B^2]解:M 文件:A=[12 34 -4;34 7 87;3 65 7];B=[1 3 -1;2 0 3;3 -2 7];A+6.*BA-B+eye(3)A*BA.*BA^3A.^3A/BB\A[A,B][A([1,3],:);B^2]运算结果:A=[12 34 -4;34 7 87;3 65 7];B=[1 3 -1;2 0 3;3 -2 7]; A+6.*BA-B+eye(3)A*BA.*BA^3A.^3A/BB\A[A,B][A([1,3],:);B^2] ans =18 52 -10 46 7 105 21 53 49 ans =12 31 -3 32 8 84 0 67 1 ans =68 44 62309 -72 596154 -5 241ans =12 102 468 0 2619 -130 49ans =37226 233824 48604 247370 149188 600766 78688 454142 118820 ans =1728 39304 -64 39304 343 658503 27 274625 343 ans =16.4000 -13.6000 7.600035.8000 -76.2000 50.200067.0000 -134.0000 68.0000ans =109.4000 -131.2000 322.8000-53.0000 85.0000 -171.0000-61.6000 89.8000 -186.2000ans =12 34 -4 1 3 -1 34 7 87 2 0 3 3 65 7 3 -2 7 ans =12 34 -43 65 74 5 111 0 1920 -5 403. 设有矩阵A和B(1) 求它们的乘积C。
MAAB程序设计与应用刘卫国编课后实验答案
实验一 MATLAB运算基础1. 先求下列表达式的值,然后显示MATLAB工作空间的使用情况并保存全部变量。
(1)0 122sin851ze =+(2)21ln( 2z x=+,其中2120.455i x+⎡⎤=⎢⎥-⎣⎦(3)0.30.330.3sin(0.3)ln, 3.0, 2.9,,2.9,3.0 22a ae e az a a--+=++=--(4)2242011122123t tz t tt t t⎧≤<⎪=-≤<⎨⎪-+≤<⎩,其中t=0:0.5:2.5解:2. 已知:求下列表达式的值:(1) A+6*B和A-B+I(其中I为单位矩阵)(2) A*B和A.*B(3) A^3和A.^3(4) A/B及B\A(5) [A,B]和[A([1,3],:);B^2]解:运算结果:3. 设有矩阵A和B(1) 求它们的乘积C。
(2) 将矩阵C的右下角3×2子矩阵赋给D。
(3) 查看MATLAB工作空间的使用情况。
解:. 运算结果:4. 完成下列操作:(1) 求[100,999]之间能被21整除的数的个数。
(2) 建立一个字符串向量,删除其中的大写字母。
解:(1) 结果:(2). 建立一个字符串向量例如:ch='ABC123d4e56Fg9';则要求结果是:实验二 MATLAB矩阵分析与处理1. 设有分块矩阵33322322E R A O S ⨯⨯⨯⨯⎡⎤=⎢⎥⎣⎦,其中E 、R 、O 、S 分别为单位矩阵、随机矩阵、零矩阵和对角阵,试通过数值计算验证22E R RS A OS +⎡⎤=⎢⎥⎣⎦。
解: M 文件如下;输出结果:由ans,所以22E R RS A O S +⎡⎤=⎢⎥⎣⎦2. 产生5阶希尔伯特矩阵H 和5阶帕斯卡矩阵P ,且求其行列式的值Hh 和Hp 以及它们的条件数Th 和Tp ,判断哪个矩阵性能更好。
为什么?解:M文件如下:输出结果:因为它们的条件数Th>>Tp,所以pascal矩阵性能更好。
MATLAB程序设计与指导应用(刘卫国编)课后实验问题详解
实验一 MATLAB 运算基础1. 先求下列表达式的值,然后显示MATLAB 工作空间的使用情况并保存全部变量。
(1) 0122sin851z e =+(2) 21ln(2z x =,其中2120.455i x +⎡⎤=⎢⎥-⎣⎦ (3) 0.30.330.3sin(0.3)ln , 3.0, 2.9,,2.9,3.022a a e e a z a a --+=++=-- (4) 2242011122123t t z t t t t t ⎧≤<⎪=-≤<⎨⎪-+≤<⎩,其中t =0:0.5:2.52. 已知:1234413134787,2033657327A B --⎡⎤⎡⎤⎢⎥⎢⎥==⎢⎥⎢⎥⎢⎥⎢⎥-⎣⎦⎣⎦求下列表达式的值:(1) A+6*B 和A-B+I (其中I 为单位矩阵)(2) A*B 和A.*B(3) A^3和A.^3(4) A/B 及B\A(5) [A,B]和[A([1,3],:);B^2]解:运算结果:3. 设有矩阵A 和B1234530166789101769,111213141502341617181920970212223242541311A B ⎡⎤⎡⎤⎢⎥⎢⎥-⎢⎥⎢⎥⎢⎥⎢⎥==-⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎣⎦⎣⎦ (1) 求它们的乘积C 。
(2) 将矩阵C 的右下角3×2子矩阵赋给D 。
(3) 查看MATLAB 工作空间的使用情况。
解:. 运算结果:4. 完成下列操作:(1) 求[100,999]之间能被21整除的数的个数。
(2) 建立一个字符串向量,删除其中的大写字母。
解:(1) 结果:(2). 建立一个字符串向量例如:ch='ABC123d4e56Fg9';则要求结果是:实验二 MATLAB 矩阵分析与处理1. 设有分块矩阵33322322E R A O S ⨯⨯⨯⨯⎡⎤=⎢⎥⎣⎦,其中E 、R 、O 、S 分别为单位矩阵、随机矩阵、零矩阵和对角阵,试通过数值计算验证22E R RS A OS +⎡⎤=⎢⎥⎣⎦。
《MATLAB程序设计与应用》刘卫国高等教育出版社课后答案 已解锁-去水印 适合打印
SY404 clear all for n=1:4 if n==1 f1=1; elseif n==2 f2=0; elseif n==3 f3=1; else a=f3-2*f2+f1; b=a-2*f3+f2; c=b-2*a+f3; d=c-2*b+a; H=[1,0,1,a,b,c,d]; for m=8:4:99 a=d-2*c+b; b=a-2*d+c; c=b-2*a+d; d=c-2*b+a; H=[H,a,b,c,d]; end f100=d-2*c+b; end end max=max(H);
[f1,f2]=f(n); a=f1; b=f2; elseif n==30; [f1,f2]=f(n); c=f1; d=f2; else [f1,f2]=f(n); e=f1; f=f2; end end y1=e/(a+c); y2=f/(b+d); disp(['(1) y=',num2str(y1)]) disp(['(2) y=',num2str(y2)]) f function [f1,f2]=f(n) f1=n+10*log(n^2+5); x=0; for a=1:n b=a*(a+1); x=x+b; end f2=x; fushu function [e,l,s,c]=fushu(x) e=exp(x); l=log(x); s=sin(x); c=cos(x); disp(['复数e的指数是:',num2str(e)]) disp(['复数e的对数是:',num2str(l)]) disp(['复数e的正弦是:',num2str(s)]) disp(['复数e的余弦是:',num2str(c)])
最新Matlab程序设计与应用第二版刘卫国课后实验答案
实验一:T1:%%第一小题z1=2*sin(85*pi/180)/(1+exp(2))%%第二小题x=[2,1+2i;-0.45,5];z2=1/2*log(x+sqrt(1+x.^2));z2%%第三小题a=-3.0:0.1:3.0;z3=1/2*(exp(0.3*a)-exp(-0.3*a)).*sin(a+0.3)+l og((0.3+a)/2)%%第四题t=0:0.5:2.5z4=(t>=0&t<1).*(t.^2)+(t>=1&t<2).*(t.^2-1)+(t >=2&t<3).*(t.^2-2*t+1)T2:A=[12,34,-4;34,7,87;3,65,7]B=[1,3,-1;2,0,3;3,-2,7]disp ('A+6*B=');disp(A+6*B);disp('A-B+I=');disp(A-B+eye(3));disp('A*B=');disp(A*B);disp('A.*B=');disp(A.*B);disp('A^3=');disp(A^3);disp('A.^3=');disp(A.^3);disp('A/B=');disp(A/B);disp('B\A=');disp(B\A);disp('[A,B]=');disp([A,B]);disp('[A([1,3],:);B^2]=');disp([A([1,3],:);B^2]);T3:z=1:25;A=reshape(z,5,5)';B=[3,0,16;17,-6,9;0,23,-4;9,7,0;4,13,11]; C=A*BD=C(3:5,2:3)T4-1:a=100:999;b=find(rem(a,21)==0);c=length(b)T4-2:a=input('请输入一个字符串:','s');b=find(a>='A'&a<='Z');a(b)=[];disp(a);实验二:T1:E=eye(3),R=rand(3,2),O=zeros(2,3),S=diag([1,2 ]);A=[E,R;O,S]disp('A^2=');disp(A^2);disp('[E,R+RS;O,S^2]');B=[E,R+R*S;O,S^2]T2:H=hilb(5)P=pascal(5)Hh=det(H)Hp=det(P)Th=cond(H)Tp=cond(P)a=abs(Th-1);b=abs(Tp-1);if a>bdisp('帕萨卡矩阵P性能更好');elseif a<bdisp('希尔伯特矩阵H性能更好');elsedisp('两个矩阵性能相同');endT3:a=1:25;A=reshape(a,5,5)disp('行列式的值:');disp(det(A));disp('矩阵的秩:');disp(rank(A));disp('矩阵的迹:');disp(trace(A));disp('矩阵的范数:');disp(norm(A));T4:A=[-29,6,18;20,5,12;-8,8,5][V,D]=eig(A)T5:A=[1/2,1/3,1/4;1/3,1/4,1/5;1/4,1/5,1/6]B=[0.95,0.67,0.52]'X1=A\BB(3)=0.53X2=A\Bdisp('系数矩阵A的条件数:'); disp(cond(A));T6:a=1:25;A=reshape(a,5,5)disp('B1=sqrtm(A)');B1=sqrtm(A)disp('B2=sqrt(A)');B2=sqrt(A)disp('B1*B1');B1*B1disp('B2.*B2');B2.*B2实验三:T1:x=-5.0:2:5.0for i=1:length(x);if (x(i)<0)&(x(i)~=-3)y(i)=x(i)^2+x(i)-6;elseif(x(i)>=0)&(x(i)<5)&(x(i)~=2)&(x(i)~=3);y(i)=x(i)^2-5*x(i)+6;elsey(i)=x(i)^2-x(i)-1;endendyT2-if:s=input('please enter the score:'); while (s<0||s>100)disp('the score is not reasonable');s=input('please enter the score:'); endif (s>=90&s<=100);disp('A');elseif(s>=80&s<90);disp('B');elseif(s>=70&s<80);disp('C');elseif(s>=60&s<70);disp('D');elsedisp('E');endT2-switch:s=input('please enter the score:'); while (s<0||s>100)disp('the score is not reasonable');s=input('please enter the score:'); endswitch fix(s/10)case{9,10}disp('A');case{8}disp('B');case{7}disp('C');case{6}disp('D');case{0,1,2,3,4,5}disp('E');endT3:t=input('请输入工时time=');if t>120w=120*84+(t-120)*1.15*84; elseif t<60w=t*84-700;elsew=84*t;enddisp('应发工资为:');disp(w);T4:a=10+floor(rand(1)*89)b=10+floor(rand(1)*89)s=input('请输入+或-或*或/','s');while(s~='+'&&s~='-'&&s~='*'&&s~='/') disp('输入的符号错误,请重新输入');s=input('请输入+或-或*或/','s');endswitch scase{'+'}c=a+b;case{'-'}c=a-b;case{'*'}c=a*b;case{'/'}c=a/b;endcT5:A=rand(5,6)n=input('请输入n:');while (n<1)disp('输入的n有误,请重新输入');n=input('请输入n:');endif n>5B=A(5,:)elseB=A(n,:)End实验四:T1:n=input('请输入n:');m=0;for i=1:n;m=m+1/i^2;endpii=sqrt(6*m)T1-2:n=input('请输入n:');m=1./(1:n).^2;s=sum(m);pii=sqrt(6*s)T2:n=1000;y=0; for i=1:n;y=y+1/(2*i-1);if y>=3disp('最大n值为:');i-1disp('对应的y值为:');y-1/(2*i-1)break;endendT3:format longa=input('请输入a:');b=input('请输入b:');x(1)=a/(1.0+b);i=1;x(2)=a/(x(i)+b);while (abs(x(i+1)-x(i))>0.00001&i<500)i=i+1;x(i+1)=a/(x(i)+b);endr1=(-b+sqrt(b^2+4*a))/2;r2=(-b-sqrt(b^2+4*a))/2;disp(['x',num2str(i+1),'=',num2str(x(i+1),8)]); disp(['x',num2str(i),'=',num2str(x(i),8)]);disp(['r1=',num2str(r1,8),',r2=',num2str(r2,8)]) ;format shortT4:f(1)=1;f(2)=0;f(3)=1;i=4;while(i<=100)f(i)=f(i-1)-2*f(i-2)+f(i-3);i=i+1;endfmax=max(f)fmin=min(f)fsum=sum(f)fp=length(find(f>0))fn=length(find(f<0))f0=length(find(f==0))T5:j=0;s=0;for i=3:50m=i*(i-1)-1;if isprime(m)==1ms=s+m;j=j+1;endenddisp(['亲密数的对数:',num2str(j)]);disp(['所有亲密素数之和:',num2str(s)]);实验五:fn1:function f=fn1(n)f=n+10*log(n.^2+5);fn2:function f=fn2(n)f=0;for i=1:nf=f+i*(i+1);endfx:function f=fx(x)f=1./((x-2).^2+0.1)+1./((x-3).^4+0.01);T1:x=input('请输入一个复数:');fe=exp(x)flg=log(x)fsin=sin(x)fcos=cos(x)T2:m1=input('请输入m1:');m2=input('请输入m2:');t=input('请输入theta:');A=[m1*cos(t),-m1,-sin(t),0;m1*sin(t),0,...cos(t),0;0,m2,-sin(t),0;0,0,-cos(t),1]B=[0,m1*9.8,0,m2*9.8]'disp('[a1,a2,N1,N2]=');disp([A\B]');T3:j=1;n=1;k=1;for i=10:99 % 挑选出10~99中所有的素数if isprime(i)==1m(j)=i;j=j+1;endendfor t=1:length(m);s(n)=10*rem(m(t),10)+fix(m(t)/10); %挑选出的素数进行位置交换if isprime(s(n))==1 %再挑选出交换绝对素数r(k)=m(t);k=k+1;endn=n+1;enddisp(['所有两位绝对素数:',num2str(r)])T5:y1=fn1(40)/(fn1(30)+fn1(20)) %函数调用y2=fn2(40)/(fn2(30)+fn2(20))实验六:T1:x=linspace(0,2*pi,101);y=(0.5+3*sin(x)./(1+x.^2)).*cos(x);plot(x,y);T2:x=linspace(0,2*pi,100);y1=x.^2;y2=cos(2*x);y3=y1.*y2;subplot(2,2,1);plot(x,y1,'r:',x,y2,'y-',x,y3,'b-.');subplot(2,2,2);plot(x,y1,'r:');subplot(2,2,3);plot(x,y2,'y-');subplot(2,2,4);plot(x,y3,'b-.');T2-3:x=linspace(0,2*pi,10);y1=x.^2;y2=cos(2*x);y3=y1.*y2;subplot(3,4,1);bar(x,y1,'r');axis([0,7,0,40]);subplot(3,4,2);stairs(x,y1,'y');axis([0,7,0,40]);subplot(3,4,3);stem(x,y1,'b');axis([0,7,0,40]);subplot(3,4,4);fill(x,y1,'g');axis([0,7,0,40]);subplot(3,4,5);bar(x,y2,'r');axis([-1,7,-1,1]);subplot(3,4,6);stairs(x,y2,'y');axis([-1,7,-1,1]);subplot(3,4,7);stem(x,y2,'b');axis([-1,7,-1,1]);subplot(3,4,8);fill(x,y2,'g');axis([-1,7,-1,1]);subplot(3,4,9);bar(x,y3,'r');axis([0,7,-30,50]);subplot(3,4,10);stairs(x,y3,'y');axis([0,7,-30,50]); subplot(3,4,11);stem(x,y3,'b');axis([0,7,-30,50]); subplot(3,4,12);fill(x,y3,'g');axis([0,7,-30,50]);T3:x=linspace(-5,5,100);y=[];for x0=x;if x0<=0;y=[y,(x0+sqrt(pi))/exp(2)];elsey=[y,1/2*log(x0+sqrt(1+x0^2))];endendsubplot(1,2,1);plot(x,y);for i=1:length(x)if x(i)<=0y(i)=(x(i)+sqrt(pi))/exp(2);elsey(i)=1/2*log(x(i)+sqrt(1+x(i)^2)); endendsubplot(1,2,2);plot(x,y);T4:a=input('请输入a:');b=input('请输入b:');n=input('请输入n:'); theta=0:0.001:2*pi;y=a.*sin(b+n.*theta);polar(theta,y);T5:x=linspace(-5,5,21);y=linspace(0,10,31);[x,y]=meshgrid(x,y);z=cos(x).*cos(y).*exp(-sqrt(x.^2+y.^2)/4); subplot(1,2,1);surf(x,y,z);subplot(1,2,2);contour3(x,y,z);T6:s=0:pi/2;t=0:3*pi/2;[s,t]=meshgrid(s,t);x=cos(s).*cos(t);y=cos(s).*sin(t);z=sin(s);surf(x,y,z);shading interp;实验八:T1:A=rand(1,30000);disp('均值为:');mean(A)disp('标准方差为:');std(A)disp('最大元素为:');max(A)disp('最小元素为:');min(A)k=find(A>0.5);b=length(k);disp('大于0.5的随机数个数占总数的百分比:');sprintf('%f%%', b/300)T2:P=45+50*rand(100,5)disp('最高分及序号:');[Y,U]=max(P,[],1)disp('最低分及序号:');[Y1,U1]=min(P,[],1)disp('每门课平均分:');mean(P,1)disp('每门课的标准方差:');std(P,0,1)s=sum(P,2);disp('总分最高分:');[Y2,U2]=max(s,[],1)disp('总分最低分:');[Y3,U3]=min(s,[],1)[zcj,xsxh]=sort(s,1,'descend') %descend降序T3:h=6:2:18;t1=[18.0,20.0,22.0,25.0,30.0,28.0,24.0];t2=[15.0,19.0,24.0,28.0,34.0,32.0,30.0];t=6.5:2:17.5;T1=interp1(h,t1,t,'spline')T2=interp1(h,t2,t,'spline')T4:x=1:10:101;y=log10(x);p=polyfit(x,y,5)x1=1:0.01:101;y1=log10(x1);y2=polyval(p,x1);plot(x1,y1,'r-',x1,y2,'b-.');T5:P1=[1,2,4,0,5];P2=[0,0,0,1,2];P3=[0,0,1,2,3];P4=conv(P2,P3);sp1=length(P1);sp2=length(P4);P=[zeros(1,sp2-sp1),P1]+P4x=roots(P)A=[-1,1.2,-1.4;0.75,2,3.5;0,5,2.5];Ax=polyval(P,A)AA=polyvalm(P,A)实验九:T1:f=inline('det([x x^2 x^3;1 2*x 3*x^2;0 2 6*x])');i=1;x=1;while x<=3.01g(i)=f(x);i=i+1;x=x+0.01;enddx=diff(g)/0.01;dx(1)dx(101)dx(length(g)-1)T2:f1=inline('sqrt(cos(t.^2)+4*sin(2*t).^2+1)')f2=inline('log(1+x)./(1+x.^2)')I1=quad(f1,0,2*pi)I2=quad(f2,0,2*pi)T3:A=[6,5,-2,5;9,-1,4,-1;3,4,2,-2;3,-9,0,2];B=[-4,13,1,11]';x1=A\B[L,U]=lu(A);x2=U\(L\B)[Q,R]=qr(A);x3=R\(Q\B)fun:function F=fun(X);x=X(1);y=X(2);z=X(3);F(1)=sin(x)+y^2+log(z)-7;F(2)=3*x+2^y-z^3+1;F(3)=x+y+z-5;T5:f=inline('3*x+sin(x)-exp(x)');fzero(f,1.5)X=fsolve('fun',[1 1 1]',optimset('Display','off')) 实验十:T1:x=sym('6');y=sym('5');z=(x+1)/(sqrt(3+x)-sqrt(y))T2:syms x y;t=sym('5135');factor(x^4-y^4)factor(t)T3:syms beta1 beta2 x;simplify(sin(beta1)*cos(beta2)-cos(beta1)*sin (beta2))simplify((4*x^2+8*x+3)/(2*x+1))T4:syms a b c d e f g h k;p1=[0,1,0;1,0,0;0,0,1];p2=[1,0,0;0,1,0;1,0,1];A=[a,b,c;d,e,f;g,h,k];B=p1*p2*AB1=inv(B)B1*B;tril(B)det(B)T5:syms x t a yf1=(x*(exp(sin(x))+1)-2*(exp(tan(x))-1))/sin(x) ^3;limit(f1,x,0) %(1)f2=(sqrt(pi)-sqrt(acos(x)))/sqrt(x+1);limit(f2,x,-1,'right') %(2)f3=(1-cos(2*x))/x;diff(f3,x,1) %(3)diff(f3,x,2)A=[a^x,t^3;t*cos(x),log(x)];diff(A,x,1) &(4)diff(A,t,2)diff(diff(A,x,1),t,1)f5=(x^2-2*x)*exp(-x^2-y^2-x*y);yx=-diff(f5,x,1)/diff(f5,y,1) %(5)fxy=diff(diff(f5,x,1),y,1)x=sym('0');y=sym('1');eval(fxy)T6:x=sym('x');f1=1/(1+x^4+x^8);int(f1,x)f2=1/(asin(x))^2/sqrt(1-x^2);int(f2,x)f3=(x^2+1)/(x^4+1);int(f3,x,0,inf)f4=exp(x)*(1+exp(x))^2;int(f4,x,0,log(2))实验十一:T1:syms n x ;S1=symsum(1/(2*n-1),n,1,10)S2=symsum(n^2*x^(n-1),n,1,inf)S3=symsum(n^2/5^n,n,1,inf)T2:x=sym('x');f=log(x);taylor(f,x,6,1)T3:x1=solve('log(1+x)-5/(1+sin(x))=2')x2=solve('x^2+9*sqrt(x+1)-1=0')x3=solve('3*x*exp(x)+5*sin(x)-78.5=0')[x4,y4]=solve('sqrt(x^2+y^2)-100=0','3*x+5*y-8=0')T4:dsolve('D2y+4*Dy+29*y=0','y(0)=0','Dy(0)=15' ,'x')T5:[x,y,z]=dsolve('Dx=2*x-3*y+3*z','Dy=4*x-5*y+ 3*z','Dz=4*x-4*y+2*z','t')2020年普通高等学校招生全国统一考试(山东模拟卷)语文一、现代文阅读(35分)(一)现代文阅读I(本题共5小题,19分)阅读下面的文字,完成1~5题。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
实验一 MATLAB 运算基础1. 先求下列表达式的值,然后显示MATLAB 工作空间的使用情况并保存全部变量。
(1) 0122sin851z e=+ (2) 221ln(1)2z x x =++,其中2120.455i x +⎡⎤=⎢⎥-⎣⎦(3) 0.30.330.3sin(0.3)ln , 3.0, 2.9,,2.9,3.022a a e e a z a a --+=++=-- (4) 2242011122123t t z t t t t t ⎧≤<⎪=-≤<⎨⎪-+≤<⎩,其中t =0:0.5:2.5 解: M 文件:z1=2*sin(85*pi/180)/(1+exp(2))x=[2 1+2*i;-.45 5];z2=1/2*log(x+sqrt(1+x^2))a=-3.0:0.1:3.0;z3=(exp(0.3.*a)-exp(-0.3.*a))./2.*sin(a+0.3)+log((0.3+a)./2) t=0:0.5:2.5; z4=(t>=0&t<1).*(t.^2)+(t>=1&t<2).*(t.^2-1)+(t>=2&t<3) .*(t.^2-2*t+1)运算结果:z1=2*sin(85*pi/180)/(1+exp(2))x=[2 1+2*i;-.45 5];z2=1/2*log(x+sqrt(1+x^2))a=-3.0:0.1:3.0;z3=(exp(0.3.*a)-exp(-0.3.*a))./2.*sin(a+0.3)+log((0.3+a)./2)t=0:0.5:2.5;z4=(t>=0&t<1).*(t.^2)+(t>=1&t<2).*(t.^2-1)+(t>=2&t<3) .*(t.^2-2*t+1) z1 =0.2375z2 =0.7114 - 0.0253i 0.8968 + 0.3658i0.2139 + 0.9343i 1.1541 - 0.0044iz3 =Columns 1 through 40.7388 + 3.1416i 0.7696 + 3.1416i 0.7871 + 3.1416i 0.7913 + 3.1416iColumns 5 through 80.7822 + 3.1416i 0.7602 + 3.1416i 0.7254 + 3.1416i 0.6784 + 3.1416iColumns 9 through 120.6196 + 3.1416i 0.5496 + 3.1416i 0.4688 + 3.1416i 0.3780 + 3.1416iColumns 13 through 160.2775 + 3.1416i 0.1680 + 3.1416i 0.0497 + 3.1416i -0.0771 + 3.1416iColumns 17 through 20-0.2124 + 3.1416i -0.3566 + 3.1416i -0.5104 + 3.1416i -0.6752 + 3.1416iColumns 21 through 24-0.8536 + 3.1416i -1.0497 + 3.1416i -1.2701 + 3.1416i -1.5271 + 3.1416iColumns 25 through 28-1.8436 + 3.1416i -2.2727 + 3.1416i -2.9837 + 3.1416i -37.0245Columns 29 through 32-3.0017 -2.3085 -1.8971 -1.5978Columns 33 through 36-1.3575 -1.1531 -0.9723 -0.8083Columns 37 through 40-0.6567 -0.5151 -0.3819 -0.2561Columns 41 through 44-0.1374 -0.0255 0.0792 0.1766Columns 45 through 480.2663 0.3478 0.4206 0.4841Columns 49 through 520.5379 0.5815 0.6145 0.6366Columns 53 through 560.6474 0.6470 0.63510.6119Columns 57 through 600.5777 0.5327 0.4774 0.4126Column 610.3388z4 =0 0.2500 0 1.2500 1.0000 2.25002. 已知:1234413134787,2033657327A B --⎡⎤⎡⎤⎢⎥⎢⎥==⎢⎥⎢⎥⎢⎥⎢⎥-⎣⎦⎣⎦求下列表达式的值:(1) A+6*B 和A-B+I (其中I 为单位矩阵)(2) A*B 和A.*B(3) A^3和A.^3(4) A/B 及B\A(5) [A,B]和[A([1,3],:);B^2]解: M 文件:A=[12 34 -4;34 7 87;3 65 7];B=[1 3 -1;2 0 3;3 -2 7]; A+6.*BA-B+eye(3)A*BA.*BA^3A.^3A/BB\A[A,B][A([1,3],:);B^2]运算结果:A=[12 34 -4;34 7 87;3 65 7];B=[1 3 -1;2 0 3;3 -2 7]; A+6.*BA-B+eye(3)A*BA.*BA^3A.^3A/BB\A[A,B][A([1,3],:);B^2]ans =18 52 -1046 7 10521 53 49ans =12 31 -332 8 840 67 1ans =68 44 62309 -72 596154 -5 241ans =12 102 468 0 2619 -130 49ans =37226 233824 48604247370 149188 60076678688 454142 118820 ans =1728 39304 -6439304 343 65850327 274625 343 ans =16.4000 -13.6000 7.600035.8000 -76.2000 50.200067.0000 -134.0000 68.0000ans =109.4000 -131.2000 322.8000-53.0000 85.0000 -171.0000-61.6000 89.8000 -186.2000ans =12 34 -4 1 3 -134 7 87 2 0 33 65 7 3 -2 7ans =12 34 -43 65 74 5 111 0 1920 -5 403. 设有矩阵A 和B1234530166789101769,111213141502341617181920970212223242541311A B ⎡⎤⎡⎤⎢⎥⎢⎥-⎢⎥⎢⎥⎢⎥⎢⎥==-⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎣⎦⎣⎦(1) 求它们的乘积C。
(2) 将矩阵C的右下角3×2子矩阵赋给D。
(3) 查看MATLAB工作空间的使用情况。
解:. 运算结果:E=(reshape(1:1:25,5,5))';F=[3 0 16;17 -6 9;0 23 -4;9 7 0;4 13 11]; C= E*FH=C(3:5,2:3)C =93 150 77258 335 237423 520 397588 705 557753 890 717H =520 397705 557890 7174. 完成下列操作:(1) 求[100,999]之间能被21整除的数的个数。
(2) 建立一个字符串向量,删除其中的大写字母。
解:(1) 结果:m=100:999;n=find(mod(m,21)==0);length(n)ans =43(2). 建立一个字符串向量例如:ch='ABC123d4e56Fg9';则要求结果是:ch='ABC123d4e56Fg9';k=find(ch>='A'&ch<='Z');ch(k)=[]实验二 MATLAB 矩阵分析与处理1. 设有分块矩阵33322322E R A O S ⨯⨯⨯⨯⎡⎤=⎢⎥⎣⎦,其中E 、R 、O 、S 分别为单位矩阵、随机矩阵、零矩阵和对角阵,试通过数值计算验证22E R RS A O S +⎡⎤=⎢⎥⎣⎦。
解: M 文件如下;输出结果:S =1 00 2ch =123d4e56g9A =1.0000 0 0 0.5383 0.44270 1.0000 0 0.9961 0.10670 0 1.0000 0.0782 0.96190 0 0 1.0000 00 0 0 0 2.0000a =1.0000 0 0 1.0767 1.32800 1.0000 0 1.9923 0.32000 0 1.0000 0.1564 2.88570 0 0 1.0000 00 0 0 0 4.0000ans =0 0 0 0 00 0 0 0 00 0 0 0 00 0 0 0 00 0 0 0 0由ans,所以22E R RS A O S +⎡⎤=⎢⎥⎣⎦2. 产生5阶希尔伯特矩阵H 和5阶帕斯卡矩阵P ,且求其行列式的值Hh 和Hp 以及它们的条件数Th 和Tp ,判断哪个矩阵性能更好。
为什么?解:M 文件如下:输出结果:H =1.0000 0.5000 0.3333 0.2500 0.20000.5000 0.3333 0.2500 0.2000 0.16670.3333 0.2500 0.2000 0.1667 0.14290.2500 0.2000 0.1667 0.1429 0.12500.2000 0.1667 0.1429 0.1250 0.1111 P =1 1 1 1 11 2 3 4 51 3 6 10 151 4 10 20 351 5 15 35 70Hh =3.7493e-012Hp =1Th =4.7661e+005Tp =8.5175e+003因为它们的条件数Th>>Tp,所以pascal矩阵性能更好。
3. 建立一个5×5矩阵,求它的行列式值、迹、秩和范数。
解:M文件如下:输出结果为:A =17 24 1 8 1523 5 7 14 164 6 13 20 2210 12 19 21 311 18 25 2 9d =5070000t =65c1 =6.8500c2 =5.4618cinf =6.85004. 已知2961820512885A -⎡⎤⎢⎥=⎢⎥⎢⎥-⎣⎦求A 的特征值及特征向量,并分析其数学意义。