首页 > 其他分享 >8.4 8.5

8.4 8.5

时间:2024-11-17 23:31:41浏览次数:1  
标签:dm span 8.4 title sol plt import 8.5

8.4

点击查看代码
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp

def system(t, state):
    x, y = state
    dxdt = -x*3 - y
    dydt = x - y*3
    return [dxdt, dydt]

t_span = (0, 30)
y0 = [1, 0.5]

sol = solve_ivp(system, t_span, y0, t_eval=np.linspace(t_span[0], t_span[1], 1000))

x = sol.y[0]
y = sol.y[1]
t = sol.t

plt.figure(figsize=(12, 6))

plt.subplot(1, 2, 1)
plt.plot(t, x, label='x(t)')
plt.xlabel('t')
plt.ylabel('x(t)')
plt.title('x(t) vs t')
plt.legend()
plt.grid(True)

plt.subplot(1, 2, 2)
plt.plot(t, y, label='y(t)')
plt.xlabel('t')
plt.ylabel('y(t)')
plt.title('y(t) vs t')
plt.legend()
plt.grid(True)

plt.figure(figsize=(6, 6))
plt.plot(x, y, label='Phase Trajectory')
plt.xlabel('x')
plt.ylabel('y')
plt.title('Phase Plane (x, y)')
plt.legend()
plt.grid(True)
plt.axis('equal')

plt.tight_layout()
plt.show()

print("3010")

7.5

点击查看代码
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.1*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]

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

标签:dm,span,8.4,title,sol,plt,import,8.5
From: https://www.cnblogs.com/zhhhhha/p/18551391

相关文章

  • 数学建模习题8.5
    `importnumpyasnpimportmatplotlib.pyplotaspltfromscipy.integrateimportsolve_ivp定义微分方程模型defmodel(t,y):f,df_dm,d2f_dm2,T,dT_dm=yd3f_dm3=-3*f*d2f_dm2+2*(df_dm)**2-Td2T_dm2=-2*f*dT_dmreturn[df_dm,d2f_dm2,d3f_dm......
  • 习题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......
  • 数学建模习题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......
  • 8.4
    importnumpyasnpfromscipy.integrateimportsolve_ivpimportmatplotlib.pyplotaspltdefdifferential_equations(t,z):x,y=zdx_dt=-x**3-ydy_dt=x-y**3return[dx_dt,dy_dt]z0=[1,0.5]t_span=(0,30)sol=solve_ivp(differential_eq......
  • 详解连接 MySQL8.4 出现 Client does not support authentication protocol requested
    文章目录项目场景问题描述原因分析解决方案方案一(不推荐)方案二(推荐)总结项目场景在开发过程中,我们在Node.js项目中使用MySQL数据库,并且通过typeorm和mysql库进行数据库连接。然而,在项目启动时,遇到了数据库连接失败的问题,导致项目无法正常运行。问题描述......
  • 8.4
    importnumpyasnpimportpandasaspdimportsympyasspsp.init_printing(use_latex=True)fromscipy.integrateimportodeintimportmatplotlib.pyplotaspltplt.rcParams['font.sans-serif']=['TimesNewRoman+SimSun+WFMSansSC']pl......
  • 8.4 求微分方程组的数值解 x'=-x^3-y,x(0)=1,y'=x-y^3,y(0)=0.5,0<=t<=30,要求画出x(t)和
    importnumpyasnpimportmatplotlib.pyplotaspltfromscipy.integrateimportsolve_ivpdefsystem(t,state):x,y=statedxdt=-x3-ydydt=x-y3return[dxdt,dydt]t_span=(0,30)y0=[1,0.5]sol=solve_ivp(system,t_span,y0,t_eval=np.linsp......
  • 基于Centos7.X部署mysql8.4集群(主备)
    1、目标    将在主库的数据变更同步到从库,从而保证主库和从库的数据一致。2、原理    2.1主库会把数据变更记录在二进制日志文件Binlog中    2.2从库连接主库,读取binlog日志,并写入自身中继日志relaylog    2.3slave重做中继日志,将改变......