1、1第二章3. 写出完成下列操作的命令假设:A=rand(5,5) B=A(2:5,1,3,5) A(7)= A+30 size(A), ndims(A) t=0:0.1:1,t(find(t=0)=eps x=1:12, reshape(x,3,4) abs(b) char(89) 4.下列命令执行后,L1,L2,L3,L4 的值分别是多少A=1:9;B=10-A;L1=A=B;L2=A3 L1L2L3L4 L1 =0 0 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 6 5.A=23 10 -0.778 0;41
2、 -45 65 5;32 5 0 32;6 -9.54 54 3.14;B=A(1:3,:)C=A(:,1:2)D=A(2:end,3:end)2E=B*C B =23.0000 10.0000 -0.7780 041.0000 -45.0000 65.0000 5.000032.0000 5.0000 0 32.0000C =23.0000 10.000041.0000 -45.000032.0000 5.00006.0000 -9.5400D =65.0000 5.00000 32.000054.0000 3.1400E =1.0e+003 *0.9141 -0.22391.2080 2.
3、71231.1330 -0.2103 6.A=34,NaN,Inf,-Inf,-pi,eps,0all(A) A =34.0000 NaN Inf -Inf -3.1416 0.0000 0ans =0 any(A) ans =1 isnan(A) ans =0 1 0 0 0 0 0 3isinf(A) ans =0 0 1 1 0 0 0 isfinite(A) ans =1 0 0 0 1 1 1 7.student(1).number=123;student(1).name=lili; student(1).specialty=computer; student(1).grade=87
4、 68 70 70 97 95;student(2).number=123;student(2).name=lili; student(2).specialty=computer; student(2).grade=87 68 70 70 97 95;student(3).number=123;student(3).name=lili; student(3).specialty=computer;student(3).grade=87 68 70 70 97 95;student(4).number=123;student(4).name=lili; student(4).specialty=
5、computer; student(4).grade=87 68 70 70 97 95;student(5).number=123;student(5).name=lili; student(5).specialty=computer; student(5).grade=87 68 70 70 97 95; student student = 1x5 struct array with fields:numbernamespecialtygrade 8.B=1,Brenden;reshape(1:9,3,3),12,34,2;54,21,3;4,23,67 B = 1 Brenden 3x3
6、 double 3x3 cell 4size(B) ans =2 2 ndims(B) ans =2 B(2) ans = 3x3 double B(4) ans = 3x3 cell B(3)= B = 1 3x3 double 3x3 cell B3= B = 1 3x3 double B(2) ans = 3x3 double B2 ans =1 4 72 5 83 6 9 5第三章1.(1)eye(3) ans =1 0 00 1 00 0 1 (2)A=round(rand(5,6)*100+100) A =142 146 130 155 138 192186 145 105 140
7、 101 184149 141 169 120 142 137182 190 165 163 175 162146 101 198 173 179 173 randn(1,500)*0.2+1 ones(size(A) ans =1 1 1 1 1 11 1 1 1 1 11 1 1 1 1 11 1 1 1 1 11 1 1 1 1 1 C=diag(30 30 30 30 30 30)C(1:5,:)+A a=diag(A)B=diag(a) a =1421451691636179B =142 0 0 0 00 145 0 0 00 0 169 0 00 0 0 163 00 0 0 0
8、179 2.使用函数,实现方阵左旋 90 或右旋 90 的功能A=1 4 7 10;2 5 8 11;3 6 9 12;B=rot90(A,1) B =10 11 127 8 94 5 61 2 3 C=rot90(A,3) C =3 2 16 5 49 8 712 11 10 3.A=rand(3);B=inv(A) B =-0.3872 1.2413 -0.0844-5.1444 -5.1549 9.94674.6429 3.2377 -6.7282 det(A) ans =0.0782 A*B ans =1.0000 -0.0000 0.00007-0.0000 1.0000 0.000
9、0-0.0000 -0.0000 1.0000 B*A ans =1.0000 0.0000 0.00000.0000 1.0000 -0.0000-0.0000 0.0000 1.0000 4.A=4 2 -1;3 -1 2;12 3 0;b=2 10 8;x=Ab x =-6.000026.666727.3333 或者用x=inv(A)*b x =-6.000026.666727.3333 5.A=1 -1 2 3;5 1 -4 2;3 0 5 2;11 15 0 9diag(A) A =1 -1 2 35 1 -4 23 0 5 211 15 0 9ans =1159 triu(A) 8
10、ans =1 -1 2 30 1 -4 20 0 5 20 0 0 9 tril(A) ans =1 0 0 05 1 0 03 0 5 011 15 0 9 rank(A) ans =4 norm(A) ans =21.3005 norm(A,1) ans =20 norm(A,inf) ans =35 cond(A) ans =11.1739 cond(A,1) ans =14.4531 9cond(A,inf) ans =22.0938 trace(A) ans =16 B=0.43 43 2;-8.9 4 21 B =0.4300 43.0000 2.0000-8.9000 4.000
11、0 21.0000 diag(B) ans =0.43004.0000 triu(B) ans =0.4300 43.0000 2.00000 4.0000 21.0000 tril(B) ans =0.4300 0 0-8.9000 4.0000 0 rank(B) ans =2 norm(B) ans =1043.4271 norm(B,1) ans =47 norm(B,inf) ans =45.4300 cond(B) ans =1.9354 trace(B) ans =4.4300 6.A=1 1 0.5;1 1 0.25;0.5 0.25 2 A =1.0000 1.0000 0.50001.0000 1.0000 0.25000.5000 0.2500 2.0000 V,D=eig(A) V =0.7212 0.4443 0.5315-0.6863 0.5621 0.4615-0.0937 -0.6976 0.7103D =-0.0166 0 00 1.4801 00 0 2.5365