复摆T^2-h与T-h图象

#T^2-h
import numpy as np
import matplotlib.pyplot as plt

# 生成样本数据
x = np.array([0.0841,0.0784,0.0729,0.0676,0.0625,0.0576,0.0529,0.0484,0.0441,0.04,0.0361,0.0324,0.0289,0.0256,0.0225,0.0196,0.0169,0.0144,0.0121,0.01,0.0081,0.0064])
y = np.array([0.469547,0.445764,0.424715,0.401842,0.3818,0.361798,0.34071,0.323301,0.306851,0.289418,0.273806,0.259827,0.245412,0.232787,0.218708,0.207455,0.197368,0.187622,0.176693,0.167018,0.159371,0.149656])

# 使用polyfit函数计算多项式系数
coefficients = np.polyfit(x, y, 1)

slope = coefficients[0]  # 斜率
intercept = coefficients[1]  # 截距

print(f"斜率为: {slope}")
print(f"截距为: {intercept}")

poly = np.poly1d(coefficients)

# 在给定的x值上预测y值
y_pred = poly(x)

# 绘制原始数据和拟合曲线
plt.scatter(x, y)
plt.plot(x, y_pred, color='red')
plt.xlabel('h^2')
plt.ylabel('T^2*h')
plt.title('Fitting Curve by Least Square Method')
plt.show()
#T-h
import numpy as np
import matplotlib.pyplot as plt

# 生成样本数据
x = np.array([0.29,0.28,0.27,0.26,0.25,0.24,0.23,0.22,0.21,0.2,0.19,0.18,0.17,0.16,0.15,0.14,0.13,0.12,0.11,0.1,0.09,0.08])
y = np.array([1.27245,1.26175,1.2542,1.2432,1.2358,1.2278,1.2171,1.21225,1.2088,1.20295,1.20045,1.20145,1.2015,1.2062,1.2075,1.2173,1.23215,1.2504,1.2674,1.29235,1.3307,1.3677])

# 使用polyfit函数计算多项式系数
coefficients = np.polyfit(x, y, 22)


# 使用多项式系数生成拟合曲线
poly = np.poly1d(coefficients)
y_pred = poly(x)

# 绘制原始数据和拟合曲线
plt.scatter(x, y)
plt.plot(x, y_pred, color='red')
plt.xlabel('h')
plt.ylabel('T')
plt.title('The Relationship between T and h')
plt.show()

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值