Skip to content

Instantly share code, notes, and snippets.

@akira093
Created October 11, 2012 00:15
Show Gist options
  • Save akira093/3869346 to your computer and use it in GitHub Desktop.
Save akira093/3869346 to your computer and use it in GitHub Desktop.
from __future__ import division
import pylab
import scipy
def p(x, l_):
sum = 0
for i in range(len(l_)):
sum += l_[i]*x**(len(l_)-i-1)
return sum
x = pylab.linspace(0,pylab.pi/2,10**3)
y = pylab.sin(x)
for i in range(1,10):
l_=scipy.polyfit(x,y,i)
pylab.plot(x,p(x,l_))
pylab.plot(x,y,label="sin curve")
pylab.title("Polyfit to sin curve")
pylab.legend()
pylab.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment