line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::Function::Interpolator::Quadratic; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
33
|
use 5.006; |
|
2
|
|
|
|
|
6
|
|
4
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
58
|
|
5
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
121
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.03'; ## VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Math::Function::Interpolator); |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
13
|
use Carp qw(confess); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
88
|
|
12
|
2
|
|
|
2
|
|
881
|
use Math::Cephes::Matrix qw(mat); |
|
2
|
|
|
|
|
16095
|
|
|
2
|
|
|
|
|
138
|
|
13
|
2
|
|
|
2
|
|
16
|
use Scalar::Util qw(looks_like_number); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
491
|
|
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
|
879
|
my ($self, $x) = @_; |
51
|
|
|
|
|
|
|
|
52
|
6
|
100
|
|
|
|
43
|
confess "sought_point[$x] must be a number" unless looks_like_number($x); |
53
|
5
|
|
|
|
|
21
|
my $ap = $self->points; |
54
|
5
|
50
|
|
|
|
33
|
return $ap->{$x} if defined $ap->{$x}; # no need to interpolate |
55
|
|
|
|
|
|
|
|
56
|
5
|
|
|
|
|
25
|
my @Xs = keys %$ap; |
57
|
5
|
100
|
|
|
|
26
|
confess "cannot interpolate with fewer than 3 data points" |
58
|
|
|
|
|
|
|
if scalar @Xs < 3; |
59
|
|
|
|
|
|
|
|
60
|
4
|
|
|
|
|
22
|
my @points = $self->closest_three_points($x, \@Xs); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Three cofficient |
63
|
4
|
|
|
|
|
12
|
my $abc = mat([map { [$_**2, $_, 1] } @points]); |
|
12
|
|
|
|
|
54
|
|
64
|
|
|
|
|
|
|
|
65
|
4
|
|
|
|
|
138
|
my $y = [map { $ap->{$_} } @points]; |
|
12
|
|
|
|
|
36
|
|
66
|
|
|
|
|
|
|
|
67
|
4
|
|
|
|
|
7
|
my $solution; |
68
|
4
|
50
|
|
|
|
10
|
eval { $solution = $abc->simq($y); 1 } |
|
4
|
|
|
|
|
18
|
|
|
4
|
|
|
|
|
457
|
|
69
|
|
|
|
|
|
|
or confess 'Insoluble matrix: ' . $_; |
70
|
4
|
|
|
|
|
13
|
my ($A, $B, $C) = @$solution; |
71
|
|
|
|
|
|
|
|
72
|
4
|
|
|
|
|
59
|
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 |