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# | Copy |
|---|
ChebyshevSeries c1 = new ChebyshevSeries(5);
ChebyshevSeries c2 = new ChebyshevSeries(5, 0.0, 2.0);
|
| Visual Basic | Copy |
|---|
Dim c1 As ChebyshevSeries = New ChebyshevSeries(5)
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# | Copy |
|---|
Double [] coefficients = new Double[] {1, 0.5, 0.25, 0.125, 0.0625};
ChebyshevSeries c3 = new ChebyshevSeries(coefficients);
ChebyshevSeries c4 = new ChebyshevSeries(coefficients, 0.0, 2.0);
|
| Visual Basic | Copy |
|---|
Dim coefficients As Double() = New Double() {1, 0.5, 0.25, 0.125, 0.0625}
Dim c3 As ChebyshevSeries = New ChebyshevSeries(coefficients)
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(RealFunction, Double, Double, Int32) 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# | Copy |
|---|
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]);
}
ChebyshevSeries lsqApproximation =
ChebyshevSeries.LeastSquaresFit(xValues, yValues,
-Constants.Pi/2, Constants.Pi/2, 4);
Console.WriteLine("Least squares fit:");
for(index = 0; index <= 4; index++)
Console.WriteLine("c({0}) = {0}",
index, lsqApproximation[index]);
RealFunction f = new RealFunction(Math.Sin);
ChebyshevSeries interpolant =
ChebyshevSeries.GetInterpolatingPolynomial(f,
-Constants.Pi/2, Constants.Pi/2, 4);
Console.WriteLine("Interpolating polynomial:");
for(index = 0; index <= 4; index++)
Console.WriteLine("c({0}) = {0}",
index, interpolant[index]);
|
| Visual Basic | Copy |
|---|
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
Dim lsqApproximation As ChebyshevSeries = _
ChebyshevSeries.LeastSquaresFit(xValues, yValues, _
-Constants.Pi/2, Constants.Pi/2, 4)
Console.WriteLine("Least squares fit:")
For index = 0 To 4
Console.WriteLine("c({0}) = {0}", _
index, lsqApproximation.Coefficients(index))
Next
Dim f As RealFunction = New RealFunction(AddressOf Math.Sin)
Dim interpolant As ChebyshevSeries = _
ChebyshevSeries.GetInterpolatingPolynomial(f, _
-Constants.Pi/2, Constants.Pi/2, 4)
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(Double) method returns the value of the
polynomial at a specified point. SlopeAt(Double)
returns the derivative. For expansions over an interval different from the standard [-1,1], appropriate
transformations are applied automatically.
| C# | Copy |
|---|
Console.WriteLine("p1.ValueAt(2) = {0}", c1.ValueAt(2));
Console.WriteLine("p1.SlopeAt(2) = {0}", c1.SlopeAt(2));
|
| Visual Basic | Copy |
|---|
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# | Copy |
|---|
Curve derivative = c1.GetDerivative();
Console.WriteLine("Slope at 2 (derivative) = {0}",
derivative.ValueAt(2));
|
| Visual Basic | Copy |
|---|
Dim derivative As Curve = c1.GetDerivative()
Console.WriteLine("Slope at 2 (derivative) = {0}", _
derivative.ValueAt(2))
|
Integral(Double, Double) evaluates the definite integral
over a specified interval. This value is calculated directly using the coefficients of the expansion. No numerical
approximation is used.