7.3

Tsuki*發表於2024-11-10

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("3022")

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()

相關文章