Newton's law of cooling; 冷卻速率 dT/dt= k(T-T_ref)
Example Code
- import numpy as np
- from scipy.integrate import odeint
- import matplotlib.pyplot as plt
- def model(T,t):
- k = 1
- Tref=26
- dTdt = -k * (T-Tref)
- return dTdt
- y0 = 100
- t = np.linspace(0, 5)
- t100 = odeint(model, y0, t)
- t80= odeint(model, 80, t)
- t10= odeint(model, 10, t)
- plt.plot(t,t100, label='cooling from 100 degrees')
- plt.plot(t,t80, label='cooling from 80 degrees')
- plt.plot(t,t10, label='heating from 10 degrees')
- plt.title('Exponential decay');
- plt.legend(loc='right')
- plt.xlabel('time')
- plt.ylabel('I(t)')
- plt.show()
Note and Comments
- import numpy as np: 讀入numpy函式庫並命名為np
- from scipy.integrate import odeint 讀取scipy.integrate函式庫的odeint函式庫 (可使用odeint求解ODE)
- def model(T,t): 定義常微分方程式
- k = 1
- Tref=26
- dTdt = -k * (T-Tref)
- return dTdt
- Tref 是熱庫溫度,在此我設成26度室溫
- odeint(model, I0, t): odeeint() 爲解常微分方程的求解程式, 其中第一個變量equation是我們求欲求解的常微分方程, I0爲初始值, t爲變數
result