7.3 已知当温度T=[700,720,740,760,780]时,过热蒸汽体积的变化为V=[0.0977,0.1218,0.1406,0.1551,0.1664],分别采用线性插值和三次样条插值求解T=750,770时的体积变化,并在一个图形界面中画出线性插值函数和三次样条插值函数

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d, CubicSpline

T = np.array([700, 720, 740, 760, 780])
V = np.array([0.0977, 0.1218, 0.1406, 0.1551, 0.1664])

T_interp = np.array([750, 770])

f_linear = interp1d(T, V, kind='linear')
V_linear_interp = f_linear(T_interp)

cs = CubicSpline(T, V)
V_cubic_interp = cs(T_interp)

print(f"线性插值结果: T={T_interp} 对应的 V={V_linear_interp}")
print(f"三次样条插值结果: T={T_interp} 对应的 V={V_cubic_interp}")
print("学号后四位:3004")

x = np.linspace(700, 780, 400)

plt.figure(figsize=(10, 6))
plt.plot(T, V, 'o', label='原始数据点')
plt.plot(x, f_linear(x), '-', label='线性插值')
plt.plot(x, cs(x), '--', label='三次样条插值')
plt.scatter(T_interp, V_linear_interp, color='red', label='线性插值点')
plt.scatter(T_interp, V_cubic_interp, color='green', label='三次样条插值点')
plt.xlabel('温度 T')
plt.ylabel('体积 V')
plt.title('过热蒸汽体积随温度变化的插值')
plt.legend()
plt.grid(True)
plt.show()

posted on   黄元元  阅读(34)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示