Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168730
Image: ubuntu2004
def pol1(x, a): """ Algoritmo pol1 """ n = a.shape[0] px = a[n-1] for j in range(n-2, -1, -1): px = px + a[j] * x^(n-j-1) return px
def pol2(x, a): """ Algoritmo pol2 """ n = a.shape[0] px = a[n-1] xp = 1 for j in range(n-2, -1, -1): xp = xp*x px = px + a[j] * xp return px
def horner(x, a): """ Algoritmo di Horner """ n = a.shape[0] px = a[0] for i in range(1, n): px = a[i] + px*x return px
import numpy as np import matplotlib.pylab as plt
p = np.array([1,-6,15,-20,15,-6,1]) x = np.linspace(0.995,1.005,1000) # rappresentazione compatta y = (x-1)**6
# Algoritmo di horner yh = horner(x,p) # Algoritmo 1 y1 = pol1(x,p) # Algoritmo 2 y2 = pol2(x,p)
plt.plot(x,y,'-b',lw=2) plt.plot(x,yh,'og') plt.plot(x,y1,'*r') plt.plot(x,y2,'vm') plt.savefig('polfig.png')