Extreme Optimization™: Complexity made simple.

Math and Statistics
Libraries for .NET

  • Home
  • Features
    • Math Library
    • Vector and Matrix Library
    • Statistics Library
    • Performance
    • Usability
  • Documentation
    • Introduction
    • Math Library User's Guide
    • Vector and Matrix Library User's Guide
    • Data Analysis Library User's Guide
    • Statistics Library User's Guide
    • Reference
  • Resources
    • Downloads
    • QuickStart Samples
    • Sample Applications
    • Frequently Asked Questions
    • Technical Support
  • Blog
  • Order
  • Company
    • About us
    • Testimonials
    • Customers
    • Press Releases
    • Careers
    • Partners
    • Contact us
Introduction
Deployment Guide
Nuget packages
Configuration
Using Parallelism
Expand Mathematics Library User's GuideMathematics Library User's Guide
Expand Vector and Matrix Library User's GuideVector and Matrix Library User's Guide
Expand Data Analysis Library User's GuideData Analysis Library User's Guide
Expand Statistics Library User's GuideStatistics Library User's Guide
Expand Data Access Library User's GuideData Access Library User's Guide
Expand ReferenceReference
  • Extreme Optimization
    • Features
    • Solutions
    • Documentation
    • QuickStart Samples
    • Sample Applications
    • Downloads
    • Technical Support
    • Download trial
    • How to buy
    • Blog
    • Company
    • Resources
  • Documentation
    • Introduction
    • Deployment Guide
    • Nuget packages
    • Configuration
    • Using Parallelism
    • Mathematics Library User's Guide
    • Vector and Matrix Library User's Guide
    • Data Analysis Library User's Guide
    • Statistics Library User's Guide
    • Data Access Library User's Guide
    • Reference
  • Mathematics Library User's Guide
    • General Classes
    • Mathematical Functions
    • Complex Numbers
    • Arbitrary Precision Arithmetic
    • Automatic Differentiation
    • Curves and Interpolation
    • Curve Fitting
    • Solving Equations
    • Optimization
    • Calculus
    • Fast Fourier Transforms
    • Random Numbers
    • Generic Arithmetic
    • Appendices
  • Curves and Interpolation
    • Curve Basics
    • Polynomials
    • Chebyshev Series
    • Barycentric Series
    • Piecewise Curves and Cubic Splines
    • Cubic Splines
    • Comparing Curve classes and delegates
  • Chebyshev Series

Chebyshev Series

Extreme Optimization Numerical Libraries for .NET Professional

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:

C#
VB
C++
F#
Copy
// 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);
' 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)

No code example is currently available or this language may not be supported.

// Chebyshev expansion of degree 5:
let c1 = ChebyshevSeries(5)
// Chebyshev expansion of degree 5 over the interval [0,2]:
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.

C#
VB
C++
F#
Copy
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);
Dim coefficients = 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)

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 |])
// Chebyshev expansion of degree 4 with the above coefficients:
let c3 = ChebyshevSeries(coefficients)
// Chebyshev expansion of degree 4 over the interval [0, 2]:
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.

C#
VB
C++
F#
Copy
// x and y values contain the data points:
var xValues = Vector.Create(13, i => (i - 6) * Constants.Pi / 12);
var yValues = Vector.Sin(xValues);
// 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 (int i = 0; i <= 4; i++)
    Console.WriteLine("c({0}) = {0}",
        i, lsqApproximation[i]);
// Now let's calculate the interpolating Chebyshev expansion:
ChebyshevSeries interpolant =
    ChebyshevSeries.GetInterpolatingPolynomial(Math.Sin,
        -Constants.Pi / 2, Constants.Pi / 2, 4);
// This expansion is close to the previous one:
Console.WriteLine("Interpolating polynomial:");
for (int i = 0; i <= 4; i++)
    Console.WriteLine("c({0}) = {0}",
        i, interpolant[i]);
' x and y values contain the data points:
Dim xValues = Vector.Create(13, Function(i) (i - 6) * Constants.Pi / 12)
Dim yValues = Vector.Sin(xValues)
' 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 i As Integer = 0 To 4
    Console.WriteLine("c(0) = {0}",
        i, lsqApproximation(i))
Next
' Now let's calculate the interpolating Chebyshev expansion:
Dim interpolant As ChebyshevSeries =
    ChebyshevSeries.GetInterpolatingPolynomial(AddressOf Math.Sin,
        -Constants.Pi / 2, Constants.Pi / 2, 4)
' This expansion is close to the previous one:
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.

// x and y values contain the data points:
let xValues = Vector.Create(13, fun i -> float (i - 6) * Constants.Pi / 12.0)
let yValues = Vector.Sin(xValues)
// Now we can find the least squares approximation:
let lsqApproximation =
    ChebyshevSeries.LeastSquaresFit(xValues, yValues,
        -Constants.PiOverTwo, Constants.PiOverTwo, 4)
// Note that, as expected, the odd coefficients are close to zero.
Console.WriteLine("Least squares fit:")
for i in 0..4 do
    Console.WriteLine("c(0) = {0}", i, lsqApproximation.[i])
// Now let's calculate the interpolating Chebyshev expansion:
let interpolant =
    let sin = Func<double,double>(Math.Sin)
    ChebyshevSeries.GetInterpolatingPolynomial(sin,
        -Constants.PiOverTwo, Constants.PiOverTwo, 4)
// This expansion is close to the previous one:
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.

C#
VB
C++
F#
Copy
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.

C#
VB
C++
F#
Copy
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.

Copyright (c) 2004-2021 ExoAnalytics Inc.

Send comments on this topic to support@extremeoptimization.com

Copyright © 2004-2021, Extreme Optimization. All rights reserved.
Extreme Optimization, Complexity made simple, M#, and M Sharp are trademarks of ExoAnalytics Inc.
Microsoft, Visual C#, Visual Basic, Visual Studio, Visual Studio.NET, and the Optimized for Visual Studio logo
are registered trademarks of Microsoft Corporation.