《MATLAB程序设计与应用第二版课后题及实验答案全刘卫国》由会员分享,可在线阅读,更多相关《MATLAB程序设计与应用第二版课后题及实验答案全刘卫国(105页珍藏版)》请在金锄头文库上搜索。
1、第二章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=A(2:5,1:2:5)B = 65 24 21 34 98 21 8 42 121 43 45 21(2)A(7)=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)size(A);ndims(A)(5)题目有误(6)reshape(x,3,4)(7)abs(x)(8)char(x)4. L1 = 0 0
2、 0 0 1 0 0 0 0L2 = 1 1 1 1 1 0 0 0 0L3 = 0 0 0 1 1 1 0 0 0L4 = 4 5 65.(1)B=A(1:3,:)C=A(:,1:2)D=A(2:4,3:4)E=B*CB = 23.0000 10.0000 -0.7780 0 41.0000 -45.0000 65.0000 5.0000 32.0000 5.0000 0 32.0000C = 23.0000 10.0000 41.0000 -45.0000 32.0000 5.0000 6.0000 -9.5400D = 65.0000 5.0000 0 32.0000 54.0000 3
3、.1400E = 1.0e+003 * 0.9141 -0.2239 1.2080 2.7123 1.1330 -0.2103(2)E=10&A25)ans = 1 56. all(A)ans = 0any(A)ans = 1isnan(A) ans = 0 1 0 0 0 0 0isinf(A)ans = 0 0 1 1 0 0 0isfinite(A)ans = 1 0 0 0 1 1 17.A(1).x1=学号;A(1).x2=姓名;A(1).x3=专业;A(1).x4.x41=成绩1;.A(2).x1=学号;A(2).x2=姓名;A(2).x3=专业;A(2).x4.x41=成绩1;.
4、A(3).x1=学号;A(3).x2=姓名;A(3).x3=专业;A(3).x4.x41=成绩1;.A(4).x1=学号;A(4).x2=姓名;A(4).x3=专业;A(4).x4.x41=成绩1;.A(5).x1=学号;A(5).x2=姓名;A(5).x3=专业;A(5).x4.x41=成绩1;.8.(1)size(B)ans = 2 2ndims(B)ans = 2(2) B(2)ans =3x3 doubleB(4)ans = 3x3 cell(3)B(3)=B = 1 3x3 double 3x3 cellB3=B = 1 3x3 double 第三章1.(1)A=eye(3)(2)
5、A=100+100*rand(5,6)(3)A=1+sqrt(0.2)*randn(10,50)(4)B=ones(size(A)(5)A+30*eye(size(A)(6)B=diag(diag(A)2.B=rot90(A)C=rot90(A,-1)3.B=inv(A) ;A的逆矩阵C=det(A) ;A的行列式的值D=A*BE=B*AD=E 因此A与A-1是互逆的。4.A=4 2 -1;3 -1 2;12 3 0;b=2;10;8;x=inv(A)*bx = -6.0000 26.6667 27.33335.(1) diag(A) ;主对角线元素ans = 1 1 5 9triu(A) ;
6、上三角阵ans = 1 -1 2 3 0 1 -4 2 0 0 5 2 0 0 0 9tril(A) ;下三角阵ans = 1 0 0 0 5 1 0 0 3 0 5 011 15 0 9rank(A) ;秩ans = 4norm(A) ;范数ans = 21.3005cond(A) ;条件数ans = 11.1739trace(A) ;迹ans =16(2)略6.A=1 1 0.5;1 1 0.25;0.5 0.25 2A = 1.0000 1.0000 0.5000 1.0000 1.0000 0.2500 0.5000 0.2500 2.0000 V,D=eig(A)V = 0.7212
7、 0.4443 0.5315 -0.6863 0.5621 0.4615 -0.0937 -0.6976 0.7103D = -0.0166 0 0 0 1.4801 0 0 0 2.5365第四章1.a=input(请输入一个4位数:);while (a9999)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)
8、;g=b;b=d;d=g;g=c;c=e;e=g;a=1000*d+100*e+10*b+c;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&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)3.x=fix(rand(1,20)*89)+10;x1=fix(sum(x)/20);disp(平均数是:,nu
9、m2str(x1)m=(rem(x,2)=0&x=na=n;elseif b=nb=n;endenddisp(min:,num2str(a)disp(max:,num2str(b)请输入20个数:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20min:1max:205.s=0;x=0;for n=1:64c=2x;x=x+1;s=s+c;enddisp(2的0次方到63次方的和是:,num2str(s)2的0次方到63次方的和是:184467440737095520006,(1)sum1=0;for n=1:100x=(-1)(n+1)*(1
10、/n);sum1=sum1+x;enddisp(当n取100时: sum=,num2str(sum1)当n取100时: sum=0.68817sum2=0;for n=1:1000x=(-1)(n+1)*(1/n);sum2=sum2+x;enddisp(当n取1000时: sum=,num2str(sum2)当n取1000时: sum=0.69265sum3=0;for n=1:10000x=(-1)(n+1)*(1/n);sum3=sum3+x;enddisp(当n取10000时:sum=,num2str(sum3)当n取10000时:sum=0.6931(2)sum1=0;for n=1:2:100x=(-1)(n+1)*(1/(n+1);sum1=sum1+x;enddisp(当n取100时: sum=,num2str(sum1)当n取100时: sum=2.2496sum1=0;for n=1:2:1000x=(-1)(n+1)*(1/(n+1);sum1=sum1+x;enddisp(当n取1000时: sum=,num2str(sum1)当n取1000时: sum=3.3964sum1=0;for n=1:2