perl - PDL::Slatec::chcm 示例/用法

标签 perl

我有包含 x 和 y 的数据点列表,如下所示。我需要确定 Perl 中的单调性(由于遗留问题,因为我没有太多关于 Perl 的信息)。我搜索并发现以下网址包含此类信息,但没有提供任何示例。任何例子都会对我有很大帮助。

http://pdl.perl.org/?docs=Slatec&title=PDL::Slatec#chcm

1.00000000000001e-08 4.9281e-02
2.00000000000001e-08 4.9280e-02
3.00000000000001e-08 4.2290e-01
4e-08 4.3381e-01
5.00000000000001e-08 4.3801e-01
6.00000000000001e-08 4.3965e-01
7.00000000000001e-08 4.4004e-01
8.00000000000001e-08 4.4020e-01
9e-08 4.4025e-01
1e-07 4.4026e-01
1.1e-07 5.1206e-02
1.2e-07 4.9925e-02
1.3e-07 4.9480e-02
1.4e-07 4.9326e-02
1.5e-07 4.9295e-02
1.6e-07 4.9284e-02
1.7e-07 4.9280e-02
1.8e-07 4.9279e-02
1.9e-07 4.2288e-01
2e-07 4.3380e-01
2.1e-07 4.3801e-01
2.2e-07 4.3965e-01
2.3e-07 4.4023e-01
2.4e-07 4.4036e-01
2.5e-07 4.4035e-01
2.6e-07 4.4032e-01
2.7e-07 5.1209e-02
2.8e-07 4.9924e-02
2.9e-07 4.9475e-02
3e-07 4.9334e-02
3.1e-07 4.9294e-02
3.2e-07 4.9283e-02
3.3e-07 4.9280e-02
3.4e-07 4.9280e-02
3.5e-07 4.2289e-01
3.6e-07 4.3381e-01
3.7e-07 4.3801e-01
3.8e-07 4.3965e-01
3.9e-07 4.4023e-01
4e-07 4.4036e-01
4.1e-07 4.4035e-01
4.2e-07 4.4032e-01
4.3e-07 5.1209e-02
4.4e-07 4.9925e-02
4.5e-07 4.9478e-02
4.6e-07 4.9332e-02
4.7e-07 4.9295e-02
4.8e-07 4.9282e-02
4.9e-07 4.9279e-02
5e-07 4.9278e-02
5.1e-07 4.2289e-01
5.2e-07 4.3381e-01
5.3e-07 4.3801e-01
5.4e-07 4.3965e-01
5.5e-07 4.4023e-01
5.6e-07 4.4036e-01
5.7e-07 4.4035e-01
5.8e-07 4.4032e-01
5.9e-07 5.1209e-02
6e-07 4.9924e-02
6.1e-07 4.9474e-02
6.2e-07 4.9334e-02
6.3e-07 4.9294e-02
6.4e-07 4.9283e-02
6.5e-07 4.9280e-02
6.6e-07 4.9280e-02
6.7e-07 4.2287e-01
6.8e-07 4.3380e-01
6.9e-07 4.3801e-01
7e-07 4.3961e-01
7.1e-07 4.4004e-01
7.2e-07 4.4021e-01
7.3e-07 4.4027e-01
7.4e-07 4.4028e-01
7.5e-07 5.1207e-02
7.6e-07 4.9925e-02
7.7e-07 4.9481e-02
7.8e-07 4.9323e-02
7.9e-07 4.9294e-02
8e-07 4.9284e-02
8.1e-07 4.9281e-02
8.2e-07 4.9280e-02
8.3e-07 4.2289e-01
8.4e-07 4.3381e-01
8.5e-07 4.3801e-01
8.6e-07 4.3966e-01
8.7e-07 4.4023e-01
8.8e-07 4.4036e-01
8.9e-07 4.4035e-01
9e-07 4.4032e-01
9.1e-07 5.1208e-02
9.2e-07 4.9926e-02
9.3e-07 4.9481e-02
9.4e-07 4.9323e-02
9.5e-07 4.9294e-02
9.6e-07 4.9284e-02
9.7e-07 4.9281e-02
9.8e-07 4.9280e-02
9.9e-07 4.2288e-01

最佳答案

以下是如何使用 chim 的示例和 chcm检查分段三次 Hermite 函数的单调性:

use feature qw(say);
use strict;
use warnings;
use PDL;
use PDL::Slatec;

{
    my $x   = float( 1, 2, 3, 5, 6, 7 );
    my $f   = float( 1, 2, 3, 4, 5 ,6 );
    check_monotonicity($x, $f);
}
{
    my $x   = float( 1, 2, 3, 5, 6, 7 );
    my $f   = float( 6, 5, 4, 3, 2 ,1 );
    check_monotonicity($x, $f);
}

{
    my $x   = float( 1, 2, 3, 5, 6, 7 );
    my $f   = float( 6, 5, 4, 4, 5 ,6 );
    check_monotonicity($x, $f);
}

sub check_monotonicity {
    my ( $x, $f ) = @_;

    my ( $deriv, $err ) = chim($x, $f);
    if ( $err < 0 ) {
        say "Could not calculate derivative";
    }
    else {
        say "Derivative: ", $deriv;
        my $check = 1;
        my ( $ismon, $err ) = chcm($x, $f, $deriv, $check);
        if ( $err == -1 ) {
            say "Error: too few points..";
        }
        elsif ( $err == -3 ) {
            say "Error: x is not strictly increasing";
        }
        else {
            say "Monotonicity: ", $ismon;
        }
    }
}

输出:

Derivative: [1 1 0.692308 0.692308 1 1]
Monotonicity: [1 1 1 1 1 1]
Derivative: [-1 -1 -0.692308 -0.692308 -1 -1]
Monotonicity: [-1 -1 -1 -1 -1 -1]
Derivative: [-1 -1 0 0 1 1]
Monotonicity: [-1 -1 0 1 1 2]

关于perl - PDL::Slatec::chcm 示例/用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64260202/

相关文章:

perl - 为什么我不应该使用UNIVERSAL::isa?

Perl 数据包制作和注入(inject)模块

c++ - 如何在不使用 perl/awk/etc 更改 'long' 的情况下将 'int' 更改为 'long long'

perl 拆分有趣的行为

perl - 在网站上解析和显示 MIME 多部分电子邮件

perl - 在运行时使 Perl 打印?

arrays - 在 perl 中使用 <$socket[i]> 读取数组中的套接字

perl - 这条线到底是做什么的,它是如何做到的?打开我的 $fh_echo, '-|' 或 exec "$sshstr\"$str\""

perl - 如何在 Perl 中对 IP 地址列表进行排序?

perl - 如何制作从 A 到 Z 的字母列表并在 shell 中迭代它们?