Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 41 additions & 39 deletions lib/Math/Function/Interpolator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,42 @@ use Module::Pluggable
search_path => ['Math::Function::Interpolator'],
;

=head1 NAME

Math::Function::Interpolator - Interpolation made easy

=head1 VERSION

Version 0.01

=head1 SYNOPSIS

use Math::Function::Interpolator;

my $interpolator = Math::Function::Interpolator->new(
points => {1=>2,2=>3,3=>4}
);

$interpolator->linear(2.5);

$interpolator->quadratic(2.5);

$interpolator->cubic(2.5);

=head1 DESCRIPTION

Math::Function::Interpolator helps you to do the interpolation calculation with linear, quadratic and cubic methods.

=head1 FIELDS

=head2 points (REQUIRED)

HashRef of points for interpolations

=cut

our $VERSION = '0.01';

# Automatically load all interpolate methods
has 'interpolate_classes' => (
is => 'ro',
Expand All @@ -37,9 +73,10 @@ has points => (
required => 1,
);

=head1 SUBROUTINES/METHODS
=head1 METHODS

=head2 BUILDARGS

=head2 buildargs
BUILDARGS

=cut
Expand All @@ -59,45 +96,8 @@ sub BUILDARGS { ## no critic (Subroutines::RequireArgUnpacking)
return \%args;
}

=head1 NAME

Math::Function::Interpolator - Interpolation made easy

=head1 VERSION

Version 0.01

=cut

our $VERSION = '0.01';

=head1 SYNOPSIS

use Math::Function::Interpolator;

my $interpolator = Math::Function::Interpolator->new(
points => {1=>2,2=>3,3=>4}
);

$interpolator->linear(2.5);

$interpolator->quadratic(2.5);

$interpolator->cubic(2.5);

=head1 DESCRIPTION

Math::Function::Interpolator helps you to do the interpolation calculation with linear, quadratic and cubic methods.

=head1 EXPORT

=head2 linear
=head2 quadratic
=head2 cubic

=head1 SUBROUTINES/METHODS

=head2 linear
This method do the linear interpolation. It solves for point_y linearly given point_x and an array of points.

=cut
Expand All @@ -112,6 +112,7 @@ sub linear {
}

=head2 quadratic

This method do the quadratic interpolation. It solves the interpolated_y value given point_x with 3 data points.

=cut
Expand All @@ -126,6 +127,7 @@ sub quadratic {
}

=head2 cubic

This method do the cubic interpolation. It solves the interpolated_y given point_x and a minimum of 5 data points.

=cut
Expand Down
40 changes: 24 additions & 16 deletions lib/Math/Function/Interpolator/Cubic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ use List::MoreUtils qw(pairwise indexes);
use Number::Closest::XS qw(find_closest_numbers_around);
use Scalar::Util qw(looks_like_number);

=head1 NAME

Math::Function::Interpolator::Cubic

=head1 SYNOPSIS

use Math::Function::Interpolator;

my $interpolator = Math::Function::Interpolator->new(
points => {1=>2,2=>3,3=>4}
);

$interpolator->cubic(2.5);

=head1 DESCRIPTION

Math::Function::Interpolator::Cubic helps you to do the interpolation calculation with cubic method.
It solves the interpolated_y given point_x and a minimum of 5 data points.

=cut

has 'interpolate' => (
is => 'ro',
isa => sub {
Expand Down Expand Up @@ -92,9 +113,10 @@ sub _extrapolate_spline {
return $first->{y} - ( $first->{x} - $x ) * $derivative1;
}

=head1 SUBROUTINES/METHODS
=head1 METHODS

=head2 do_calculation

=head2 cubic
do_calculation

=cut
Expand Down Expand Up @@ -154,20 +176,6 @@ sub do_calculation {
return $y;
}

=head1 SYNOPSIS

use Math::Function::Interpolator;

my $interpolator = Math::Function::Interpolator->new(
points => {1=>2,2=>3,3=>4}
);

$interpolator->cubic(2.5);

=head1 DESCRIPTION

Math::Function::Interpolator::Cubic helps you to do the interpolation calculation with cubic method.
It solves the interpolated_y given point_x and a minimum of 5 data points.

=head1 AUTHOR

Expand Down
38 changes: 20 additions & 18 deletions lib/Math/Function/Interpolator/Linear.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,24 @@ use Number::Closest::XS qw(find_closest_numbers_around);
use Scalar::Util qw(looks_like_number);

=head1 NAME

Math::Function::Interpolator::Linear - Interpolation made easy

=head1 SYNOPSIS

use Math::Function::Interpolator;

my $interpolator = Math::Function::Interpolator->new(
points => {1=>2,2=>3,3=>4}
);

$interpolator->linear(2.5);

=head1 DESCRIPTION

Math::Function::Interpolator::Linear helps you to do the interpolation calculation with linear method.
It solves for point_y linearly given point_x and an array of points.

=cut

has 'interpolate' => (
Expand All @@ -24,9 +41,10 @@ has 'interpolate' => (
required => 1
);

=head1 SUBROUTINES/METHODS
=head1 METHODS

=head2 do_calculation

=head2 linear
do_calculation

=cut
Expand Down Expand Up @@ -55,22 +73,6 @@ sub do_calculation {
return $m * $x + $c;
}

=head1 SYNOPSIS

use Math::Function::Interpolator;

my $interpolator = Math::Function::Interpolator->new(
points => {1=>2,2=>3,3=>4}
);

$interpolator->linear(2.5);

=head1 DESCRIPTION

Math::Function::Interpolator::Linear helps you to do the interpolation calculation with linear method.
It solves for point_y linearly given point_x and an array of points.


=head1 AUTHOR

Binary.com, C<< <perl at binary.com> >>
Expand Down
42 changes: 22 additions & 20 deletions lib/Math/Function/Interpolator/Quadratic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,29 @@ has 'interpolate' => (
required => 1
);

=head1 SUBROUTINES/METHODS
=head1 NAME

Math::Function::Interpolator::Quadratic

=head1 SYNOPSIS

use Math::Function::Interpolator;

my $interpolator = Math::Function::Interpolator->new(
points => {1=>2,2=>3,3=>4,4=>5,5=>6}
);

$interpolator->quadratic(2.5);

=head1 DESCRIPTION

Math::Function::Interpolator::Quadratic helps you to do the interpolation calculation with quadratic method.
It solves the interpolated_y given point_x and a minimum of 5 data points.

=head1 METHODS

=head2 do_calculation

=head2 quadratic
do_calculation

=cut
Expand Down Expand Up @@ -81,21 +101,6 @@ sub _get_closest_three_points {
return @sorted;
}

=head1 SYNOPSIS

use Math::Function::Interpolator;

my $interpolator = Math::Function::Interpolator->new(
points => {1=>2,2=>3,3=>4,4=>5,5=>6}
);

$interpolator->quadratic(2.5);

=head1 DESCRIPTION

Math::Function::Interpolator::Quadratic helps you to do the interpolation calculation with quadratic method.
It solves the interpolated_y given point_x and a minimum of 5 data points.

=head1 AUTHOR

Binary.com, C<< <perl at binary.com> >>
Expand All @@ -106,9 +111,6 @@ Please report any bugs or feature requests to C<bug-math-function-interpolator a
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Math-Function-Interpolator>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.




=head1 SUPPORT

You can find documentation for this module with the perldoc command.
Expand Down