NAME
Math::Taylor  Taylor Polynomials and remainders
SYNOPSIS
use Math::Taylor;
# Create new approximation
my $approximation = Math::Taylor>new(
function => "sin(y) * cos(x)",
point => 2,
variable => 'y',
remainder_type => 'cauchy',
);
# Calculate Taylor Polynomial of degree 2
my $poly = $approximation>taylor_poly(2);
print "$poly\n";
# Upper bounds of the remainder are also availlable:
my $remainder = $approximation>remainder(2, 'cauchy');
DESCRIPTION
Math::Taylor offers facilites to calculate Taylor Polynomials of any degree symbolically. For its inner workings, it makes use of Math::Symbolic and specifically Math::Symbolic::MiscCalculus.
Math::Taylor can also calculate two types of remainders for the Taylor Series.
EXPORT
This module does not export any functions. You will have to use the objectoriented interface.
Methods
 Constructor new(OPTION => ARGUMENT)

new() is the constructor for Math::Taylor objects. It takes key => value style named arguments. Valid options are 'function', 'variable', 'point' and 'remainder_type'.
new() may be called as a class method (
Math::Taylor
new(...)> to create an object from scratch or on an existing object to clone the object. In that case, the function and variable objects are deeply cloned. (If you don't know what that means, rest assured that it's the sane behaviour.) If you use key => value pairs to set attributes, these overwrite the attributes copied from the prototype.Any Math::Taylor object requires that at least a function attribute is defined. that means, if you create objects from scratch, you have to specify a
function =
$ms_tree> attribute.Details on the attributes of the Math::Taylor objects can be learned from the documentation of the accessor methods for these attributes (below).
new() returns a Math::Taylor object.
 Accessor function()

This accessor can be used to get or set the function to approximate through the Math::Taylor object.
Called with no arguments, the method just returns the Math::Symbolic tree that internally represents the function.
Called with an argument, the first argument is treated as a new function for the approximation and the corresponding attribute is set. The function may be specified in one of two formats: Either as a Math::Symbolic tree or as a string which will be parsed as a Math::Symbolic tree. For details on the syntax of such strings, please refer to Math::Symbolic and Math::Symbolic::Parser. it should, however be relatively straighforward. A few examples:
$taylor>function('sin(x)^2/x'); # (square of the sine of x) divided by x my $func = $taylor>function(); # returns the tree for the above print $func."\n"; # print out the function $taylor>function($anotherfunc); # set the function differently
Please note that when setting the function to an existing Math::Symbolic tree, the tree is not cloned. If you modify the tree thereafter, the modifications will propagate to the function in the Math::Taylor object. This is not a bug, it is a documented feature and wanted actionatadistance.
When using function() to access the function attribute, the Math::Symbolic tree is not cloned either.
 Accessor point()

This accessor can be used to get or set the point about which to approximate using the Taylor Series. If this attribute is not set, it defaults to
0
.Called with no arguments, the method just returns the number.
Called with an argument, the first argument is treated as a point to approximate about and the corresponding attribute is set accordingly.
The method always returns the current point (which should be a real number).
 Accessor variable()

This accessor can be used to get or set the variable in respect to which the function should be approximated. If the variable attribute remains unset, it defaults to 'x'.
Called with no arguments, the method just returns the Math::Symbolic::Variable object which internally represents the variable. You can use this object in a string to interpolate as the variable name.
Called with an argument, the first argument is treated as a new variable in respect to which the function should be approximated. The variable may be specified either as a string which will be parsed as the name of a new Math::Symbolic::Variable object or as an existing Math::Symbolic::Variable.
The method always returns the current variable.
When retrieving or setting the variable as a Math::Symbolic::Variable object, the object is not cloned.
Please refer to Math::Symbolic::Variable for details.
 Accessor remainder_type()

This accessor can be used to get or set the type of remainder of the Taylor Series. If this attribute is not set, it defaults to
lagrange
.Called with no arguments, the method just returns the remainder type.
Called with an argument, the first argument is treated as a name of a remainder type to calculate. Valid values are either 'lagrange' or 'cauchy'.
For details, I have to refer you to the documentation of Math::Symbolic::MiscCalculus.
The method always returns the current remainder type.
 taylor_poly()

This method calculates the Taylor polynomial of specified degree or of degree 1 if none has been specified. The polynomial is returned as a Math::Symbolic tree.
Optional argument is the degree of the polynomial. Zeroth degree is the first element of the series. That means, it's just the function evaluated at the point of approximation.
 remainder()

This method calculates and returns the remainder of a Taylor polynomial of specified degree. If no degree (>= 0) is specified as first argument, degree 1 is assumed.
Depending on what has been set as remainder_type, the calculated remainder may be either the Lagrange Remainder or the Cauchy Remainder.
The method takes two arguments, both optional. The first is the degree as stated above. The second is the name of a new variable introduced to the remainder term. This variable is called theta in the documentation of Math::Symbolic::MiscCalculus and ranges between 0 and 1. The default name is thus theta. Be careful when you are approximation a formula containing a variable of that name.
For details, refer to the following web pages and Perl modules:
Eric W. Weisstein. "Lagrange Remainder." From MathWorld  A Wolfram Web Resource. http://mathworld.wolfram.com/LagrangeRemainder.html
Eric W. Weisstein. "Cauchy Remainder." From MathWorld  A Wolfram Web Resource. http://mathworld.wolfram.com/CauchyRemainder.html
SEE ALSO
Have a look at Math::Symbolic and in particular Math::Symbolic::MiscCalculus which implements the calculation of the Taylor Polynomial.
New versions of this module can be found on http://steffenmueller.net or CPAN.
The following web pages should explain enough about Taylor Expansions.
Eric W. Weisstein. "Taylor Series." From MathWorld  A Wolfram Web Resource. http://mathworld.wolfram.com/TaylorSeries.html
Eric W. Weisstein. "Lagrange Remainder." From MathWorld  A Wolfram Web Resource. http://mathworld.wolfram.com/LagrangeRemainder.html
Eric W. Weisstein. "Cauchy Remainder." From MathWorld  A Wolfram Web Resource. http://mathworld.wolfram.com/CauchyRemainder.html
AUTHOR
Steffen Mueller, <symbolicmodule at steffenmueller dot net>
COPYRIGHT AND LICENSE
Copyright (C) 2005 by Steffen Mueller
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.1 or, at your option, any later version of Perl 5 you may have available.