习题8.5
1.代码实现
点击查看代码
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
# 定义微分方程组
def system(state, eta):
f, df, d2f, T, dT = state
d3f = -3 * d2f + 2 * df ** 2 - T
d2T = -2.1 * df * dT
return [df, d2f, d3f, dT, d2T]
# 初始条件
f0 = 0
df0 = 0
d2f0 = 0.68
T0 = 1
dT0 = -0.5
state0 = [f0, df0, d2f0, T0, dT0]
# 时间范围
eta = np.linspace(0, 10, 1000)
# 求解微分方程组
solution = odeint(system, state0, eta)
f_sol = solution[:, 0]
T_sol = solution[:, 3]
# 绘制解曲线
plt.figure()
plt.plot(eta, f_sol, label='f(eta)')
plt.plot(eta, T_sol, label='T(eta)')
plt.xlabel('eta')
plt.ylabel('f, T')
plt.title('Solution of the system of differential equations')
plt.legend()
plt.show()
2.运行结果