非常小白,有问题有错误,各位大佬请指正!!!!
问题:
y y y 举重成绩
t t t 力度
s s s 肌肉横截面积
q q q 特征尺寸
w w w 体重
假设1
举重成绩与力度成正比,即 y ∝ t y = k 1 t y \propto t ~~~ y=k_{1}t y∝t y=k1t
力度与肌肉横截面积成正比, 即 t ∝ s t = k 2 s t \propto s ~~~ t=k_{2}s t∝s t=k2s
肌肉横截面积与某种特征尺寸成正比, 即 s ∝ q s = k 3 q s \propto q~~~ s=k_{3}q s∝q s=k3q
体重与某种特征尺寸成正比, 即 w ∝ q w = k 4 q w \propto q~~~ w=k_{4}q w∝q w=k4q
将上面的公式结合得, y = k 1 k 2 k 3 w k 4 y=\frac{k_{1}k_{2}k_{3}w}{k_{4}} y=k4k1k2k3w
集合表中数据利用最小二乘法的思想,来求关系式 y = k 1 k 2 k 3 w k 4 y=\frac{k_{1}k_{2}k_{3}w}{k_{4}} y=k4k1k2k3w的比例系数,利用python scipy库求解
程序,如下
from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei']
import numpy as np
from scipy.optimize import leastsq
def err(p, x, y):
return p[0] * x - y
p0 = [100]
Xi=np.array([54, 59, 64, 70, 76, 83, 91, 99, 108])
Yi=np.array([287.5, 307.5, 335, 357.5, 367.5, 392.5, 402.5, 420, 430])
ret = leastsq(err, p0, args = (Xi, Yi))
print (ret)
import matplotlib.pyplot as plt
k = ret[0]
plt.figure(figsize=(8,6))
plt.scatter(Xi,Yi,color="red",label="Sample Point",linewidth=3)
x = np.linspace(50,110,1000)
y = k * x
plt.plot(x,y,color="orange",label="Fitting Line",linewidth=2)
plt.xlabel("最大体重(y)/kg", fontsize=12)
plt.ylabel("总成绩(w)/kg", fontsize=12)
plt.legend()
plt.grid()
plt.show()
猜测,用线性函数对举重成绩与体重进行拟合的模型过于简单
所以我们再次猜测
假设2
举重成绩与力度成正比,即 y ∝ t y = k 1 t y \propto t ~~~ y=k_{1}t y∝t y=k1t
力度与肌肉横截面积成正比, 即 t ∝ s t = k 2 s t \propto s ~~~t=k_{2}s t∝s t=k2s
肌肉横截面积与某种特征尺寸的平方成正比, 即 s ∝ q 2 s = k 3 q 2 s \propto q^{2}~~~ s=k_{3}q^{2} s∝q2 s=k3q2
体重与某种特征尺寸成正比, 即 w ∝ q w = k 4 q w \propto q~~~ w=k_{4}q w∝q w=k4q
将上面的公式结合得, y = k 1 k 2 k 3 w 2 k 4 y=\frac{k_{1}k_{2}k_{3}w^{2}}{k_{4}} y=k4k1k2k3w2
集合表中数据利用最小二乘法的思想,来求关系式 y = k 1 k 2 k 3 w 2 k 4 y=\frac{k_{1}k_{2}k_{3}w^{2}}{k_{4}} y=k4k1k2k3w2的比例系数,利用python scipy库求解
即模型 y ∝ k w α y \propto kw^{\alpha} y∝kwα
程序,如下
from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei']
import numpy as np
from scipy.optimize import leastsq
Xi=np.array([54, 59, 64, 70, 76, 83, 91, 99, 108])
Yi=np.array([287.5, 307.5, 335, 357.5, 367.5, 392.5, 402.5, 420, 430])
def error(p,x,y):
return p[0]*x**p[1]-y
p0 = [5,2]
ret = leastsq(error,p0,args=(Xi,Yi))
import matplotlib.pyplot as plt
plt.figure(figsize=(8,6))
plt.scatter(Xi,Yi,color="red",label="Sample Point",linewidth=3)
x = np.linspace(50,110,1000)
y = 32.74825487 * x ** 0.55553414
plt.plot(x,y,color="orange",label="Fitting Curve",linewidth=2)
plt.xlabel("最大体重(y)/kg", fontsize=12)
plt.ylabel("总成绩(w)/kg", fontsize=12)
plt.legend()
plt.grid()
plt.show()
from sympy import *
x = symbols('x')
e = 32.74825487 * x ** 0.55553414
print("函数:")
print(e)
函数:
32.74825487*x**0.55553414
从上图看出,模型2理论值与实际值非常接近
即求解