Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Vaca R., Trazadores Cúbicos, Conejito.
Vaca R., Trazadores Cúbicos, Conejito.
#DEBER N° : 9
#FECHA DE ENTREGA : JUEVES, 18 DE JULIO, 2019.
#PROFESOR : ALEX JERVES
#ESTUDIANTE : ROBERT BORIS VACA REYES
import numpy
import sympy
def tcubico(xi,yi):
n = len(xi)
i = 0
while (i < n-3):
A[i,i-1] = h[i]
A[i,i] = 2*(h[i]+h[i+1])
A[i,i+1] = h[i+1]
B[i] = 6*((yi[i+2]-yi[i+1])/h[i+1] - (yi[i+1]-yi[i])/h[i])
i = i+1
A[n-3,n-4] = h[n-3]
A[n-3,n-3] = 2*(h[n-3]+h[n-2])
B[n-3] = 6*((yi[n-1]-yi[n-2])/h[n-2] - (yi[n-2]-yi[n-3])/h[n-3])
r = numpy.linalg.solve(A,B)
j = 0
while (j < n-1):
S[j] = r[j-1]
j = j+1
S[0] = 0
S[n-1] = 0
a = numpy.zeros(n-1, dtype = float)
b = numpy.zeros(n-1, dtype = float)
c = numpy.zeros(n-1, dtype = float)
d = numpy.zeros(n-1, dtype = float)
j = 0
while (j < n-1):
a[j] = (S[j+1]-S[j])/(6*h[j])
b[j] = S[j]/2
c[j] = (yi[j+1]-yi[j])/h[j] - (2*h[j]*S[j]+h[j]*S[j+1])/6
d[j] = yi[j]
j = j + 1
x = sympy.Symbol('x')
polinomio = []
j = 0
while(j < n-1):
ptramo = a[j]*(x-xi[j])**3 + b[j]*(x-xi[j])**2 + c[j]*(x-xi[j])+ d[j]
ptramo = ptramo.expand()
polinomio.append(ptramo)
j = j+1
return(polinomio)
#******************************************************************************#
# CONEJITO PLAYBOY
xi = numpy.array([1.4, 2.0, 3.0, 6.0, 9.0, 10.3, 12.7, 13.8, 13.5, 8.3, 8.8,
10.5, 13.7, 16.2, 17.8, 18.3, 19.7, 18.0, 15.0, 13.0, 10.9, 7.8, 7.3, 5.8, 5.4,
5.9, 7.0, 6.6, 5.2, 4.1, 3.8, 2.2, 1.4])
fi = numpy.array([12.3, 14.0, 15.3, 16.0, 18.8, 18.5, 19.8, 18.7, 17.0, 14.2,
13.0, 12.4, 12.6, 11.4, 9.4, 5.4, 4.1, 1.7, 1.5, 0.6, 0.9, 1.4, 2.6, 2.8, 3.7,
4.6, 4.9, 5.8, 6.5, 7.8, 10.3, 10.7, 12.3 ])
resolucion = 20
n = len(xi)
polinomio = tcubico(xi,fi)
print('Polinomios por tramos: ')
tramo = 1
while(tramo < n):
print(' x = ['+str(xi[tramo-1])+','+str(xi[tramo])+']')
print(str(polinomio[tramo-1]))
tramo = tramo + 1
xtrazado = numpy.array([])
ytrazado = numpy.array([])
tramo = 1
while(tramo < n):
a = xi[tramo-1]
b = xi[tramo]
xtramo = numpy.linspace(a,b,resolucion)
ptramo = polinomio[tramo-1]
pxtramo = sympy.lambdify('x',ptramo)
ytramo = pxtramo(xtramo)
xtrazado = numpy.concatenate((xtrazado,xtramo))
ytrazado = numpy.concatenate((ytrazado,ytramo))
tramo = tramo + 1
import matplotlib.pyplot as rv
rv.title('CONEJITO PLAYBOY By Robert Vaca (Made With Splines)')
rv.plot(xtrazado,ytrazado)
rv.plot(xi,fi,'o')
rv.show()