Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
restrepo
GitHub Repository: restrepo/ComputationalMethods
Path: blob/master/homework/homework_2018_1_06_1038414799.ipynb
934 views
Kernel: Python 3
%pylab inline import pandas as pd from scipy import optimize
Populating the interactive namespace from numpy and matplotlib
df= pd.DataFrame({'X':[0.3,0.5,1.3,3.2,4.5,5.2,6.0,7.5], 'Y':[0.11406,-0.1775,-1.87334,2.30704,24.8025,150.45,160.564,0.847]})
#Interpolacion de puntos S=np.polyfit(df.X,df.Y,deg=7) P=np.poly1d(S)
#Grafica de puntos x=np.linspace(df.X[0],df.X[7]) plt.plot(df.X,df.Y, "or", label="Puntos") plt.plot(x,P(x), "-b", label="Polinomio de interpolación") plt.legend()
<matplotlib.legend.Legend at 0x7f11eb0f6a20>
Image in a Jupyter notebook
loc=optimize.fmin_powell(P,4, full_output=True)#Minimo local glo=optimize.fmin_powell(P,7, full_output=True)#Minimo global
Optimization terminated successfully. Current function value: -27.114802 Iterations: 2 Function evaluations: 32 Optimization terminated successfully. Current function value: -229.774318 Iterations: 2 Function evaluations: 28
print(" Minimo global=({},{}), Minimo local=({},{}) ".format(glo[0],glo[1],loc[0],loc[1]))
Minimo global=(7.119927707838121,-229.77431802644736), Minimo local=(3.8202928576617037,-27.114802418687447)