Chebyshev Polynomial Approximator Code Generator

This is a code generator that can generate fast approximations of functions for speed-critical applications. It does so by generating a Chebyshev polynomial which approximates the function then writing out code to quickly evaluate that polynomial. Multiple languages and styles are supported for code generation.

To use this tool, fill in the body of the javascript function with the calculation you want to appproximate. The input to the function will be available to this expression as "x". You also have to select a range to operate over - all inputs to the generated function must be in the range given. By clicking on the generate button you can create code to approximate the expression entered.

Different functions vary in how easy they are to approximate with a polynomial - sin can be done quite easily but tan would be inaccurate however large the polynomial. Avoid anything with extreme fluctuations within the input range given. Generally smoother functions also get better approximations. A number of example functions are given as preset options.

Examples:

Polynomial Order: Setting order higher increases accuracy, but takes longer to calculate.
Function Name: Function name in generated code
Function: function(x) {

}
Range: from to The generated function will break if given numbers outside this.
Clamp output: from to Limit output to minimum and maximum. Either or both may be left out.
Generated Code Style:






Polynomial:
 

Code:
 

Plot

This is a very rough plot of the function generated

Test Run

First generate a polynomial above, then you can try it out against different inputs by entering them in this form. This always runs on the last generated approximation. This doesn't apply the clamp part so you can see where the output will be clamped.


Result:  

Detailed Notes

Often many of the coefficients will be extremely small. By default coefficients with a magnitude below 1e-12 may be omitted from some code formats (where it speeds things up and doesn't add complication) and from the displayed polynomial. This level can be set in the advanced options.