I am trying to calculate Chebyshev nodes to approximate the cos function in the interval [-1,1] with a polynomial of degree 4. In Python3, I used chebyfit from mpmath and chebyshev from numpy.
While I am getting accurate approximations,
nprint(cos(0.6), 12)
nprint(polyval(poly, 0.6), 12)
nprint(np.polynomial.chebyshev.chebval(0.6, c), 12)
0.82533561491
0.825331777049
0.825331777049078
I am not sure why the coefficients differ.
poly, err = chebyfit(cos, [-1, 1], 5, error=True)
nprint(poly)
[0.0399612, 2.11758e-23, -0.499576, -2.64698e-23, 1.0]
c = np.polynomial.chebyshev.chebinterpolate(np.cos, 4)
nprint(c)
[ 7.65197687e-01 -6.51999524e-18 -2.29807158e-01 -3.40959333e-18
  4.99515460e-03]
I am expecting the coefficients to match as the approximation is calculated for the same interval and order.