如何在教堂中构建矩阵多项式



一位智者曾经开始,我有这个矩阵A......(此处称为"W"(

use LinearAlgebra, 
    LayoutCS,
    LinearAlgebra.Sparse;
var nv: int = 8,
    D = {1..nv, 1..nv},
    SD: sparse subdomain(D) dmapped CS(),
    W: [SD] real;
SD += (1,2); W[1,2] = 1.0;
SD += (1,3); W[1,3] = 1.0;
SD += (1,4); W[1,4] = 1.0;
SD += (2,2); W[2,2] = 1.0;
SD += (2,4); W[2,4] = 1.0;
SD += (3,4); W[3,4] = 1.0;
SD += (4,5); W[4,5] = 1.0;
SD += (5,6); W[5,6] = 1.0;
SD += (6,7); W[6,7] = 1.0;
SD += (6,8); W[6,8] = 1.0;
SD += (7,8); W[7,8] = 1.0;
const a: real = 0.5;

我想建立多项式

const P = aW + a^2W^2 + .. + a^kW^k

但是,该函数似乎.dot无法链接。 有没有明确的方法来做到这一点,即构建中间元素?

这是实现此目的的一种方法,但可以通过拆分多项式计算来改进它,以便每个矩阵幂只计算一次:

use LinearAlgebra, 
    LayoutCS,
    LinearAlgebra.Sparse;
var nv: int = 8,
    D = {1..nv, 1..nv},
    SD: sparse subdomain(D) dmapped CS(),
    W: [SD] real;
SD += (1,2); W[1,2] = 1.0;
SD += (1,3); W[1,3] = 1.0;
SD += (1,4); W[1,4] = 1.0;
SD += (2,2); W[2,2] = 1.0;
SD += (2,4); W[2,4] = 1.0;
SD += (3,4); W[3,4] = 1.0;
SD += (4,5); W[4,5] = 1.0;
SD += (5,6); W[5,6] = 1.0;
SD += (6,7); W[6,7] = 1.0;
SD += (6,8); W[6,8] = 1.0;
SD += (7,8); W[7,8] = 1.0;
const a: real = 0.5;
const polynomial = dot(a, W).plus(dot(a**2, W.dot(W))).plus(dot(a**3, W.dot(W).dot(W)));

相关内容

  • 没有找到相关文章

最新更新