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 Numerical Libraries for .NET
supports Chebyshev series through the
ChebyshevSeries
class.
The ChebyshevSeries class
A Chebyshev series 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 representing general polynomials. Two characteristics
make Chebyshev polynomials especially attractive. They are
mutually orthogonal, and there exists a simple recurrence
relation between three consecutive polynomials.
The first characteristic makes it so that most algorithms
involving Chebyshev polynomials are numerically stable.
The second characteristic makes it easy to evaluate
series of Chebyshev polynomials.
Chebyshev polynomials are defined over the interval [-1, 1].
Using Chebyshev series outside of this interval
is usually not meaningful and is to be avoided.
To allow series 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 series are the coefficients of the polynomial.
The Degree
of a Chebyshev series is the highest degree of a Chebyshev polynomial
that appears in the sum. The number of parameters of the series equals
the degree plus one.
Constructing Chebyshev Series
The ChebyshevSeries
has four constructors. The first two variants let you specify
the degree of the highest order Chebyshev polynomial in the series.
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:
ChebyshevSeries c1 = new ChebyshevSeries(5);
ChebyshevSeries c2 = new ChebyshevSeries(5, 0.0, 2.0);
Dim c1 As ChebyshevSeries = New ChebyshevSeries(5)
Dim c2 As ChebyshevSeries = New ChebyshevSeries(5, 0.0, 2.0)
No code example is currently available or this language may not be supported.
let c1 = ChebyshevSeries(5)
let c2 = ChebyshevSeries(5, 0.0, 2.0)
The third and fourth variants let you specify the coefficients
of the series, 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.
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);
Dim coefficients = 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)
No code example is currently available or this language may not be supported.
let coefficients = Vector.Create([| 1.0; 0.5; 0.25; 0.125; 0.0625 |])
let c3 = ChebyshevSeries(coefficients)
let c4 = ChebyshevSeries(coefficients, 0.0, 2.0)
In addition, you can also create a Chebyshev series using
one of several static methods.
The LeastSquaresFit
method constructs a 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 Polynomial
class. The calculation is much more stable, however,
leading to good accuracy even for high degree approximations.
The GetInterpolatingPolynomial
method interpolates a function.
The function is specified as its first parameter in the form of a
FuncT, TResult delegate.
The second argument is an integer indicating the degree of the polynomial.
This method calculates the interpolating polynomial
(in the form of a Chebyshev series) 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.
var xValues = Vector.Create(13, i => (i - 6) * Constants.Pi / 12);
var yValues = Vector.Sin(xValues);
ChebyshevSeries lsqApproximation =
ChebyshevSeries.LeastSquaresFit(xValues, yValues,
-Constants.Pi / 2, Constants.Pi / 2, 4);
Console.WriteLine("Least squares fit:");
for (int i = 0; i <= 4; i++)
Console.WriteLine("c({0}) = {0}",
i, lsqApproximation[i]);
ChebyshevSeries interpolant =
ChebyshevSeries.GetInterpolatingPolynomial(Math.Sin,
-Constants.Pi / 2, Constants.Pi / 2, 4);
Console.WriteLine("Interpolating polynomial:");
for (int i = 0; i <= 4; i++)
Console.WriteLine("c({0}) = {0}",
i, interpolant[i]);
Dim xValues = Vector.Create(13, Function(i) (i - 6) * Constants.Pi / 12)
Dim yValues = Vector.Sin(xValues)
Dim lsqApproximation As ChebyshevSeries =
ChebyshevSeries.LeastSquaresFit(xValues, yValues,
-Constants.Pi / 2, Constants.Pi / 2, 4)
Console.WriteLine("Least squares fit:")
For i As Integer = 0 To 4
Console.WriteLine("c(0) = {0}",
i, lsqApproximation(i))
Next
Dim interpolant As ChebyshevSeries =
ChebyshevSeries.GetInterpolatingPolynomial(AddressOf Math.Sin,
-Constants.Pi / 2, Constants.Pi / 2, 4)
Console.WriteLine("Interpolating polynomial:")
For i As Integer = 0 To 4
Console.WriteLine("c(0) = {0}",
i, interpolant(i))
Next
No code example is currently available or this language may not be supported.
let xValues = Vector.Create(13, fun i -> float (i - 6) * Constants.Pi / 12.0)
let yValues = Vector.Sin(xValues)
let lsqApproximation =
ChebyshevSeries.LeastSquaresFit(xValues, yValues,
-Constants.PiOverTwo, Constants.PiOverTwo, 4)
Console.WriteLine("Least squares fit:")
for i in 0..4 do
Console.WriteLine("c(0) = {0}", i, lsqApproximation.[i])
let interpolant =
let sin = Func<double,double>(Math.Sin)
ChebyshevSeries.GetInterpolatingPolynomial(sin,
-Constants.PiOverTwo, Constants.PiOverTwo, 4)
Console.WriteLine("Interpolating polynomial:")
for i in 0..4 do
Console.WriteLine("c(0) = {0}", i, interpolant.[i])
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 series
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 series over an interval different from the standard [-1,1], appropriate
transformations are applied automatically.
Console.WriteLine("c1.ValueAt(2) = {0}", c1.ValueAt(2));
Console.WriteLine("c1.SlopeAt(2) = {0}", c1.SlopeAt(2));
Console.WriteLine("c1.ValueAt(2) = {0}", c1.ValueAt(2))
Console.WriteLine("c1.SlopeAt(2) = {0}", c1.SlopeAt(2))
No code example is currently available or this language may not be supported.
Console.WriteLine("c1.ValueAt(2) = {0}", c1.ValueAt(2.0))
Console.WriteLine("c1.SlopeAt(2) = {0}", c1.SlopeAt(2.0))
The GetDerivative method returns the
Chebyshev series that is the derivative of a Chebyshev series.
Curve derivative = c1.GetDerivative();
Console.WriteLine("Slope at 2 (derivative) = {0}",
derivative.ValueAt(2));
Dim derivative As Curve = c1.GetDerivative()
Console.WriteLine("Slope at 2 (derivative) = {0}",
derivative.ValueAt(2))
No code example is currently available or this language may not be supported.
let derivative = c1.GetDerivative()
Console.WriteLine("Slope at 2 (derivative) = {0}",
derivative.ValueAt(2.0))
Integral evaluates the definite integral
over a specified interval. This value is calculated directly using the coefficients of the series. No numerical
approximation is used.