1. 请创建一个3*3矩阵和4*4矩阵,判断能否相加减,能否相减。
A= rand(3,3);
B= rand(4,4);
A+B; % 不能 错误使用+ 矩阵维度必须一致
A - B;%
不能 错误使用- 矩阵维度必须一致
2
. 设A和B是两个同阶方阵判断能否相加减,能否相乘。
>> A= rand(3,3);
B= rand(3,3);
C=A+B;
D= A-B;
E = A*B;
C,D,E %可以相加减,也可以相乘
C =
0.8549 0.9726 0.4706
1.5666 1.1214 0.6585
1.0871 0.7405 0.8117
1.5666 1.1214 0.6585
1.0871 0.7405 0.8117
D =
0.6606 0.3384 -0.4069
-0.0803 -0.7790 -0.1046
-0.3026 0.6716 -0.7193
-0.0803 -0.7790 -0.1046
-0.3026 0.6716 -0.7193
E =
0.6355 0.8642 0.6069
0.4056 0.4079 0.6034
0.6516 0.7969 0.4768
0.4056 0.4079 0.6034
0.6516 0.7969 0.4768
3 若1中的矩阵不能进行运算,试改变矩阵的维数,使其能够相加减或相乘。并计算结果
%当A 和B 同列同行时可以相加减也可以相乘,相乘需要前面矩阵的列数和后面矩阵的行数一致
%即 我可以将A 和B 转变成同为(3*3)或者同为(4*4)的矩阵这样可以相加减与乘,只需要相乘的话
%我可以将B矩阵的的行数调成3 或者将A矩阵的列数调整成4
>> A = rand(3,3);
>> B = rand(4,4);
%用矩阵编辑器将A 修改为(4*4)或者将B修改为(3*3)可以相乘相加减
![](https://i-blog.csdnimg.cn/blog_migrate/7dd09c418a13c11a530040e845d204b0.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a6e9eb3786f8bc6f346ce8a3ffd2a920.png)
>> C = A+B;
>> D = A-B;
>> E =A*B;
>> C,D,E
>> D = A-B;
>> E =A*B;
>> C,D,E
C =
0.9102 1.4577 0.8428 1.2435
0.6686 1.5070 1.0645 0.9293
0.8181 0.4790 1.0055 0.3500
2.0000 0 0 0
0.6686 1.5070 1.0645 0.9293
0.8181 0.4790 1.0055 0.3500
2.0000 0 0 0
D =
0.4000 -0.4609 0.3278 0.7565
-0.3433 0.4125 -0.6169 -0.9293
-0.5801 0.2018 0.4970 -0.3500
0 0 0 0
-0.3433 0.4125 -0.6169 -0.9293
-0.5801 0.2018 0.4970 -0.3500
0 0 0 0
E =
1.8284 0.9823 0.7365 0.8275
0.6835 0.7122 0.9057 1.0098
0.7278 0.4046 0.5078 0.6082
0.2551 0.9593 0.2575 0.2435
0.6835 0.7122 0.9057 1.0098
0.7278 0.4046 0.5078 0.6082
0.2551 0.9593 0.2575 0.2435
![](https://i-blog.csdnimg.cn/blog_migrate/06d7476364706be73e68145eb13330fd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1651642238e84f078cfb1205966f24a2.png)
C = A+B;
D = A-B;
E =A*B;
C,D,E
D = A-B;
E =A*B;
C,D,E
C =
0.9102 1.4577 0.8428
0.6686 1.5070 1.0645
0.8181 0.4790 1.0055
0.6686 1.5070 1.0645
0.8181 0.4790 1.0055
D =
0.4000 -0.4609 0.3278
-0.3433 0.4125 -0.6169
-0.5801 0.2018 0.4970
-0.3433 0.4125 -0.6169
-0.5801 0.2018 0.4970
E =
0.8284 0.9823 0.7365
0.6835 0.7122 0.9057
0.7278 0.4046 0.5078
0.6835 0.7122 0.9057
0.7278 0.4046 0.5078
%用矩阵编辑器将A修改为(3*4)或者将B修改为(3*4)可以相乘
![](https://i-blog.csdnimg.cn/blog_migrate/ea650ce9391b13f81869679c0696ec0c.png)
![](https://i-blog.csdnimg.cn/blog_migrate/e62e292edfb64b46afd41abe83374ceb.png)
4
. A=rand(3),B=magic(3),C=rand(3,4),计算:A*B*C
A = rand(3);
B = magic(3);
C = rand(3,4);
A*B*C
ans =
11.1563 3.7893 12.9471 7.0196
22.5310 7.8971 26.6327 14.1754
12.4201 4.6542 15.2147 7.7899
22.5310 7.8971 26.6327 14.1754
12.4201 4.6542 15.2147 7.7899
5 A=[1,2,3]计算A'与A的积,A*B与B*A是否相等?
A = [1 2 3];
C = A'*A;
D = A*A';
C = A'*A;
D = A*A';
C,D %很明显 CD不相等
![](https://i-blog.csdnimg.cn/blog_migrate/dfd8398ae1a10cf69811adf093e950c5.png)