在perl中对矩阵求幂

发布于 2025-01-08 12:38:23 字数 497 浏览 3 评论 0原文

我正在寻找一个使用 perl 对矩阵求幂的函数。我搜索了 CPAN 但似乎找不到合适的东西。有谁知道合适的包或简单的功能?

例如,对于以下矩阵 ($m):

$m = [[-1.85294,0.36417,1.34865,0.14012],
      [0.13385,-0.70885,0.16502,0.40998],
      [0.48588,0.16174,-0.77471,0.12709],
      [0.13424,1.06859,0.33797,-1.54081]];

e^m ~=

0.25438971 0.2029723 0.4580481 0.08458940
0.07460393 0.6061030 0.1588883 0.16040370
0.16502112 0.1557330 0.6025270 0.07671839
0.08103971 0.4180838 0.2040153 0.29685570

I'm looking for a function to exponentiate a matrix using perl. I've searched CPAN but can't seem to find anything suitable. Does anyone know of a suitable package, or easy function?

For example, for the following matrix ($m):

$m = [[-1.85294,0.36417,1.34865,0.14012],
      [0.13385,-0.70885,0.16502,0.40998],
      [0.48588,0.16174,-0.77471,0.12709],
      [0.13424,1.06859,0.33797,-1.54081]];

e^m ~=

0.25438971 0.2029723 0.4580481 0.08458940
0.07460393 0.6061030 0.1588883 0.16040370
0.16502112 0.1557330 0.6025270 0.07671839
0.08103971 0.4180838 0.2040153 0.29685570

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小巷里的女流氓 2025-01-15 12:38:23

正如 @JD 指出的,PDL 将处理这个问题。

use strict;
use warnings;

use PDL;
use PDL::LinearAlgebra::Trans;
use PDL::IO::Dumper;

my $m = pdl [[-1.85294,0.36417,1.34865,0.14012],
             [0.13385,-0.70885,0.16502,0.40998],
             [0.48588,0.16174,-0.77471,0.12709],
             [0.13424,1.06859,0.33797,-1.54081]];

my $new = mexp $m;

print sdump $new;

结果:

{my($VAR1);
my($PDL_140600590505856) = (double(0.254389714179579,0.202972289234997,0.458048094091295,0.08458940315894629,0.0746039289026906,0.606102994157082,0.158888283526803,0.160403695685552,0.165021120118487,0.155733015860466,0.602527027489139,0.07671838765811791,0.08103970821403091,0.418083774202018,0.204015347133539,0.296855703714981)->reshape(4,4));


$VAR1 = $PDL_140600590505856;

}

double() 函数内的位是结果矩阵。

PDL will handle this, as @J.D. points out.

use strict;
use warnings;

use PDL;
use PDL::LinearAlgebra::Trans;
use PDL::IO::Dumper;

my $m = pdl [[-1.85294,0.36417,1.34865,0.14012],
             [0.13385,-0.70885,0.16502,0.40998],
             [0.48588,0.16174,-0.77471,0.12709],
             [0.13424,1.06859,0.33797,-1.54081]];

my $new = mexp $m;

print sdump $new;

Result:

{my($VAR1);
my($PDL_140600590505856) = (double(0.254389714179579,0.202972289234997,0.458048094091295,0.08458940315894629,0.0746039289026906,0.606102994157082,0.158888283526803,0.160403695685552,0.165021120118487,0.155733015860466,0.602527027489139,0.07671838765811791,0.08103970821403091,0.418083774202018,0.204015347133539,0.296855703714981)->reshape(4,4));


$VAR1 = $PDL_140600590505856;

}

The bit inside the double() function is the result matrix.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文