Math::Calculus::TaylorSeries - Decomposition of an expression into its Taylor Series
use Math::Calculus::TaylorSeries; # Create an object. my $exp = Math::Calculus::TaylorSeries->new; # Set a variable and expression. $exp->addVariable('x'); $exp->setExpression('sin(x)') or die $exp->getError; # Get expression object for first 4 terms about x = 0. my $result = $exp->taylorSeries('x', 4, 0) or die $exp->getError; print $result->getExpression; # Prints x - x^3/6 + x^5/120 - x^7/5040
This module can take an algebraic expression, parses it and then decomposes it into a Taylor series, returning a new expression containing the first N elements.
It understands expressions containing any of the operators +, -, *, / and ^ (raise to power), bracketed expressions to enable correct precedence and the functions ln, exp, sin, cos, tan, sec, cosec, cot, sinh, cosh, tanh, sech, cosech, coth, asin, acos, atan, asinh, acosh and atanh.
None by default.
$exp = Math::Calculus::TaylorSeries->new;
Creates a new instance of the Taylor Series object, which can hold an individual expression.
Sets a certain named value in the expression as being a variable. A named value must be an alphabetic chracter.
$exp->setExpression('x^2 + 5*x);
Takes an expression in human-readable form and stores it internally as a tree structure, checking it is a valid expression that the module can understand in the process. Note that the engine is strict about syntax. For example, note above that you must write 5*x and not just 5x. Whitespace is allowed in the expression, but does not have any effect on precedence. If you require control of precedence, use brackets; bracketed expressions will always be evaluated first, as you would normally expect. The module follows the BODMAS precedence convention. Returns undef on failure and a true value on success.
$expr = $exp->getExpression;
Returns a textaul, human readable representation of the expression that is being stored.
$result = $exp->taylorSeries($variable, $terms, $about);
Finds the first $terms non-zero terms of the Taylor series of the expression object for the variable $variable evaluated about the value $about and returns a new expression object that represents it.
$result = $exp->taylorSeries($variable, $numcoeffs, $about);
Returns an array containing the first $numcoeffs terms when the Taylor series for the variable $variable is found about $about.
When setExpression and taylorSeries are called, a traceback is generated to describe what these functions did. If an error occurs, this traceback can be extremely useful in helping track down the source of the error.
When any method other than getTraceback is called, the error message stored is cleared, and then any errors that occur during the execution of the method are stored. If failure occurs, call this method to get a textual representation of the error.
The author of this module has a website at http://www.jwcs.net/~jonathan/, which has the latest news about the module and a web-based frontend to allow you to test the module out for yourself.
Jonathan Worthington, <email@example.com>
Copyright (C) 2004 by Jonathan Worthington
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.1 or, at your option, any later version of Perl 5 you may have available.