Extreme Optimization > User's Guide > Mathematics Library > Curves > Chebyshev Approximations

Extreme Optimization User's Guide

User's Guide

Up: Curves Next: Piecewise Curves and Cubic Splines Previous: Polynomials Contents

Chebyshev Expansions

Chebyshev polynomials form a special class of polynomials whose properties make them especially suited for approximating other functions. As such, they form an essential part of any numerical library. The Extreme Optimization Mathematics Library for .NET supports Chebyshev approximations through the ChebyshevSeries class.

The ChebyshevSeries class

A Chebyshev expansion is a linear combination of Chebyshev polynomials. The Chebyshev polynomials are never formed explicitly. All calculations can be performed using only the coefficients.

The Chebyshev polynomials provide an alternate basis for representating general polynomials. Two characteristics make Chebyshev polynomials especially attractive. They are mutually orthogonal, and there exists a simple recurrence relation between consecutive polynomials.

Chebyshev polynomials are defined over the interval [-1, 1]. Using Chebyshev expansions outside of this interval is usually not meaningful and is to be avoided. To allow expansions over any finite interval, transformations are applied wherever necessary.

The ChebyshevSeries class inherits from PolynomialBase This class defines a number of properties shared by all polynomial classes. The PolynomialBase is itself derived from LinearCombination.

The parameters of a Chebyshev expansion are the coefficients of the polynomial.

The Degree of a Chebyshev expansion is the highest degree of a Chebyshev polynomial that appears in the sum. The number of parameters of the expansion equals the degree plus one.

Constructing Chebyshev Expansions

The The ChebyshevSeries has four constructors. The first two variants let you specify the degree of the highest order Chebyshev polynomial in the expansion. You can also specify the lower and upper bound of the interval. If the lower and upper bound are omitted, the standard interval [-1,1] is assumed:

C# CopyCode imageCopy Code
// Chebyshev expansion of degree 5:
ChebyshevSeries c1 = new ChebyshevSeries(5);
// Chebyshev expansion of degree 5 over the interval [0,2]:
ChebyshevSeries c2 = new ChebyshevSeries(5, 0.0, 2.0);
Visual Basic CopyCode imageCopy Code
' Chebyshev expansion of degree 5:
Dim c1 As ChebyshevSeries = New ChebyshevSeries(5)
' Chebyshev expansion of degree 5 over the interval [0,2]:
Dim c2 As ChebyshevSeries = New ChebyshevSeries(5, 0.0, 2.0)

The third and fourth variants let you specify the coefficients of the expansion, and optionally the lower and upper bound of the interval. The kth element of the coefficient array should be the coefficient of the Chebyshev polynomial of degree k.

C# CopyCode imageCopy Code
Double [] coefficients = new Double[] {1, 0.5, 0.25, 0.125, 0.0625};
// Chebyshev expansion of degree 4 with the above coefficients:
ChebyshevSeries c3 = new ChebyshevSeries(coefficients);
// Chebyshev expansion of degree 4 over the interval [0, 2]:
ChebyshevSeries c4 = new ChebyshevSeries(coefficients, 0.0, 2.0);
Visual Basic CopyCode imageCopy Code
Dim coefficients As Double() = New Double() {1, 0.5, 0.25, 0.125, 0.0625}
' Chebyshev expansion of degree 4 with the above coefficients:
Dim c3 As ChebyshevSeries = New ChebyshevSeries(coefficients)
' Chebyshev expansion of degree 4 over the interval [0, 2]:
Dim c4 As ChebyshevSeries = New ChebyshevSeries(coefficients, 0.0, 2.0)

In addition, you can also create a Chebyshev expansion using one of several static methods.

The LeastSquaresFit method constructs a The ChebyshevSeries that is the least squares fit of a specified degree through a given set of points. If the boundaries of the approximation interval are not specified, the smallest and highest x-coordinates are used as the lower and upper bound. The result is mathematically equivalent to the polynomial obtained from the LeastSquaresFit method of the The Polynomial class. The calculation is much more stable, however, leading to good accuracy even for high degree approximations.

The GetInterpolatingPolynomial function takes a RealFunction delegate as its first parameter. The second parameter is an integer indicating the degree of the polynomial. This method calculates the interpolating polynomial (in the form of a Chebyshev expansion) through the so-called Chebyshev points . This technique ensures that the approximation deviates as little as possible from the actual function.

The following examples illustrate these methods. We will approximate the function sin(x) over the interval [-pi/2,pi/2] in two ways. First, we will find a least squares fit through 7 points on this curve. We will then calculate the Chebyshev interpolating polynomial of degree 4.

C# CopyCode imageCopy Code
// x and y values contain the data points:
double[] xValues = new double[13];
double[] yValues = new double[13];
int index;
for(index = 0; index < 13; index++)
{
  xValues[index] = (index-6) * Constants.Pi / 12;
  yValues[index] = Math.Sin(xValues[index]);
}
// Now we can find the least squares approximation:
ChebyshevSeries lsqApproximation = 
    ChebyshevSeries.LeastSquaresFit(xValues, yValues,
        -Constants.Pi/2, Constants.Pi/2, 4);
// Note that, as expected, the odd coefficients are close to zero.
Console.WriteLine("Least squares fit:");
for(index = 0; index <= 4; index++)
    Console.WriteLine("c({0}) = {0}", 
        index, lsqApproximation[index]);
// Now let's calculate the interpolating Chebyshev expansion:
RealFunction f = new RealFunction(Math.Sin);
ChebyshevSeries interpolant = 
    ChebyshevSeries.GetInterpolatingPolynomial(f, 
        -Constants.Pi/2, Constants.Pi/2, 4);
// This expansion is close to the previous one:
Console.WriteLine("Interpolating polynomial:");
for(index = 0; index <= 4; index++)
    Console.WriteLine("c({0}) = {0}", 
        index, interpolant[index]);
Visual Basic CopyCode imageCopy Code
' x and y values contain the data points:
Dim xValues As Double() = New Double(13)
Dim yValues As Double() = New Double(13)
Dim index As Integer
For index = 0 To 12
  xValues(index) = (index-6) * Constants.Pi / 12
  yValues(index) = Math.Sin(xValues(index))
Next
' Now we can find the least squares approximation:
Dim lsqApproximation As ChebyshevSeries = _
    ChebyshevSeries.LeastSquaresFit(xValues, yValues, _
        -Constants.Pi/2, Constants.Pi/2, 4)
' Note that, as expected, the odd coefficients are close to zero.
Console.WriteLine("Least squares fit:")
For index = 0 To 4
    Console.WriteLine("c({0}) = {0}", _
        index, lsqApproximation.Coefficients(index))
Next
' Now let's calculate the interpolating Chebyshev expansion:
Dim f As RealFunction = New RealFunction(AddressOf Math.Sin)
Dim interpolant As ChebyshevSeries = _
    ChebyshevSeries.GetInterpolatingPolynomial(f, _
        -Constants.Pi/2, Constants.Pi/2, 4)
' This expansion is close to the previous one:
Console.WriteLine("Interpolating polynomial:")
For index = 0 To 4
    Console.WriteLine("c({0}) = {0}", _
        index, interpolant.Coefficients(index))
Next

Note that, even though the interpolating polynomial was calculated using only a third of the data, the resulting approximation is still very close to the least squares solution.

Working with Chebyshev expansions

The ChebyshevSeries class implements all methods and properties of the Curve class.

The ValueAt method returns the value of the polynomial at a specified point. SlopeAt returns the derivative. For expansions over an interval different from the standard [-1,1], appropriate transformations are applied automatically.

C# CopyCode imageCopy Code
Console.WriteLine("p1.ValueAt(2) = {0}", c1.ValueAt(2));
Console.WriteLine("p1.SlopeAt(2) = {0}", c1.SlopeAt(2));
Visual Basic CopyCode imageCopy Code
Console.WriteLine("p1.ValueAt(2) = {0}", c1.ValueAt(2))
Console.WriteLine("p1.SlopeAt(2) = {0}", c1.SlopeAt(2))

The GetDerivative method returns the Chebyshev expansion that is the derivative of a Chebyshev expansion.

C# CopyCode imageCopy Code
Curve derivative = c1.GetDerivative();
Console.WriteLine("Slope at 2 (derivative) = {0}",
    derivative.ValueAt(2));
Visual Basic CopyCode imageCopy Code
Dim derivative As Curve = c1.GetDerivative()
Console.WriteLine("Slope at 2 (derivative) = {0}", _
    derivative.ValueAt(2))

Integral evaluates the definite integral over a specified interval. This value is calculated directly using the coefficients of the expansion. No numerical approximation is used.

Up: Curves Next: Piecewise Curves and Cubic Splines Previous: Polynomials Contents

Overview
Introduction
Features
Documentation
QuickStart Samples
Sample Applications
Downloads
Get it now!
Download trial version
How to Buy
Information
Resources
Contact Us
Search

"The Extreme Optimization Statistics Library for .NET is a major boon for those doing statistical work in .NET. I strongly recommend this product."
- Marc Brooks

"I have made it my mission to institutionalize the value of good API design.  I strongly believe that this is key to making developers more productive and happy on our platform. It is clear that you value good API design in your work, and take to heart developer productivity and synergy with the .NET framework."
- Brad Abrams,
Lead Program Manager, Microsoft.

This is a partial list of companies who are using our libraries:
ABB Robotics
Allstate
Applied Materials
Arcam
Astra Schedule
Babson College
Canadian Council on Learning
Canyon Associates
Caxton Associates
CECity
Constellation Energy
CreditSights
DeepOcean
Duke University
Dynamotive
Elecsoft
Engelhard Corporation
Epcor
Equipoise Software
Galileo International
GAM UK
Gammex
GlaxoSmithKline
Global Matrix
The Hartford
Infinera Corporation
Intel
JDS Uniphase
LaBranche & Co.
Learning & Skills Council
Jacobs Consultancy
Litman Gregory
Lucas Systems
Malvern Instruments
Medrio
Merck & Co.
Mintera.
Monitor Software
MorningStar
NanoString Technologies
Paletta Invent
Parametric Portfolio Associates
Prosanos
RATA Associates
RiskShield
Ramboll
Standard & Poor's
Strategic Analysis Corporation
Univ. of Alicante
Univ. of South Carolina
vielife
Xerox
US Army