MATLAB程序设计与应用刘卫国编课后实验答案81653
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程序设计与应用(第二版) 刘卫国 课后实验报告

0 0
0 0
4.0000 0
0 9.0000
A,H,Trace,Rank,Norm 结果 H = -3.2509e+004 Trace =33 Rank =5 Norm =25.3208 4、 A=[-29,6,18;20,5,12;-8,8,5]; [V,D]=eig(A); 结果 A = -29 20 -8 5、 5 8 6 18 12 5
0 0 2、 H=hilb(5); P=pascal(5); Hh=det(H); Hp=det(P); Th=cond(H); Tp=cond(P); H,P,Hh,Hp,Th,Tp 结果 Hh = 3.7493e-012 Hp =1 Th = 4.7661e+005 Tp =8.5175e+003 3、 A=fix(10*rand(5)); H=det(A); Trace=trace(A); Rank=rank(A); Norm=norm(A);
b=?1 ans =1 x1 =0.6180 r10 =0.6180 r20 =-1.6180 4、 for i=1:100 if i==1 f(i)=1; elseif i==2 f(i)=0; elseif i==3 f(i)=1; else f(i)=f(i-1)-2*f(i-2)+f(i-3); end end a=max(f); b=min(f); c=sum(f); disp(['最大值',num2str(a)]); disp(['最小值',num2str(b)]); disp(['各数之和',num2str(c)]); zhengshu=length(find(f>0)); zeroshu=length(find(f==0)); fushu=length(find(f<0)); 结果 最大值;4.377633e+011 最小值:-8.994121e+011 各数之和:-7.427456e+011 zhengshu =49 zeroshu = 2 fushu =49 5、 s=0;
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)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解: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.1416i Columns 5 through 80.7822 + 3.1416i 0.7602 + 3.1416i 0.7254 + 3.1416i 0.6784 + 3.1416i Columns 9 through 120.6196 + 3.1416i 0.5496 + 3.1416i 0.4688 + 3.1416i 0.3780 + 3.1416i Columns 13 through 160.2775 + 3.1416i 0.1680 + 3.1416i 0.0497 + 3.1416i -0.0771 + 3.1416i Columns 17 through 20-0.2124 + 3.1416i -0.3566 + 3.1416i -0.5104 + 3.1416i -0.6752 + 3.1416i Columns 21 through 24-0.8536 + 3.1416i -1.0497 + 3.1416i -1.2701 + 3.1416i -1.5271 + 3.1416i Columns 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.6351 0.6119Columns 57 through 600.5777 0.5327 0.4774 0.4126Column 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 -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 118820ans =1728 39304 -6439304 343 65850327 274625 343ans =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和B(1) 求它们的乘积C。
MATLAB程序设计与应用(刘卫国)》(第二版)-课后实验答案

MATLAB程序设计与应⽤(刘卫国)》(第⼆版)-课后实验答案《MATLAB程序设计与应⽤(刘卫国)》(第⼆版)实验⼀MATLAB运算基础1.(1) z1=2*sin(pi*85/180)/(1+exp(2))(2)x=[2,1+2i;-0.45,5];z2=log(x+sqrt(1+x.^2))/2(3)a=-3.0:0.1:3.0;z3=0.5*(exp(0.3*a)-exp(-0.3*a)).*sin(a+0.3)+log((0.3+a)/2)(4)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)2. A=[12,34,-4;34,7,87;3,65,7];B=[1,3,-1;2,0,3;3,-2,7];(1)a=A+6*Bb=A-B+eye(size(A)) %I=eye(size(A))(2)c=A*Bd=A.*B(3)e=A^3f=A.^3(4)g=A/Bh=B\A(5)m=[A,B]n=[A([1,3],:);B^2]3. A=[1,2,3,4,5;6,7,8,9,10;11,12,13,14,15;16,17,18,19,20;21,22,23,24,25];B=[3,0,16;17,-6,9;0,23,-4;9,7,0;4,13,11];(1)C=A*B(2)D=C(3:end,2:end)4.(1) a=100:999;b=rem(a,21)==0;c=find(b);d=length(c)(2)ch='Just as Bianhaiman said,Xiehong is ...';e=find(ch>='A'&ch<='Z');ch(e)=[]实验⼆ MATLAB矩阵分析与处理R=rand(3,2);O=zeros(2,3);S=diag([1,2]);A=[E,R+R*S;O,S^2];a=A^22. H=hilb(5);P=pascal(5);Hh=det(H)Hp=det(P)Th=cond(H)Tp=cond(P)3. A=rand(5,5);a=det(A) %⾏列式的值b=trace(A) %⾏列式的迹c=rank(A) %⾏列式的秩d=norm(A) %⾏列式的范数4. A=[-29,6,18;20,5,12;-8,8,5];[V,D]=eig(A)5. 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]';(1)x=inv(A)*b(2)b1=[0.95,0.67,0.53]';x=inv(A)*b1(3)c=cond(A)6. A=rand(3,3);B=sqrtm(A)C=sqrt(A)实验三选择结构程序设计1. x=input('请输⼊x的值:');if x<0&x~=-3y=x*x+x-6;elseif x>=0&x<5&x~=2&x~=3y=x*x-5*x+6;elseendy2.(if语句)score=input('请输⼊成绩:');if score>=0&score<60disp('E');elseif score>=60&score<70disp('D');elseif score>=70&score<80disp('C');elseif score>=80&score<90disp('B');elseif score>=90&score<=100disp('A');elsedisp('您输⼊的成绩有误,请重新输⼊!'); end(switch语句)score=input('请输⼊成绩:');switch fix(score/10)case num2cell(0:5)disp('E');case {6}disp('D');case {7}disp('C');case {8}disp('B');case {9}disp('A');otherwisedisp('您输⼊的成绩有误,请重新输⼊!'); end 3. a=input('请输⼊⼯号:','s');b=input('请输⼊该员⼯的⼯时数:');y=120*84+(b-120)*(1+15/100)*84; elseif b<60y=b*84-700;elsey=b*84;endy4.a=10+fix(89*rand());b=10+fix(89*rand());c=input('请输⼊⼀个运算符:','s'); if c=='+' disp(a+b);elseif c=='-'disp(a-b);elseif c=='*'disp(a*b);elsedisp(a/b);end5. A=rand(5,6);n=1:5;n=input('请输⼊n的值:');tryB=A(n,:);catchB=A(end,:);endBlasterr实验四循环结构程序设计1.(循环结构)n=input('请输⼊n的值:');y=0;for i=1:ny=y+1/i/i;pi=sqrt(6*y);endpi(向量运算)n=input('请输⼊n的值:');i=1:n;y=1./i.^2;f=sum(y);pi=sqrt(f*6)2. y=0;n=0;while 1n=n+1;y=y+1/(2*n-1);if y>=3breakendendny=y-1/(2*n-1)3. a=input('输⼊a的值:');b=input('输⼊b的值:');x0=1.0;n=1;x1=a/(b+x0);while abs(x1-x0)>=10^(-5)|n<=500 x1=a/(b+x0); x0=x1;n=n+1;endx14. f(1)=1;f(2)=0;f(3)=1;for n=4:100f(n)=f(n-1)-2*f(n-2)+f(n-3); enda=max(f) %最⼤值b=min(f) %最⼩值c=sum(f) %各数之和d=length(find(f>0)) %正数的个数e=length(find(f==0)) %零的个数f=length(find(f<0)) %负数的个数5. n=0;s=0;for k=2:49sn=k*(k+1)-1;m=fix(sqrt(sn));for i=2:mif rem(sn,i)==0breakelseendendif i==mn=n+1;s=s+sn;endendns实验五函数⽂件1.(函数⽂件)function [e,l,s,c]=f1(x)e=exp(x);l=log10(x);s=sin(x);c=cos(x);(命令⽂件)x=input('请输⼊⼀个复数:'); [e,l,s,c]=f1(x);elsc2.(函数⽂件)function [x]=f2(A,B)C=B';x=C*inv(A);(命令⽂件)m1=input('Enter m1:');m2=input('Enter m2:');theta=input('Enter theta:'); g=9.8;A=[m1*cos(theta),-m1,-sin(theta),0;m1*sin(theta),0,cos(theta),0;0,m2,-sin(theta),0;0,0,-cos(theta),1]; B=[0,m1*g,0,m2*g]';[x]=f2(A,B);x3.(函数⽂件)function f=f3(x)f=1;for i=2:sqrt(x)if rem(x,i)==0f=0;breakendend(命令⽂件)for i=10:99j=10*rem(i,10)+fix(i/10);if f3(i)&f3(j)disp(i);endend4.(函数⽂件)function f=f4(x)f=1./((x-2).^2+0.1)+1./((x-3).^4+0.01);(命令⽂件)x=[1,2,3;4,5,6];y=f4(x)5.(1)(函数⽂件)function f=f5(n)f=n+10*log(n^2+5);(命令⽂件)y=f5(40)/(f5(30)+f5(20))(2)(函数⽂件)function f=f6(i)g=0;for i=1:nf=g+i.*(i+1);end(命令⽂件)y=f6(40)/(f6(30)+f6(20))实验六⾼层绘图操作1. x=linspace(0,2*pi,101);y=(0.5+3*sin(x)./(1+x.*x));plot(x,y);title('实验六第⼀题');xlabel('X');ylabel('Y');text(3,0.6,'y=0.5+3sin(x)/(1+x^2)');2.(1)x=linspace(0,pi,100);y1=x.^2;y2=cos(2*x);y3=y1.*y2;plot(x,y1,'b',x,y2,'g',x,y3,'r'); title('同⼀坐标系下得三条曲线'); text(2,4,'y1=x^2');text(2,-0,8,'y2=cos(2x)');text(2,-2.2,'y=x^2*cos(2x)');xlabel('X');ylabel('Y');(2)x=linspace(0,pi,100); y1=x.^2;y2=cos(2*x);y3=y1.*y2;subplot(1,3,1);plot(x,y1);title('y1=x^2');xlabel('X');ylabel('Y'); subplot(1,3,2);plot(x,y2);title('y2=cos(x)');xlabel('X');ylabel('Y') subplot(1,3,3);plot(x,y3);title('y3=x^2*cos(x)'); xlabel('X');ylabel('Y');(3)x=linspace(0,2*pi,20); y1=x.^2;y2=cos(2*x);y3=y1.*y2;subplot(4,3,1);bar(x,y1);subplot(4,3,2);bar(x,y2);subplot(4,3,3);bar(x,y3);subplot(4,3,4);stairs(x,y1);subplot(4,3,5);stairs(x,y2);subplot(4,3,6);stairs(x,y3);subplot(4,3,7);stem(x,y1);subplot(4,3,8);stem(x,y2);subplot(4,3,9);stem(x,y3);subplot(4,3,10);fill(x,y1,'b');subplot(4,3,11);fill(x,y2,'r');subplot(4,3,12);fill(x,y3,'g');3. x=linspace(-5,5,100);y=[];for x0=xif x0>=-5&x<=0y=[y,(x0+sqrt(pi))/exp(2)];elsey=[y,log(x0+sqrt(1+x0.^2))/2];endendplot(x,y);title('实验六第三题');xlabel('X');ylabel('Y');4. a=input('请输⼊a:');b=input('请输⼊b:');n=input('请输⼊n:');theta=0:0.01:2*pi;rho=a.*sin(b+n.*theta);polar(theta,rho,'r');title('极坐标曲线');(如:当输⼊a=3,b=4,n=6时,图形为:)5. x=linspace(-5,5,21);y=linspace(0,10,31);[x,y]=meshgrid(x,y);z=cos(x).*cos(y).*exp(-sqrt(x.*x+y.*y)/4); subplot(2,1,1); surf(x,y,z);title('曲⾯图');xlabel('X');ylabel('Y');zlabel('Z'); subplot(2,1,2);surfc(x,y,z);title('等⾼线图');xlabel('X');ylabel('Y');zlabel('Z');6.(⽅法⼀)s=0:pi/100:pi/2;t=0:pi/100: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;title('实验六第六题');xlabel('X');ylabel('Y');zlabel('Z');(⽅法⼆)ezsurf('cos(s)*cos(t)','cos(s)*sin(t)','sin(s)',[0,0.5*pi,0,1.5*pi]); shading interp;实验七低层绘图操作1. hf=figure('MenuBar','figure','NumberTitle','off','Color','r',...'Name','图形窗⼝⽰例',...'WindowButtonDownFcn','disp(''Left Button Pressed.'')');2. x=-1:0.1:1;y=x.^2.*exp(2*x);h=line('XData',x,'YData',y);text(0.6,0.36*exp(1.2),'\leftarrow y=x^2*exp(2*x)');set(h,'Color','r','LineStyle','--','LineWidth',2);grid on;title('函数y=x^2*exp(2*x)');3. x=0:0.00001:0.001;[x,t]=meshgrid(x);v=10*exp(-0.01*x).*sin(2000*pi*t-0.2*x+pi);axes('view',[-37.5,30]);hf=surface(x,t,v);grid on;xlabel('X');ylabel('Y');zlabel('Z');title('曲⾯v=10*exp(-0.01*x)*sin(2000*pi*t-0.2*x+pi)');set(hf,'EdgeColor','interp','FaceColor','r','LineStyle',':','LineWidth',2);4. x=linspace(0,2*pi,20);y1=sin(x);y3=sin(x)./(cos(x)+eps);y4=cos(x)./(sin(x)+eps);axes('Position',[0.15,0.1,0.2,0.4]);plot(x,y1);title('y1=sin(x)');axes('Position',[0.05,0.6,0.2,0.3]);plot(x,y2);title('y2=cos(x)');axes('Position',[0.45,0.6,0.3,0.3]);plot(x,y3);title('y3=tan(x)');axes('Position',[0.5,0.2,0.3,0.2]);plot(x,y4);title('y4=cot(x)');5. cylinder(3);light('Position',[1,2,4]); shading interp;lighting gouraud;material shiny实验⼋数据处理与多项式计算1.A=rand(1,30000);a=mean(A) %均值b=std(A,0,2) %标准⽅差c=max(A) %最⼤元素d=min(A) %最⼩元素n=0;for i=1:30000if A(i)>0.5n=n+1; %⼤于0.5的随机数的个数endendm=n/30000 %百分⽐2. P=45+fix(50*rand(100,5));[zgf,xh]=max(P) %每门课的最⾼分及相应的学号[zdf,xh]=min(P) %每门课的最低分及相应的学号pjf=mean(P) %每门课的平均分fc=std(P) %标准⽅差A=sum(P,2); %总分[zfzg,xh]=max(A) %总分最⾼分及学号[zfzd,xh]=min(A) %总分最低分及学号[zcj,xsxh]=sort(A,1,'descend')x=6.5:2:17.5;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]; a=interp1(h,t1,x,'spline')b=interp1(h,t2,x,'spline')4. x=linspace(1,101,10);y=log10(x);p=polyfit(x,y,5);y1=polyval(p,x);plot(x,y,'r:o',x,y1,'-*')。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
0、3388
z4 =
0 0、2500 0 1、2500 1、0000 2、2500
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]
A+6、*B
A-B+eye(3)
A*B
A、*B
A^3
A、^3
A/B
B\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 62
309 -72 596
154 -5 241
ans =
实验一
1、先求下列表达式的值,然后显示MATLAB工作空间的使用情况并保存全部变量。
(1)
(2) ,其中
(3)
(4) ,其中t=0:0、5:2、5
解:
M文件:
z1=2*sin(85*pi/180)/(1+exp(2))
x=[2 1+2*i;-、45 5];
z2)
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)
(3)计算系数矩阵A的条件数并分析结论。
解: M文件如下:
输出结果:
X =
1、2000
0、6000
0、6000
X2 =
1、2000
0、6000
0、6000
C =
1、3533e+003
由结果,X与X2的值一样,这表示b的微小变化对方程解也影响较小,而A的条件数算得较小,所以数值稳定性较好,A就是较好的矩阵。
12 102 4
68 0 261
9 -130 49
ans =
37226 233824 48604
247370 149188 600766
78688 454142 118820
ans =
1728 39304 -64
39304 343 658503
27274625 343
ans =
16、4000 -13、6000 7、6000
运算结果:
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)
4、4721 2、2361 3、4641
3、0000 2、8284 2、2361
b =
16、0000 6、0000 18、0000
20、0000 5、0000 12、0000
9、0000 8、0000 5、0000
分析结果知:sqrtm(A)就是类似A的数值平方根(这可由b1*b1=A的结果瞧出),而sqrt(A)则就是对A中的每个元素开根号,两则区别就在于此。
-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 48
实验三
一、实验目的
1、掌握建立与执行M文件的方法。
2、掌握利用if语句实现选择结构的方法。
3、掌握利用switch语句实现多分支选择结构的方法。
4、掌握try语句的使用。
二、实验内容
1、求分段函数的值。
用if语句实现,分别输出x=-5、0,-3、0,1、0,2、0,2、5,3、0,5、0时的y值。
解:M文件如下:
Columns 17 through 20
-0、2124 + 3、1416i -0、3566+ 3、1416i -0、5104 + 3、1416i -0、6752 + 3、1416i
Columns 21 through 24
-0、8536 + 3、1416i -1、0497 + 3、1416i -1、2701 + 3、1416i -1、5271 + 3、1416i
C= E*F
H=C(3:5,2:3)
C =
93 150 77
258 335 237
423 520 397
588 705 557
753 890 717
H =
520 397
705 557
890 717
4、完成下列操作:
(1)求[100,999]之间能被21整除的数的个数。
(2)建立一个字符串向量,删除其中的大写字母。
34 7 87 2 0 3
3 65 7 3 -2 7
ans =
12 34 -4
3 65 7
4 5 1
11 0 19
20 -5 40
3、设有矩阵A与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];
0、2663 0、3478 0、4206 0、4841
Columns 49through 52
0、5379 0、5815 0、6145 0、6366
Columns 53 through 56
0、6474 0、6470 0、6351 0、6119
Columns 57 through 60
0、5777 0、5327 0、4774 0、4126
Columns 25 through 28
-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
6、建立A矩阵,试比较sqrtm(A)与sqrt(A),分析它们的区别。
解:M文件如下:
运行结果有:
A =
16 6 18
20 5 12
9 8 5
b1 =
3、8891-0、1102 3、2103
3、2917 2、1436 0、3698
0、3855 2、0760 1、7305
b2 =
4、0000 2、4495 4、2426
ch =
123d4e56g9
实验二
1、设有分块矩阵 ,其中E、R、O、S分别为单位矩阵、随机矩阵、零矩阵与对角阵,试通过数值计算验证 。
解: M文件如下;
输出结果:
S =
1 0
0 2
A =
1、0000 0 0 0、5383 0、4427
01、0000 0 0、9961 0、1067
0 0 1、0000 0、0782 0、9619
10 12 19 21 3
11 18 25 2 9
d =
5070000
t =
65
c1 =
6、8500
c2 =
5、4618
cinf =
6、8500
4、已知
求A的特征值及特征向量,并分析其数学意义。
解:
M文件如图:
输出结果为:
V =
0、7130 0、2803 0、2733
-0、6084 -0、7867 0、8725
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、2375
z2 =
0、7114 - 0、0253i0、8968 + 0、3658i
0、2139 + 0、9343i 1、1541 - 0、0044i
35、8000 -76、2000 50、2000
67、0000 -134、0000 68、0000
ans =
109、4000 -131、2000 322、8000
-53、0000 85、0000 -171、0000
-61、6000 89、8000 -186、2000
ans =
12 34 -4 13 -1
0 0 0 1、0000 0
0 0 0 0 2、0000
a =
1、0000 0 0 1、0767 1、3280
01、0000 0 1、9923 0、3200
0 0 1、0000 0、1564 2、8857