- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道计算 Ax=B 等线性代数的最短代码(ACM 等竞赛所需)是什么。这是我用高斯规则计算 Ax=B 的 java 代码:
public static void linearAlgebra(double[][] a , double[] b , double[] x , int n)
{
for(int j = 0 ; j<n ; j++)
{
for(int i = 0 ; i<n ; i++)
{
if(j<i)//lower triangle of A matrix
{
double factor = 1 ;
int k=i-1;
while(k>=0)//find the Gaussian factor from the upper rows of the current row
{
if(k==i)continue;
if(a[k][j]!=0)//if the upper rows same column is not zero
{
factor = (double)(-a[i][j])/a[k][j];
break;
}//if
k--;
}//while checking the upper rows of the current row to find the Gaussian factor
for(int m = 0 ; m<n ; m++)
{
a[i][m] += factor*a[k][m];// Gaussian factor
}//for
b[i] += factor*b[k];//do the same thing that we did with A to B
}//if j<i
}//i
}//j
for(int i=n-1 ; i>=0 ;i--)
{
//for example if we have 2*x2 + 3*x3 = b2 we already found x3 the rest is history :)
double sum = 0 ;
for(int j = i+1 ; j<n ; j++)
{
sum += a[i][j]*x[j];
}//j
x[i] = (b[i]-sum)/a[i][i];//calculate x_i --> for example the first loop will find x_n
}//i
//output the linear Algebra
System.out.print("A's matrix after Gaussian:");
System.out.println();
for(int row = 0 ; row<n ; row++)
{
for(int col = 0 ; col<n ; col++)
{
System.out.print(a[row][col]+ " ");
}
System.out.println();
}//i
System.out.println();
System.out.print("B's matrix after Gaussian:");
for(int col = 0 ; col<n ; col++)
{
System.out.println(b[col]);
}//for
System.out.println();
System.out.print("x's vector is:");
for(int col = 0 ; col<n ; col++)
{
System.out.println(x[col]);
}//for
}//linearAlgebra method
如果您需要快速编码,是否有更快的规则,或者高斯规则是最好的编码规则?顺便说一下,这段代码可以帮助那些需要用java计算线性代数的人。该代码已经过测试,但如果有任何错误,请告诉我。
最佳答案
可以证明,使用 blockwise inversion 的分而治之算法反转 矩阵的运行时间复杂度与内部使用的矩阵乘法算法相同。
因此,如果您实现 Coppersmith–Winograd algorithm对于矩阵乘法,您可以实现的时间复杂度为 或even better .
关于java - 计算和编码线性代数(例如 Ax=B)的最短方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48471230/
我开始测试 Haskell 的线性代数。有没有人为此目的提供最佳包装的建议?使用 Haskell 进行基本矩阵操作的任何其他好的资源? Haskell 维基 lists several resourc
教程名称:使用 C# 入门深度学习 作者:痴者工良 地址: https://torch.whuanle.cn 线性代数 目录 线性代数
对于给定的向量,我想找到它周围的正交基, 即给定向量归一化和随机选择的正交子空间的基础。 在 Julia 中有一个方便的功能吗? 最佳答案 您正在寻找的函数名为 nullspace . julia>
我想计算 Julia 1.0 中的经典伴随 为此,我复制了 wikipedia 中作为示例给出的矩阵 julia> B = [-3 2 -5; -1 0 -2; 3 -4 1] 3×3 Array{I
我最近开始阅读 OpenGL Superbible 第 5 版,并注意到以下内容: 刚刚学习了线性代数,这对我来说似乎很奇怪。列向量的尺寸为 4x1,矩阵的尺寸为 4x4,如何将它们相乘?如果向量是行
我正在尝试修改我的线性代数模块以避免虚拟 vtable 的东西.. 尝试使用 CRTP 和表达式模板。我选择了一些基本的东西来测试整个事情,但我无法让它工作。 我有 4 个类,比如:基 CRTP 类,
我对 C++ 和 OpenCV 很陌生,但对 Matlab 比较熟悉。我有一项任务需要转移到 C++ 以加快处理速度。所以我想就图像处理问题征求您的建议。我在一个文件夹中有 10 张图片,我可以使用
我有一个数组 w (shape (3000, 100, 100)) 我想将它与另一个数组 e (shape (5, 3000)) 使得结果 k 的形状为 (5, 5, 100, 100) 和 k[:,
Tally-ho 小伙子们, 这个问题认为线性代数的艺术是数学中我无法解决的地方。所以我希望你们能帮助我 :D。 我正在尝试为一款名为《骑马与砍杀》的游戏创建单人自动踢球作弊。这个 autokicke
我是一名优秀的程序员,十分优秀!