Introduction

介绍

Strassen in 1969 which gives an overview that how we can find the multiplication of two 2*2 dimension matrix by the brute-force algorithm. But by using divide and conquer technique the overall complexity for multiplication two matrices is reduced. This happens by decreasing the total number if multiplication performed at the expenses of a slight increase in the number of addition.

Strassen在1969年概述了如何用蛮力算法找到两个2 * 2维矩阵的乘法。 但是通过使用分而治之技术,两个矩阵相乘的整体复杂度降低了。 如果以乘法数略有增加为代价执行乘法,则会通过减少总数来实现。

For multiplying the two 2*2 dimension matrices Strassen's used some formulas in which there are seven multiplication and eighteen addition, subtraction, and in brute force algorithm, there is eight multiplication and four addition. The utility of Strassen's formula is shown by its asymptotic superiority when order n of matrix reaches infinity. Let us consider two matrices A and B, n*n dimension, where n is a power of two. It can be observed that we can contain four n/2*n/2 submatrices from A, B and their product C. C is the resultant matrix of A and B.

为了将两个2 * 2维矩阵相乘, 斯特拉森使用了一些公式,其中有七个乘法和十八个加法,减法,在蛮力算法中,有八个乘法和四个加法。 Strassen公式的效用由矩阵阶数n达到无穷大时的渐近优越性表示。 让我们考虑两个矩阵ABn * n维,其中n是2的幂。 可以观察到,我们可以包含来自AB及其乘积C的四个n / 2 * n / 2个子矩阵。 CAB的合成矩阵。

Strassen矩阵乘法的过程 (Procedure of Strassen matrix multiplication)

There are some procedures:

有一些过程:

  1. Divide a matrix of order of 2*2 recursively till we get the matrix of 2*2.

    递归除以2 * 2的矩阵,直到得到2 * 2的矩阵。

  2. Use the previous set of formulas to carry out 2*2 matrix multiplication.

    使用前面的一组公式进行2 * 2矩阵乘法。

  3. In this eight multiplication and four additions, subtraction are performed.

    在这八个乘法和四个加法中,执行减法。

  4. Combine the result of two matrixes to find the final product or final matrix.

    合并两个矩阵的结果以找到最终乘积或最终矩阵。

Stassen矩阵乘法的公式 (Formulas for Stassen’s matrix multiplication)

In Strassen’s matrix multiplication there are seven multiplication and four addition, subtraction in total.

Strassen的矩阵乘法中,总共有七个乘法和四个加减法。

    1. D1 =  (a11 + a22) (b11 + b22)
2.  D2 =  (a21 + a22).b11
3.  D3 =  (b12 – b22).a11
4.  D4 =  (b21 – b11).a22
5.  D5 =  (a11 + a12).b22
6.  D6 =  (a21 – a11) . (b11 + b12)
7.  D7 =  (a12 – a22) . (b21 + b22)
C11 = d1 + d4 – d5 + d7
C12 = d3 + d5
C21 = d2 + d4
C22 = d1 + d3 – d2 – d6

Strassen矩阵乘法的算法 (Algorithm for Strassen’s matrix multiplication)

Algorithm Strassen(n, a, b, d)

算法Strassen(n,a,b,d)

begin
If n = threshold then compute
C = a * b is a conventional matrix.
Else
Partition a into four sub matrices  a11, a12, a21, a22.
Partition b into four sub matrices b11, b12, b21, b22.
Strassen ( n/2, a11 + a22, b11 + b22, d1)
Strassen ( n/2, a21 + a22, b11, d2)
Strassen ( n/2, a11, b12 – b22, d3)
Strassen ( n/2, a22, b21 – b11, d4)
Strassen ( n/2, a11 + a12, b22, d5)
Strassen (n/2, a21 – a11, b11 + b22, d6)
Strassen (n/2, a12 – a22, b21 + b22, d7)
C = d1+d4-d5+d7     d3+d5
d2+d4           d1+d3-d2-d6
end if
return (C)
end.

Strassen矩阵乘法代码 (Code for Strassen matrix multiplication)

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }
#include <stdio.h>
int main()
{int a[2][2],b[2][2],c[2][2],i,j;
int m1,m2,m3,m4,m5,m6,m7;
printf("Enter the 4 elements of first matrix: ");
for(i=0;i<2;i++)
for(j=0;j<2;j++)
scanf("%d",&a[i][j]);
printf("Enter the 4 elements of second matrix: ");
for(i=0;i<2;i++)
for(j=0;j<2;j++)
scanf("%d",&b[i][j]);
printf("\nThe first matrix is\n");
for(i=0;i<2;i++)
{printf("\n");
for(j=0;j<2;j++)
printf("%d\t",a[i][j]);
}
printf("\nThe second matrix is\n");
for(i=0;i<2;i++)
{printf("\n");
for(j=0;j<2;j++)
printf("%d\t",b[i][j]);
}
m1= (a[0][0] + a[1][1])*(b[0][0]+b[1][1]);
m2= (a[1][0]+a[1][1])*b[0][0];
m3= a[0][0]*(b[0][1]-b[1][1]);
m4= a[1][1]*(b[1][0]-b[0][0]);
m5= (a[0][0]+a[0][1])*b[1][1];
m6= (a[1][0]-a[0][0])*(b[0][0]+b[0][1]);
m7= (a[0][1]-a[1][1])*(b[1][0]+b[1][1]);
c[0][0]=m1+m4-m5+m7;
c[0][1]=m3+m5;
c[1][0]=m2+m4;
c[1][1]=m1-m2+m3+m6;
printf("\nAfter multiplication using \n");
for(i=0;i<2;i++)
{printf("\n");
for(j=0;j<2;j++)
printf("%d\t",c[i][j]);
}
return 0;
}

Output:

输出:

    Enter the 4 elements of first matrix:
5 6 1 7
Enter the 4 element of second matrix:
6 2 8 7
The first matrix  is
5       6
1       7
The second matrix is
6       2
8      7
After multiplication
78         52
62         51

Complexity: The time complexity is O(N2.8074).

复杂度:时间复杂度为O(N 2.8074 )

翻译自: https://www.includehelp.com/algorithms/strassen-matrix-multiplication.aspx

算法中的Strassen矩阵乘法相关推荐

  1. strassen矩阵乘法c语言代码,计算机算法:Strassen矩阵乘法

    简介 Strassen矩阵乘法是典型的分而治之算法.我们已经见过诸如归并排序,Karatsuba大数乘法的分而治之的算法.让我们再次领略一下分而治之的含义. 与动态编程的"分散"得 ...

  2. strassen矩阵乘法 java_Strassen 矩阵算法 Java 实现

    展开全部 算法如下: //STRASSEN矩阵算法 #include const int N=8; //常量N用来定义矩阵的大小 void main() { void STRASSEN(int n,f ...

  3. 编程实现Strassen矩阵乘法

    编程实现Strassen矩阵乘法 #include<stdio.h> int a[3][3] = {{1,2,3},{1,2,3},{1,2,3}, }; int b[3][3] = {{ ...

  4. strassen矩阵乘法 java_矩阵乘法Strassen算法

    矩阵乘法是种极其耗时的运算.以 为例,其中 和 都是 矩阵.根据矩阵乘法的定义, 中的每个元素需要按照如下方式计算 式(4.8)包含一个 次的循环,因此计算 的时间复杂度为 .而 共有 个元素,因此总 ...

  5. 分治-Strassen矩阵乘法

    A和B的乘积矩阵C中的元素C[i,j]定义为: 若依此定义来计算A和B的乘积矩阵C,则每计算C的一个元素C[i][j],需要做n次乘法和n-1次加法.因此,算出矩阵C的个元素所需的计算时间为O(n3) ...

  6. Strassen矩阵乘法(C++)

    思路 两个矩阵A,B相乘时.有以下三种方法 暴力计算法. 三个for循环, 这时候时间复杂度为O(n^3).因为Cij=∑(k=1->n)Aik*Bkj,需要一个循环, 且C中有n^2个元素, ...

  7. Strassen 矩阵乘法

    快累死了,因为计算这个计算的头晕脑胀,加减乘除严重的忘记了,总算是出来了, 矩阵乘法最原始的解决手段大家都是知道的,但是算法的时间复杂度却是O(n^3),如果采用Strassen对问题的分析,在分治的 ...

  8. C语言求任意两个矩阵相乘的算法(初学尝试矩阵乘法)

    C语言求任意两个矩阵相乘的算法(不同于大部分规格固定的矩阵乘法) 结果图如下   : 代码如下: //----- 任意两个矩阵相乘 # include <stdio.h> int main ...

  9. 关于strassen矩阵乘法的矩阵大小不是2^k的形式时,时间复杂度是否还是比朴素算法好的看法...

    原来是n,找到大于等于n且是2^k形式的数m. n*n的矩阵补全为m*m的矩阵,原来的矩阵放在最左上方,其它位置的值为0. 朴素方法:n^3 现在:m^2.8 即m/n需小于e^(3/2.8)=2.9 ...

最新文章

  1. git 提交到某分支_Git如何拉取某个分支的某段提交
  2. UVa1418 - WonderTeam(构造法)
  3. WinAPI: midiInReset - 重置输入
  4. h5支付不能打开支付宝 ios_IOS H5支付调起微信支付宝客户端问题总结
  5. 4.5 计算机网络之网络层路由选择协议(自治系统AS、RIP、OSPF、BGP)
  6. 查看Oracle数据库表空间大小(空闲、已使用),是否要增加表空间的数据文件
  7. Android 自定义 ListView 显示网络上 JSON 格式歌曲列表
  8. 长沙理工大学计算机考研难吗,长沙理工大学考研难吗?一般要什么水平才可以进入?...
  9. 《零基础》MySQL GROUP BY 语句(十九)
  10. 努比亚红魔3开启预约:鲁大师跑分破47万
  11. Python轻量级WEB框架web.py之操作数据库
  12. 【实用工具】linux Can‘t bind address: Address already in use
  13. linux暂时不能域名解析,Kali Linux中暂时不能解析域名
  14. 牛客练习赛43F Tachibana Kanade Loves Game
  15. C# 使用 NPOI操作excle文件(读取与新建重写)
  16. java 查看native方法_Java-如何查看java里的native方法?
  17. 国内外优秀呼叫中心系统简介
  18. 职称计算机 河南,2017年河南职称计算机报名入口
  19. 【金猿技术展】同盾科技知识联邦技术——3.0人工智能的坚强基石
  20. Tagged Pointer 含义的解释

热门文章

  1. 关于Ecllipse
  2. 红队技巧-域渗透的协议利用
  3. 2019广西对口计算机分数线,2019广西本科第一批投档分数线出炉,网友:我差一点考上清华大学...
  4. 真机x86 android分辨率,Android-x86入门之--启动参数设置
  5. 使用 Canvas 生成公众号头图
  6. WAP自助建站 我编程之路的启蒙
  7. 求助:安装程序无法创建一个DCOM用户帐号来注册.....\valec.exe
  8. 需加装饰——装饰模式
  9. unity json解析IPA后续
  10. 数据结构及算法 -- 目录