0

I need to create simple program which will take every element of list and put it in polyfit polynomial,then calculate it.

Here is my code

import pylab as p
import numpy as np
import sympy as s
from random import random

X=np.arange(0,1000)
y=np.random.randint(100,size=1000)

if len(X)==len(y):
   print "ok"
else:
   print "not ok"

polyfit=np.polyfit(X,y,3)
poly1d=np.poly1d(polyfit)
print poly1d
i=1
my=[]
for i in X:
    p=poly1d[i]
    my.append(p)
Y=my

print Y

My problem is that this only rewrite coefficient of polynomial and rest elements from list are 0.I need a clue how to solve it properly.

wiedzminYo
  • 531
  • 4
  • 11
  • 24
  • Is this a typo: `p=poly1d[i]`? Maybe you wanted `p = np.poly1d(i)`? – VP. Jan 02 '15 at 11:05
  • Thats interesting,I have forgot about this but after correct all i got is poly1d([ 0.]), poly1d([1]), poly1d([2])... to poly1d([1000]) – wiedzminYo Jan 02 '15 at 11:13
  • I'm with Victor! Apart from this: As you hava fitted a 3rd order polynom to your data, you can evaluate the polynom on the full X vector by `Y = poly1d(X)`, so what is the loop meant to be useful for?? – jkalden Jan 04 '15 at 15:48

0 Answers0