首页 > 其他分享 >数学建模习题8.5

数学建模习题8.5

时间:2024-11-17 15:10:55浏览次数:1  
标签:plt 8.5 建模 sol dm2 dm import span 习题

`import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp

定义微分方程模型

def model(t, y):
f, df_dm, d2f_dm2, T, dT_dm = y
d3f_dm3 = -3 * f * d2f_dm2 + 2 * (df_dm)**2 - T
d2T_dm2 = -2 * f * dT_dm
return [df_dm, d2f_dm2, d3f_dm3, dT_dm, d2T_dm2]

初始条件

y0 = [0, 0, 0.68, 1, -0.5]
t_span = (0, 10)
t_eval = np.linspace(t_span[0], t_span[1], 1000)

解微分方程

sol = solve_ivp(model, t_span, y0, t_eval=t_eval, method='RK45')

提取解

f = sol.y[0]
T = sol.y[3]

绘制 f(m) 和 T(m) 的图像

plt.figure(figsize=(12, 6))
plt.subplot(2, 1, 1)
plt.plot(sol.t, f, label='f(m)')
plt.xlabel('m')
plt.ylabel('f(m)')
plt.title('Solution for f(m)')
plt.grid(True)

plt.subplot(2, 1, 2)
plt.plot(sol.t, T, label='T(m)', color='orange')
plt.xlabel('m')
plt.ylabel('T(m)')
plt.title('Solution for T(m)')
plt.grid(True)

plt.tight_layout()
plt.show()

print("学号后四位:05")`

标签:plt,8.5,建模,sol,dm2,dm,import,span,习题
From: https://www.cnblogs.com/vvlin/p/18550573

相关文章

  • 习题7.10(3)
    1.代码实现点击查看代码importnumpyasnpimportpylabaspltfromscipy.optimizeimportcurve_fit#原始数据点x0=np.array([-2,-1.7,-1.4,-1.1,-0.8,-0.5,-0.2,0.1,0.4,0.7,1,1.3,1.6,1.9,2.2,2.5,2.8,3.1,3.4,3.7,4,4.3,4.6,4.9])y0=np.......
  • 习题8.5
    1.代码实现点击查看代码importnumpyasnpfromscipy.integrateimportodeintimportmatplotlib.pyplotasplt#定义微分方程组defsystem(state,eta):f,df,d2f,T,dT=stated3f=-3*d2f+2*df**2-Td2T=-2.1*df*dTreturn[df,......
  • 习题8.4
    1.代码实现点击查看代码importnumpyasnpfromscipy.integrateimportodeintimportmatplotlib.pyplotasplt#定义微分方程组defsystem(state,t):x,y=statedxdt=-x**3-ydydt=x-y**3return[dxdt,dydt]#初始条件x0=1y......
  • 数学建模习题7.10
    `importnumpyasnpimportpandasaspdimportmatplotlib.pyplotaspltfromscipy.interpolateimportinterp1d,PchipInterpolator,CubicSplinefromscipy.optimizeimportcurve_fitfromscipy.statsimportnorm读取数据file_path='7.17.xISX'#确保文件......
  • 习题7.10(2)
    1.代码实现点击查看代码importnumpyasnpimportpylabasplt#原始数据点x0=np.array([-2,-1.7,-1.4,-1.1,-0.8,-0.5,-0.2,0.1,0.4,0.7,1,1.3,1.6,1.9,2.2,2.5,2.8,3.1,3.4,3.7,4,4.3,4.6,4.9])y0=np.array([0.1029,0.1174,0.1316,0.144......
  • 数学建模习题8.4
    `importnumpyasnpimportmatplotlib.pyplotaspltfromscipy.integrateimportsolve_ivp定义微分方程系统defsystem(t,state):x,y=statedxdt=-x-ydydt=x-y**3return[dxdt,dydt]定义时间跨度和初始条件t_span=(0,30)y0=[1,0.5]解微分方程so......
  • 8.5
    importnumpyasnpimportmatplotlib.pyplotaspltfromscipy.integrateimportsolve_ivpplt.rcParams['text.usetex']=Falsedefmodel(t,y):f,df_dm,d2f_dm2,T,dT_dm=yd3f_dm3=-3*f*d2f_dm2+2*(df_dm)**2-Td2T_dm2=-2.1*f*dT......
  • 数学建模习题7.7
    `importnumpyasnpimportmatplotlib.pyplotaspltfromscipy.optimizeimportcurve_fit,leastsq,least_squares定义函数g(x,a,b)defg(x,a,b):return(10*a)/(10*b+(a-10*b)*np.exp(a*np.sin(x)))初始参数a=1.1b=0.01生成数据x_values......
  • 数学建模习题7.4
    `importnumpyasnpimportmatplotlib.pyplotaspltfromscipy.interpolateimportgriddatadeff(x,y):x2=x2return(x2-2*x)*np.exp(-x2-y2-x*y)x_min,x_max=-3,3y_min,y_max=-4,4num_points=1000x_random=np.random.uniform(x_min,x_ma......
  • 数学建模习题7.3
    `importnumpyasnpimportmatplotlib.pyplotaspltfromscipy.interpolateimportinterp1d,CubicSpline已知的温度和对应的体积T_known=np.array([700,720,740,760,780])V_known=np.array([0.0977,0.1218,0.1406,0.1551,0.1664])需要求解的温度T_query=......