python利用scipy.integrate中的odeint方法解微分方程
一阶微分方程
dxdt+x=sin(t)\frac{\mathrm{dx}}{\mathrm{dt}}+x=\mathrm{sin}\left(t\right) dtdx+x=sin(t)
from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as pltdef func(y, t):x = ydx = -x+np.sin(t)return dxt = np.arange(0, 10, 0.001)
sol1 = odeint(func, [0], t)
fig = plt.figure(figsize=(16,8))
plt.plot(t, sol1[:,0], label='x')
plt.legend(fontsize=15)
plt.show()
二阶微分方程
以下面的方程为例
d2xdt2+dxdt+x=sin(t)\frac{d^2 x}{{\mathrm{dt}}^2 }+\frac{\mathrm{dx}}{\mathrm{dt}}+x=\mathrm{sin}\left(t\right) dt2d2x+dtdx+x=sin(t)
from scipy.integrate import odeint
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as pltdef func(y, t):x, dx = yd2x = [dx, -dx-x+np.sin(t)]return d2xt = np.arange(0, 10, 0.001)
sol1 = odeint(func, [0, 0], t)
fig = plt.figure(figsize=(16,8))
plt.plot(t, sol1[:,0])
plt.plot(t, sol1[:,1])
plt.show()
sol1 = odeint(func, [0, 0], t)中[0, 0]是传递给func函数的初始值,func是待解的方程。
二阶微分方程组
d2xdt2+ydxdt+x=sin(t)\frac{d^2 x}{{\mathrm{dt}}^2 }+y\frac{\mathrm{dx}}{\mathrm{dt}}+x=\mathrm{sin}\left(t\right) dt2d2x+ydtdx+x=sin(t)
d2ydt2+xdydt+y=1\frac{d^2 y}{{\mathrm{dt}}^2 }+x\frac{\mathrm{dy}}{\mathrm{dt}}+y=1 dt2d2y+xdtdy+y=1
from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as pltdef func(y, t):x, dx, z, dz = yd2q = [dx, -z*dx-x+np.sin(t), dz, -x*dz-z+1]return d2qt = np.arange(0, 10, 0.001)
sol1 = odeint(func, [0, 0, 0, 0], t)fig = plt.figure(figsize=(16,8))
plt.plot(t, sol1[:,0], label='x')
plt.plot(t, sol1[:,2], label='y')
plt.legend(fontsize=15)
plt.show()
sol1里对应着x,dx/dt,y,dy/dt
python利用scipy.integrate中的odeint方法解微分方程相关推荐
- 用python的scipy中的odeint来解常微分方程中的一些细节问题(适用于小白)
用python的scipy中的odeint来解常微分方程中的一些细节问题(适用于小白) 写在前面 最近有些需要解决常微分方程的问题,网上查了很多教程都不是很明晰,便自己研究了一段时间,写一点小白初次接 ...
- 利用pandas库中的read_html方法快速抓取网页中常见的表格型数据
利用pandas库中的read_html方法快速抓取网页中常见的表格型数据 本文转载自:https://www.makcyun.top/web_scraping_withpython2.html 需要 ...
- python 利用Scipy计算person 和spearman相关系数
python 利用Scipy计算person 和spearman相关系数 觉得有用的话,欢迎一起讨论相互学习~ 学习以下两位大佬的讲解 (Pearson)皮尔逊相关系数和spearman相关系数(附p ...
- Python(私有变量)类中的特殊方法
2019独角兽企业重金招聘Python工程师标准>>> 类中的特殊方法 一般说来,特殊的方法都被用来模仿某个行为.例如,如果你想要为你的类使用x[key]这样的索引操作(就像列表和元 ...
- python 文字语音朗读-python 利用pyttsx3文字转语音过程详解
这篇文章主要介绍了python 利用pyttsx3文字转语音过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 # -*- coding: ut ...
- python发音语言-python 利用pyttsx3文字转语音过程详解
这篇文章主要介绍了python 利用pyttsx3文字转语音过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下# -*- coding: utf ...
- python发音模块-python 利用pyttsx3文字转语音过程详解
这篇文章主要介绍了python 利用pyttsx3文字转语音过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 # -*- coding: ut ...
- python 语音朗读软件-python 利用pyttsx3文字转语音过程详解
这篇文章主要介绍了python 利用pyttsx3文字转语音过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 # -*- coding: ut ...
- matlab中使用ode方法解范德波尔微分方程的数值解
微分方程的解析解要求比较严苛,只有在特定的条件下才能写出解析解表达式,而在现实的科研问题当中,绝大多数情况我们会采用数值解(numeric solution)的方法来求解微分方程.这个时候就要用到od ...
最新文章
- 必须了解的 MySQL 三大日志
- Winform中实现将照片剪贴到系统剪切板中(附代码下载)
- 水下清淤机器人_新余市政管道清淤怎么收费2021-励志环保
- react列表元素hover
- k8s ready 不调度_从零开始学K8s: 10.在K8s上运行应用
- 使用Okta的单点登录保护您的Vert.x服务器
- 我的博客开张了!!!
- 家庭主机拨号上网示意图
- Java中JVM、JRE和JDK三者有什么区别和联系?
- css32D、3D、动画、过渡
- Python 列表 sort( )方法
- Linq连接查询之左连接、右连接、内连接、全连接、交叉连接、Union合并、Concat连接、Intersect相交、Except与非查询...
- python文件写入乱码_python写文件打开后是乱码
- 如何向github上传文件
- OpenJDK构建工具IcedTea 1.7发布
- 【微博简易爬虫】Python获取指定微博用户的发布文本
- 联想拯救者p7000C语言编译器,联想拯救者 刃7000P台式机装win10系统及bios设置方法...
- 苹果App Store 应用商店页面的优化技巧
- LightOJ1336(约数和)
- 向5岁小朋友解释什么是微服务