line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::Function::Interpolator::Quadratic; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
24
|
use 5.006; |
|
2
|
|
|
|
|
4
|
|
4
|
2
|
|
|
2
|
|
5
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
33
|
|
5
|
2
|
|
|
2
|
|
6
|
use warnings FATAL => 'all'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
88
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.01'; ## VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Math::Function::Interpolator); |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
6
|
use Carp qw(confess); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
60
|
|
12
|
2
|
|
|
2
|
|
813
|
use Math::Cephes::Matrix qw(mat); |
|
2
|
|
|
|
|
11040
|
|
|
2
|
|
|
|
|
90
|
|
13
|
2
|
|
|
2
|
|
9
|
use Scalar::Util qw(looks_like_number); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
416
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Math::Function::Interpolator::Quadratic |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Math::Function::Interpolator::Quadratic; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $interpolator = Math::Function::Interpolator::Quadratic->new( |
24
|
|
|
|
|
|
|
points => {1=>2,2=>3,3=>4,4=>5,5=>6} |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$interpolator->quadratic(2.5); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Math::Function::Interpolator::Quadratic helps you to do the interpolation calculation with quadratic method. |
32
|
|
|
|
|
|
|
It solves the interpolated_y given point_x and a minimum of 3 data points. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 FIELDS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 points (REQUIRED) |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
HashRef of points for interpolations |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 METHODS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 quadratic |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
quadratic |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Returns the interpolated_y value given point_x with 3 data points |
49
|
|
|
|
|
|
|
sub quadratic { |
50
|
6
|
|
|
6
|
1
|
459
|
my ($self, $x) = @_; |
51
|
|
|
|
|
|
|
|
52
|
6
|
100
|
|
|
|
26
|
confess "sought_point[$x] must be a number" unless looks_like_number($x); |
53
|
5
|
|
|
|
|
18
|
my $ap = $self->points; |
54
|
5
|
50
|
|
|
|
28
|
return $ap->{$x} if defined $ap->{$x}; # no need to interpolate |
55
|
|
|
|
|
|
|
|
56
|
5
|
|
|
|
|
13
|
my @Xs = keys %$ap; |
57
|
5
|
100
|
|
|
|
19
|
confess "cannot interpolate with fewer than 3 data points" |
58
|
|
|
|
|
|
|
if scalar @Xs < 3; |
59
|
|
|
|
|
|
|
|
60
|
4
|
|
|
|
|
15
|
my @points = $self->closest_three_points($x, \@Xs); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Three cofficient |
63
|
4
|
|
|
|
|
7
|
my $abc = mat([map { [$_**2, $_, 1] } @points]); |
|
12
|
|
|
|
|
30
|
|
64
|
|
|
|
|
|
|
|
65
|
4
|
|
|
|
|
81
|
my $y = [map { $ap->{$_} } @points]; |
|
12
|
|
|
|
|
21
|
|
66
|
|
|
|
|
|
|
|
67
|
4
|
|
|
|
|
4
|
my $solution; |
68
|
4
|
50
|
|
|
|
6
|
eval { $solution = $abc->simq($y); 1 } |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
278
|
|
69
|
|
|
|
|
|
|
or confess 'Insoluble matrix: ' . $_; |
70
|
4
|
|
|
|
|
6
|
my ($a, $b, $c) = @$solution; |
71
|
|
|
|
|
|
|
|
72
|
4
|
|
|
|
|
45
|
return ($a * ($x**2) + $b * $x + $c); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 AUTHOR |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Binary.com, C<< >> |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 BUGS |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
82
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
83
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 SUPPORT |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
perldoc Math::Function::Interpolator |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
You can also look for information at: |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=over 4 |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
L |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
L |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item * CPAN Ratings |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
L |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * Search CPAN |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=back |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; # End of Math::Function::Interpolator::Quadratic |