0

I am trying to fit 2d data using polynomial fit and find that after a certain degree of polynomials, numpy gives "Rank Warning". On the other hand, fitting using Chebyshev polynomials do not give such warnings. I could able to fit the same data using Chebyshev of numpy. The output is in the form of Chebyshev polynomials of different ranks.

I want to calculate numerical value of these Chebyshev polnomials so that I can compare the results with normal polynomial fitting. Here is the sample code.

import numpy as np
from numpy.polynomial import Chebyshev as T
import os
from mpmath import *
mp.dps = 16 
mp.pretty = True

x = [1, 2, 3, 4, 5]
y = [0.90, 8.15, 26.84, 64.87, 124.0]

deg = 3
popt_poly = np.polyfit(x, y, deg)
popt_cheb = T.fit(x, y, deg)
ypred = np.polyval(popt_poly, x)
print(popt_poly)
print(ypred)
print(popt_cheb)

Thanking you in advance.

Parag
  • 41
  • 8
  • Did you get the error when running the aforementioned code? This code run without any error on colab for me and get the results!? – Ali_Sh Dec 06 '21 at 13:02
  • It does, I want to calculate predicted values for Cheyshev polynomial fitting - equivalent of np.polyval. Thanks for your comment. – Parag Dec 07 '21 at 06:32
  • Then what is the error you have? Please copy paste the full trace (no screenshot). – jlandercy Jan 12 '22 at 13:14
  • Check the last two lines of the question. – Parag Jan 18 '22 at 07:25

1 Answers1

0

Please use "window=" parameter. In this case: window=[1,5]