Created
October 11, 2012 00:15
-
-
Save akira093/3869346 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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