Series
A series is a mathematical concept that represents the sum of terms, often used to approximate functions as polynomials. In the context of programming and computational mathematics, series are particularly useful for function approximation. Two specific types of power series commonly used for this purpose are the Maclaurin series and the Taylor series.
Maclaurin Series
The Maclaurin series is a special case of the Taylor series. It approximates a function by a polynomial using derivatives evaluated at zero. This makes it particularly useful for functions that are well-behaved around the origin. The Maclaurin series is essentially a Taylor series centered at zero.
Taylor Series
The Taylor series is a more general form of the Maclaurin series. It represents a function as an infinite sum of terms, calculated from the values of its derivatives at a single point. This allows for function approximation around any point, not just zero. The Taylor series is a powerful tool for approximating functions that may not be easily computed otherwise.
Practical Use of Series in Programming
In practice, turning a Taylor series into a Maclaurin series or computing polynomial approximations manually is not necessary. Libraries like SymPy provide functions to compute a finite number of polynomial terms for you, starting at any given point. This allows you to balance between computational cost and accuracy with a single parameter.
Example: Exponential Function
Using SymPy, you can approximate the exponential function ( e^x ) with a polynomial:
>>> series(E**x, x, x0 = 0, n = 6)
1 + x + x**2/2 + x**3/6 + x**4/24 + x**5/120 + O(x**6)
In this example, the series function computes the polynomial approximation up to the 5th degree, even though we specified ( n = 6 ).
Example: Natural Logarithm
If derivatives cannot be taken at zero, you can change the expansion point ( x_0 ). For instance, for the natural logarithm function:
>>> series(ln(x), x, x0 = 1, n = 5)
-1 - (x - 1)**2/2 + (x - 1)**3/3 - (x - 1)**4/4 + x + O((x - 1)**5, (x, 1))
Example: Sine Function
For functions like sine, which are odd functions, the polynomial series contains only odd terms. To get a specific number of terms, you may need to specify a higher degree:
>>> series(sin(x), x, x0 = 0, n = 10)
x - x**3/6 + x**5/120 - x**7/5040 + x**9/362880 + O(x**10)
Applications in Optimization
Approximating trigonometric functions with polynomials was a common optimization technique in game development a few decades ago. While modern processors are efficient at computing trigonometric functions, using power series for optimization can still be beneficial when approximating more complex functions. However, performance benefits are typically realized only when a considerable error is acceptable in the model.
FAQ (Frequently asked questions)
What is a series in mathematics?
What are Maclaurin and Taylor series used for?
What is the Maclaurin series?
What is the Taylor series?
How does the Taylor series generalize the Maclaurin series?