设A为
的矩阵,B为
的矩阵,那么称
的矩阵C为矩阵A与B的乘积,记作
,其中矩阵C中的第
行第
列元素可以表示为:
![](https://gss3.bdstatic.com/-Po3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D38/sign=7bfc6256307adab439d01d4b8ad4bc69/902397dda144ad34da6756f9d6a20cf430ad85f0.jpg)
![](https://gss1.bdstatic.com/9vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D34/sign=b993fb7eef24b899da3c7f3c6f068eaf/a2cc7cd98d1001e9a8aac571be0e7bec54e7973e.jpg)
![](https://gss1.bdstatic.com/-vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D38/sign=3e54c2a930d12f2eca05a8684ec228bf/0824ab18972bd407704270837d899e510eb309c2.jpg)
![](https://gss0.bdstatic.com/94o3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D52/sign=907a0f6c740e0cf3a4f74ef90a46ea25/bd315c6034a85edf8d995c5d4f540923dd5475b2.jpg)
![](https://gss1.bdstatic.com/9vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D12/sign=00bd64853fdbb6fd215be12408244fe6/4e4a20a4462309f7c1357d6c740e0cf3d7cad672.jpg)
![](https://gss3.bdstatic.com/7Po3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D17/sign=149b674c5cafa40f38c6cadaaa6459ed/d62a6059252dd42a4f5fd1d5053b5bb5c9eab87e.jpg)
![](https://gss1.bdstatic.com/9vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D334/sign=5e0cfe86de33c895a27e9e78e5137397/8ad4b31c8701a18bd6fe9b5e992f07082838fe8e.jpg)
如下所示:
![](https://gss0.bdstatic.com/94o3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D594/sign=01474d246759252da7171d0d009a032c/adaf2edda3cc7cd955ae9be73e01213fb80e9109.jpg)
![](https://img2018.cnblogs.com/blog/524071/201811/524071-20181123171923113-1730044516.png)
![](https://img2018.cnblogs.com/blog/524071/201811/524071-20181128174515640-248981200.png)
例子:
#include<iostream> using namespace std; typedef long long ll; const int N = 2; struct Matrix { ll mat[N][N]; }; Matrix operator * (Matrix a,Matrix b) { Matrix c; for (int i = 0;i < N;++i) { for (int j = 0;j < N;++j) { c.mat[i][j] = 0; for (int k = 0;k < N;++k) { c.mat[i][j] += a.mat[i][k]*b.mat[k][j]; } } } return c; }