View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Daniel B. Boorstein > Math-CPWLF-0.15 > Math::CPWLF



Annotate this POD

View/Report Bugs
Module Version: 0.15   Source  


Math::CPWLF - interpolation using nested continuous piece-wise linear functions


Version 0.15


Math::CPWLF provides an interface for defining continuous piece-wise linear functions by setting knots with x,y pairs.

   use Math::CPWLF;
   $func = Math::CPWLF->new;

   $func->knot( 0 => 0 );             ## set the knot at f(0) equal to 0
   $func->knot( 1 => 2 );             ## set the knot at f(1) equal to 2
   $y = $func->( 0.5 );               ## interpolate f(0.5) ($y == 1)

Functions can be used in multiple dimensions, by specifying a Math::CPWLF object as the y value of a knot.

   $nested_func = Math::CPWLF->new;

   $nested_func->knot( 0 => 0 );
   $nested_func->knot( 1 => 3 );
   $func->knot( 2 => $nested_func );
   $deep_y = $func->( 1.5 )( 0.5 );   ## $deep_y == 1.75

As a convenience, you can specify arbitrarily deep knots by passing more than two values two the knot method.

   $func->knot( 2, 2 => 4 );          ## same as $nested_func->( 2 => 4);

If any of the intermediate knots do not exist they will be autovivified as Math::CPWLF objects, much like perl hashes.

   $func->knot( 3, 2 => 4 );          ## autovivify top level f(3)



Construct a new Math::CPWLF function with no knots, and the default out of bounds behavior.

   my $func = Math::CPWLF->new;

Optional parameters:


This instance method adds a knot with the given x,y values.

   $func->knot( $x => $y );

Knots can be specified at arbitrary depth and intermediate knots will autovivify as needed. There are two alternate syntaxes for setting deep knots. The first involves passing 3 or more values to the knot() call, where the last value is the y value and the other values are the depth-ordered x values:

   $func->knot( $x1, $x2, $x3 => $y );

The other syntax is a bit more hash-like in that it separates the x values. Note that it starts with invoking the knot() method with no arguments.

   $func->knot->($x1)($x2)( $x3 => $y );


Dan Boorstein, <dan at>


Please report any bugs or feature requests to bug-math-cpwlf at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


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

    perldoc Math::CPWLF

You can also look for information at:



Copyright 2009 Dan Boorstein.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.

syntax highlighting: