Source code for naginterfaces.library.examples.fit.dim1_minimax_polynomial_ex
#!/usr/bin/env python3
"``naginterfaces.library.fit.dim1_minimax_polynomial`` Python Example."
# NAG Copyright 2017-2019.
# pylint: disable=invalid-name
from math import exp
import numpy as np
from naginterfaces.library import fit
[docs]def main():
"""
Example for :func:`naginterfaces.library.fit.dim1_minimax_polynomial`.
Minimax curve fit by polynomials.
>>> main()
naginterfaces.library.fit.dim1_minimax_polynomial Python Example Results.
Minimax curve fit by polynomials.
Coefficients of degree-5 polynomial fit of exp:
(1.0000e+00, 1.0001e+00, 4.9909e-01, 1.7042e-01, 3.4784e-02, 1.3909e-02)
"""
print(
'naginterfaces.library.fit.dim1_minimax_polynomial '
'Python Example Results.'
)
print('Minimax curve fit by polynomials.')
n = 21
x = np.linspace(0., 1., n)
y = list(map(exp, x))
m = 5
print('Coefficients of degree-5 polynomial fit of exp:')
print(
'(' +
', '.join(['{:.4e}']*(m + 1)).format(
*fit.dim1_minimax_polynomial(x, y, m).a
) +
')'
)
if __name__ == '__main__':
import doctest
import sys
sys.exit(
doctest.testmod(
None, verbose=True, report=False,
optionflags=doctest.REPORT_NDIFF,
).failed
)