1、大连理工大学线性代数实验上机报告实验一首先随机生成五阶方阵 AA=rand(5)A =0.8147 0.0975 0.1576 0.1419 0.65570.9058 0.2785 0.9706 0.4218 0.03570.1270 0.5469 0.9572 0.9157 0.84910.9134 0.9575 0.4854 0.7922 0.93400.6324 0.9649 0.8003 0.9595 0.6787 B=rand(5)随机生成五阶方阵 BB =0.7577 0.7060 0.8235 0.4387 0.48980.7431 0.0318 0.6948 0.3816 0.
2、44560.3922 0.2769 0.3171 0.7655 0.64630.6555 0.0462 0.9502 0.7952 0.70940.1712 0.0971 0.0344 0.1869 0.7547 b=rand(1,5)随机生成列向量 bb =0.27600.67970.65510.16260.1190计算 A+B A+Bans =1.5725 0.8036 0.9811 0.5806 1.14551.6489 0.3103 1.6654 0.8033 0.48130.5192 0.8238 1.2743 1.6813 1.49541.5689 1.0037 1.4356 1.
3、5874 1.64340.8035 1.0620 0.8347 1.1464 1.4334计算 A-B A-Bans =0.0570 -0.6085 -0.6658 -0.2969 0.16600.1627 0.2467 0.2758 0.0402 -0.4099-0.2652 0.2700 0.6401 0.1502 0.20280.2579 0.9113 -0.4648 -0.0030 0.22460.4612 0.8678 0.7658 0.7726 -0.0760计算 A*B+B*A A*B+B*Aans =3.0288 2.3058 3.1439 2.7276 3.10342.909
4、4 2.1967 3.0040 3.0737 3.25843.3422 2.1423 3.2104 3.5734 3.90494.1446 2.9794 4.3676 4.2354 4.91703.1350 1.7787 3.2289 3.1170 3.2815求 Ax=b 的解 x=Abx =-0.98502.43963.3124-5.65151.7085验证克莱姆法则 c=A(:,1)c =0.81470.90580.12700.91340.6324 d=A(:,2)d =0.09750.27850.54690.95750.9649 e=A(:,3)e =0.15760.97060.957
5、20.48540.8003 f=A(:,4)f =0.14190.42180.91570.79220.9595 g=A(:,5)g =0.65570.03570.84910.93400.6787 B1=b;d;e;f;gB1 =0.2760 0.0975 0.1576 0.1419 0.65570.6797 0.2785 0.9706 0.4218 0.03570.6551 0.5469 0.9572 0.9157 0.84910.1626 0.9575 0.4854 0.7922 0.93400.1190 0.9649 0.8003 0.9595 0.6787 B2=c;b;e;f;gB2
6、=0.8147 0.2760 0.1576 0.1419 0.65570.9058 0.6797 0.9706 0.4218 0.03570.1270 0.6551 0.9572 0.9157 0.84910.9134 0.1626 0.4854 0.7922 0.93400.6324 0.1190 0.8003 0.9595 0.6787 B3=c;d;b;f;gB3 =0.8147 0.0975 0.2760 0.1419 0.65570.9058 0.2785 0.6797 0.4218 0.03570.1270 0.5469 0.6551 0.9157 0.84910.9134 0.9
7、575 0.1626 0.7922 0.93400.6324 0.9649 0.1190 0.9595 0.6787 B4=c;d;e;b;gB4 =0.8147 0.0975 0.1576 0.2760 0.65570.9058 0.2785 0.9706 0.6797 0.03570.1270 0.5469 0.9572 0.6551 0.84910.9134 0.9575 0.4854 0.1626 0.93400.6324 0.9649 0.8003 0.1190 0.6787 B5=c;d;e;f;bB5 =0.8147 0.0975 0.1576 0.1419 0.27600.90
8、58 0.2785 0.9706 0.4218 0.67970.1270 0.5469 0.9572 0.9157 0.65510.9134 0.9575 0.4854 0.7922 0.16260.6324 0.9649 0.8003 0.9595 0.1190 x1=det(B1)/det(A)x1 =-0.9850 x2=det(B2)/det(A)x2 =2.4396 x3=det(B3)/det(A)x3 =3.3124 x4=det(B4)/det(A)x4 =-5.6515 x5=det(B5)/det(A)x5 =1.7085计算 A 的行列式 det(A)ans =-0.02
9、50计算 B 的行列式 det(B)ans =0.0647求 A 的逆 inv(A)ans =3.1375 -0.8078 -1.8788 -4.2194 5.1680-8.6076 3.5314 2.8907 13.7204 -14.3665-6.2824 3.7220 3.6132 10.0084 -12.419013.6173 -6.8822 -6.3938 -23.5288 27.5825-2.5292 1.0729 2.4193 5.8870 -7.2671求 B 的逆 inv(B)ans =-0.4430 3.4997 1.3255 -2.6005 -0.46971.4047 -1
10、.1626 0.2422 -0.4475 -0.01190.7210 -1.8189 -2.0635 2.4434 0.0765-0.6122 -0.1837 2.0165 0.0375 -1.25640.0384 -0.5157 -0.7370 0.5267 1.7407求 A 的秩 rank(A)ans =5求 B 的秩 rank(B)ans =5求 A*B 的行列式 det(A*B)ans =-0.0016求 A*B 的逆 inv(A*B)ans =-74.0649 35.0433 31.2288 121.5740 -137.34426.8291 -1.2718 -2.2922 -8.9
11、951 8.697263.9620 -31.4202 -29.5061 -105.6918 122.3246-9.3196 5.7452 4.6259 11.9660 -15.402811.9582 -6.3521 -3.3817 -16.7574 18.6360 rank(A*B)ans =5 det(A)*det(B)ans =-0.0016验证(1 ) (A*B)ans =0.9569 1.5566 1.6237 2.2732 2.25520.6922 0.9401 0.4969 0.9371 0.80900.9461 1.6492 1.6875 2.3563 2.38000.7507
12、1.5887 1.8840 1.9421 2.14811.1399 1.5212 2.2149 2.4545 2.449711,TABBA B*Aans =0.9569 1.5566 1.6237 2.2732 2.25520.6922 0.9401 0.4969 0.9371 0.80900.9461 1.6492 1.6875 2.3563 2.38000.7507 1.5887 1.8840 1.9421 2.14811.1399 1.5212 2.2149 2.4545 2.4497(2 ) inv(B)*inv(A)ans =-74.0649 35.0433 31.2288 121.
13、5740 -137.34426.8291 -1.2718 -2.2922 -8.9951 8.697263.9620 -31.4202 -29.5061 -105.6918 122.3246-9.3196 5.7452 4.6259 11.9660 -15.402811.9582 -6.3521 -3.3817 -16.7574 18.6360(3 ) A*Bans =0.9569 0.6922 0.9461 0.7507 1.13991.5566 0.9401 1.6492 1.5887 1.52121.6237 0.4969 1.6875 1.8840 2.21492.2732 0.937
14、1 2.3563 1.9421 2.45452.2552 0.8090 2.3800 2.1481 2.4497 B*Aans =2.0719 1.6135 2.1978 1.9769 1.96351.3528 1.2566 1.3549 1.4850 1.73721.7186 1.6454 1.5229 1.6894 1.69001.8714 2.0423 2.0113 2.2932 2.46250.8797 0.9697 0.8489 0.9690 0.8317求矩阵 X 使得 AXB=C首先随机生成五阶方阵 C C=rand(5)C =0.4984 0.7513 0.9593 0.840
15、7 0.35000.9597 0.2551 0.5472 0.2543 0.19660.3404 0.5060 0.1386 0.8143 0.25110.5853 0.6991 0.1493 0.2435 0.61600.2238 0.8909 0.2575 0.9293 0.4733X=A 的逆*B 的逆 X=inv(A)*C*inv(B)X =3.8432 -13.8858 2.1418 9.4404 -4.5871-9.3312 41.9602 -7.9101 -28.4683 14.8942-7.8738 35.1218 -5.4107 -22.8861 10.158116.7545
16、 -75.6079 14.6784 49.3951 -24.7450-3.5568 17.0848 -2.9018 -11.2670 5.4559实验二1. 验证:对于一般的方阵 A,B,C,D, 首先随机生成方阵 A,B,C,DA=rand(5)ABDCCA =0.8258 0.1067 0.8687 0.4314 0.13610.5383 0.9619 0.0844 0.9106 0.86930.9961 0.0046 0.3998 0.1818 0.57970.0782 0.7749 0.2599 0.2638 0.54990.4427 0.8173 0.8001 0.1455 0.14
17、50 B=rand(5)B =0.8530 0.0760 0.4173 0.4893 0.78030.6221 0.2399 0.0497 0.3377 0.38970.3510 0.1233 0.9027 0.9001 0.24170.5132 0.1839 0.9448 0.3692 0.40390.4018 0.2400 0.4909 0.1112 0.0965 C=rand(5)C =0.1320 0.2348 0.1690 0.5470 0.18350.9421 0.3532 0.6491 0.2963 0.36850.9561 0.8212 0.7317 0.7447 0.6256
18、0.5752 0.0154 0.6477 0.1890 0.78020.0598 0.0430 0.4509 0.6868 0.0811 D=rand(5)D =0.9294 0.3063 0.6443 0.9390 0.20770.7757 0.5085 0.3786 0.8759 0.30120.4868 0.5108 0.8116 0.5502 0.47090.4359 0.8176 0.5328 0.6225 0.23050.4468 0.7948 0.3507 0.5870 0.8443 Z=A,B;C,DZ =0.8258 0.1067 0.8687 0.4314 0.13610.
19、8530 0.0760 0.4173 0.4893 0.78030.5383 0.9619 0.0844 0.9106 0.86930.6221 0.2399 0.0497 0.3377 0.38970.9961 0.0046 0.3998 0.1818 0.5797 0.3510 0.1233 0.9027 0.9001 0.24170.0782 0.7749 0.2599 0.2638 0.5499 0.5132 0.1839 0.9448 0.3692 0.40390.4427 0.8173 0.8001 0.1455 0.1450 0.4018 0.2400 0.4909 0.1112
20、 0.09650.1320 0.2348 0.1690 0.5470 0.1835 0.9294 0.3063 0.6443 0.9390 0.20770.9421 0.3532 0.6491 0.2963 0.3685 0.7757 0.5085 0.3786 0.8759 0.30120.9561 0.8212 0.7317 0.7447 0.6256 0.4868 0.5108 0.8116 0.5502 0.47090.5752 0.0154 0.6477 0.1890 0.7802 0.4359 0.8176 0.5328 0.6225 0.23050.0598 0.0430 0.4
21、509 0.6868 0.0811 0.4468 0.7948 0.3507 0.5870 0.8443求 Z 的行列式 det(Z)ans =-0.0295求 det(A)*det(D)-det(B)*det(C) det(A)*det(D)-det(B)*det(C)ans =1.8656e-004随机生成对角矩阵 A A=diag(rand rand rand rand rand)A =0.1948 0 0 0 00 0.2259 0 0 00 0 0.1707 0 00 0 0 0.2277 00 0 0 0 0.4357随机生成对角矩阵 B B=diag(rand rand rand
22、 rand rand)B =0.3111 0 0 0 00 0.9234 0 0 00 0 0.4302 0 00 0 0 0.1848 00 0 0 0 0.9049随机生成对角矩阵 C C=diag(rand rand rand rand rand)C =0.9797 0 0 0 00 0.4389 0 0 00 0 0.1111 0 00 0 0 0.2581 00 0 0 0 0.4087随机生成对角矩阵 D D=diag(rand rand rand rand rand)D =0.5949 0 0 0 00 0.2622 0 0 00 0 0.6028 0 00 0 0 0.7112
23、 00 0 0 0 0.2217 Z=A,B;C,DZ =0.1948 0 0 0 0 0.3111 0 0 0 00 0.2259 0 0 0 0 0.9234 0 0 00 0 0.1707 0 0 0 0 0.4302 0 00 0 0 0.2277 0 0 0 0 0.1848 00 0 0 0 0.4357 0 0 0 0 0.90490.9797 0 0 0 0 0.5949 0 0 0 00 0.4389 0 0 0 0 0.2622 0 0 00 0 0.1111 0 0 0 0 0.6028 0 00 0 0 0.2581 0 0 0 0 0.7112 00 0 0 0 0.
24、4087 0 0 0 0 0.2217计算 Z 的行列式 det(Z)ans =-1.1243e-004计算 det(A)*det(D)-det(B)*det(C) det(A)*det(D)-det(B)*det(C)ans =-9.3107e-005计算 A*D-B*C 的行列式 det(A*D-B*C)ans =-1.1243e-004实验三求 A 列向量组的一个最大无关组,并把不属于 极大无关组的向量利用极大无关组表示.N= 200865083;a=83;b=86;c=50;d=88;e=28;f=63;g=83;h=60; A=a,b,c,d,3,4;1,2,3,4,4,3;12,1
25、5,22,17,5,7;e,f,g,h,8,0; B=rref(A)B =1.0000 0 0 0 -0.3548 0.46560 1.0000 0 0 -1.4905 -2.00200 0 1.0000 0 0.0473 0.39500 0 0 1.0000 1.7984 1.3383所以 a1,a2,a3,a4 是一个极大无关组。a5=-0,3548a1-1.4905a2+0.0473a3+1.7984a4;a6=0.4656a1-2.0020a2+0.3950a3+1.3383a4.实验四 a=83; b=86; c=50; d=88; e=28; f=63; g=83; h=60; b
26、1=1,1.9,f,c; b2=1,1.8,f,c; A1=a,b,c,d;0.5,1,1.5,2;12,15,22,17;e,f,g,h; A2=a,b,c,d;0.3,0.6,0.9,1.2;12,15,22,17;e,f,g,h; A3=a,b,c,d;0.1,0.2,0.3,0.4;12,15,22,17;e,f,g,h; A4=a,b,c,d;0.05,0.1,0.15,0.2;12,15,22,17;e,f,g,h; x1=A1/b1x1 =1.20430.03040.35171.2940 x2=A2/b1x2 =1.20430.01820.35171.2940 x3=A3/b1x
27、3 =1.20430.00610.35171.2940 x4=A4/b1x4 =1.20430.00300.35171.2940 x5=A2/b1x5 =1.20430.01820.35171.2940 x6=A2/b2x6 =1.20310.01820.35141.2931 x5=A1/b2x5 =1.20310.03040.35141.2931 x6=A2/b2x6 =1.20310.01820.35141.2931 x7=A3/b2x7 =1.20310.00610.35141.2931 x8=A4/b2x8 =1.20310.00300.35141.2931实验五随机生成 4 个 5 维向量,并进行正交化随机生成 4 个 5 维向量a=rand(4,5); aa =0.1174 0.5079 0.0292 0.5785 0.54680.2967 0.0855 0.9289 0.2373 0.52110.3188 0.2625 0.7303 0.4588 0.23160.4242 0.8010 0.4886 0.9631 0.4889正交化 b=null(a)b =0.6777-0.5941-0.30090.2892