Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Código: 018101393J
CODE: 735
Pregunta 1. (8p)
x 13,9 19,8 14,5 10,3 12,8 19,9 9,6 14,0 12,2 1,7 4,2 13,1 11,0 3,2
3,1 16,9 14,2 11,3 13,7 15,4
y 226,1 313,1 218,4 173,9 209,1 318,4 153,7 230,3 181,0 27,1 67,5 204,2 184,7 73,5
51,6 252,8 228,0 186,1 210,2 246,5
Determine los parámetros del modelo lineal y=a+bx. Grafique los datos junto a la recta. Estime y, cuando x=10,
cuanto es r.
import numpy as np
def minCuadrados(X,Y):
n = X.shape[0]
if (n != Y.shape[0] ):
return
SumX = np.sum(X)
SumY = np.sum(Y)
SumX2 = np.sum(X**2)
SumY2 = np.sum(Y**2)
SumXY = np.sum(X*Y)
a = (SumY - b*SumX)/n
return a,b,r
import numpy as np
def minCuadrados(X,Y):
Datos:
Resultado:
r: el coeficiente de correlacion'''
n = X.shape[0]
if (n != Y.shape[0] ):
return
SumX = 0
SumY = 0
SumX2 = 0
SumY2 = 0
SumXY = 0
for i in range(n):
SumX += X[i]
SumY += Y[i]
SumX2 += X[i]*X[i]
SumY2 += Y[i]*Y[i]
SumXY += X[i]*Y[i]
a = (SumY - b*SumX)/n
return a,b,r
import numpy as np
x = np.array([13.9,19.8,14.5,10.3,12.8,19.9,9.6,14.0,12.2,1.7,4.2,13.1,11.0,3.2,3.1,16.9,14.2,11.3,13.7,15.4])
y=
np.array([226.1,313.1,218.4,173.9,209.1,318.4,153.7,230.3,181.0,27.1,67.5,204.2,184.7,73.5,51.6,252.8,228.0,186.1,
210.2,246.5])
a,b,r = minCuadrados(x,y)
print("a =",a)
print("b =",b)
print("r =",r)
print("y =",a+b*10)
xx = np.linspace(min(x),max(x),200)
a = 8.903538980469307
b = 15.239051194167862
r = 0.9946768444315737
y = 161.29405092214793
[<matplotlib.lines.Line2D at 0x19f2af63fc8>,
<matplotlib.lines.Line2D at 0x19f2af78808>]
Determine los parámetros del modelo lineal x=c+dy. Grafique los datos junto a la recta. Estime x, cuando y=150,
cuanto es r.
import numpy as np
x = np.array([13.9,19.8,14.5,10.3,12.8,19.9,9.6,14.0,12.2,1.7,4.2,13.1,11.0,3.2,3.1,16.9,14.2,11.3,13.7,15.4])
y=
np.array([226.1,313.1,218.4,173.9,209.1,318.4,153.7,230.3,181.0,27.1,67.5,204.2,184.7,73.5,51.6,252.8,228.0,186.1,
210.2,246.5])
c,d,r = minCuadrados(y,x)
print("c =",c)
print("d =",d)
print("r =",r)
print("y =",c+d*150)
yy = np.linspace(min(x),max(x),200)
c = -0.4533994261980524
d = 0.06492412239070365
r = 0.9946768444315737
y = 9.285218932407496
[<matplotlib.lines.Line2D at 0x19f2b02da48>,
<matplotlib.lines.Line2D at 0x19f2af78648>]
Pregunta 2. (6p)
x 13,1 16,4 14,1 13,3 10,5 5,9 12,6 14,8 24,6 17,6 14,0 21,5 10,3 24,5
4,0 23,1 22,1 13,5 12,2 8,4
y 28,4 28,9 29,6 27,9 26,4 21,3 27,7 28,7 30,0 29,6 28,6 29,8 26,7 30,6
17,1 30,5 30,0 28,2 28,2 24,9
x = np.array([13.1,16.4,14.1,13.3,10.5,5.9,12.6,14.8,24.6,17.6,14.0,21.5,10.3,24.5,4.0,23.1,22.1,13.5,12.2,8.4])
y = np.array([28.4,28.9,29.6,27.9,26.4,21.3,27.7,28.7,30.0,29.6,28.6,29.8,26.7,30.6,17.1,30.5,30.0,28.2,28.2,24.9])
# Y=Ae**(-B/x)
a1,b1,r1 = minCuadrados(1/x,np.log(y))
A1 = np.exp(a1)
B1 = -b1
# y=Ax^B
a2,b2,r2 = minCuadrados(np.log(x),np.log(y))
A2 = np.exp(a2)
B2 = b2
a3,b3,r3 = minCuadrados(1/x,1/y)
A3 = 1/a3
B3 = b3/a3
xx = np.linspace(min(x),max(x),200)
plt.plot(x, y, 'r*', xx, y1, 'r', xx, y2, 'g', xx, y3, 'b')
[<matplotlib.lines.Line2D at 0x19f2b0a9588>,
<matplotlib.lines.Line2D at 0x19f2b02dcc8>,
<matplotlib.lines.Line2D at 0x19f2b0b38c8>,
<matplotlib.lines.Line2D at 0x19f2b0b3a88>]
¿Qué modelo ajusta, de mejor manera a los datos?
Pregunta 3. (6p)
x 26,7 10,3 24,9 14,9 11,9 26,7 19,1 21,1 29,2 22,1 16,1 17,0 13,2 12,3
26,5 30,0 12,2 19,4 17,5 29,5
y 92,0 29,7 101,3 11,2 13,4 85,4 59,3 81,0 45,5 99,3 17,7 16,9 6,6 14,2
86,4 35,7 7,6 58,7 33,2 31,9
Ajuste dichos datos por combinación lineal usando: la función constante, x−−√sin(x/3) y ln(x).
def coefDeterminacion(x,y,C,f):
Datos:
C: Lista de los coeficientes [c1,c2,...,cm] de la combinacion lineal y = c1f1 +c2f2 + ... + cmfm
Resultado:
Ym = np.sum(y)/n
return (1 - Sr/St)
def coefDeterminacionPoly(x,y,C):
Datos:
Resultado:
Ym = np.sum(y)/n
return (1 - Sr/St)
import numpy as np
def fval(C,f,x):
Datos:
x: Es el vector
Resultado:
y(x)'''
n = x.shape[0]
m = len(f)
y = np.zeros_like(x)
for i in range(n):
for k in range(m):
y[i] += C[k]*f[k](x[i])
return y
import numpy as np
def ajusteCL(x,y,f):
'''Determina la función y = a1f1 + a2f2 + ... + amfm que ajusta a un conjunto de datos (Xi,Yi)
Datos:
Resultado:
Retorna el vector con los coeficientes [a1,...,am]'''
n = x.shape[0]
m = len(f)
F = np.zeros((n,m))
for i in range(m):
F[:,i] = f[i](x)
A = np.dot(F.T,F)
B = np.dot(F.T,y)
return np.linalg.solve(A,B)
import numpy as np
x = np.array([26.7,10.3,24.9,14.9,11.9,26.7,19.1,21.1,29.2,22.1,16.1,17.0,13.2,12.3,26.5,30.0,12.2,19.4,17.5,29.5])
y = np.array([92.0,29.7,101.3,11.2,13.4,85.4,59.3,81.0,45.5,99.3,17.7,16.9,6.6,14.2,86.4,35.7,7.6,58.7,33.2,31.9])
xx = np.linspace(min(x),max(x),200)
np.sqrt(coefDeterminacion(x,y,C,F) )*100
= 99.32261303783955