An example of using ODEINT is with the following differential equation with parameter k=0.3, the initial condition y0=5 and the following differential equation.


import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt # function that returns dy/dt
def model(y,t):
k = 0.3
dydt = -k * y
return dydt # initial condition
y0 = 5 # time points
[t,dt] = np.linspace(0,20,retstep=True) # solve ODE
y = odeint(model,y0,t) # another way to do
y1=np.empty_like(t)
y1[0]=y0 for i in range(len(t)-1):
y1[i+1]=y1[i]+dt*model(y1[i],t) # plot results
plt.plot(t,y1,label='y1')
plt.plot(t,y,label='y')
plt.xlabel('time')
plt.ylabel('y(t)')
plt.legend(loc='best')
plt.show()

ODEINT 求解常微分方程(1)的更多相关文章

  1. ODEINT 求解常微分方程(4)

    import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt # function tha ...

  2. ODEINT 求解常微分方程(3)

    import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt # function tha ...

  3. ODEINT 求解常微分方程(2)

    import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt # function tha ...

  4. MATLAB求解常微分方程:ode45函数与dsolve函数

    ode45函数无法求出解析解,dsolve可以求出解析解(若有),但是速度较慢. 1.      ode45函数 ①求一阶常微分方程的初值问题 [t,y] = ode45(@(t,y)y-2*t/y, ...

  5. 欧拉法求解常微分方程(c++)

    #include<iostream> #include<iomanip> using namespace std; int main() { double x, y, h;   ...

  6. 改进欧拉公式求解常微分方程(c++)

    #include<iostream> #include<iomanip> using namespace std; int main() { double x,y,h,temp ...

  7. 梯形法求解常微分方程(c++)

    #include<iostream> #include<iomanip> using namespace std; int main() { double x,y,yn,h,t ...

  8. 后退欧拉法求解常微分方程(c++)

    #include<iostream> #include<iomanip> using namespace std; int main() { double x,y,yn,h,t ...

  9. 欧拉法求解常微分方程(c++)【转载】

    摘自<c++和面向对象数值计算>,代码简洁明快,采用类进行封装实现代码,增强代码的重用性,通过继承可实现代码的重用,采用函数指针,通用性增强,在函数改变时只需要单独改变函数部分的代码,无需 ...

随机推荐

  1. IDEA将Maven项目中指定文件夹下的xml等文件编译进classes

    eclipse下面创建的Maven项目,使用mybatis.eclipse里面能正常启动,在idea中一直卡在maybatis 加载位置. 1.首先是不报错也没反应.这个时候需要我们重写SqlSess ...

  2. docker基本维护命令

    docker search centos ##查服务器上面的镜像:docker images ##查本地的镜像.docker pull centos ##拉镜像. docker run centos ...

  3. kali中安装漏洞靶场Vulhub(超详细)

    前言 我们都知道,在学习网络安全的过程中,搭建漏洞靶场有着至关重要的作用.复现各种漏洞,能更好的理解漏洞产生的原因,提高自己的学习能力.下面我在kali中演示如何详细安装漏洞靶场Vulhub. 什么是 ...

  4. jdk8 Collections#sort究竟做了什么

    前言 Collections#sort 追踪代码进去看,会调用到Arrays.sort,看到这里时,你肯定会想,这不是很简单,Arrays.sort在元素较少时使用插入排序,较多时使用快速排序,再多时 ...

  5. Golang源码学习:调度逻辑(二)main goroutine的创建

    接上一篇继续分析一下runtime.newproc方法. 函数签名 newproc函数的签名为 newproc(siz int32, fn *funcval) siz是传入的参数大小(不是个数):fn ...

  6. 关闭 WordPress 自动更新

    # 方法一 推荐!编辑 WordPress 网站目录下的 wp-config.php 文件,添加如下代码: define( 'AUTOMATIC_UPDATER_DISABLED', true ); ...

  7. FPGA开发工具套餐搭配推荐及软件链接 (更新于2020.03.16)

    一.Xilinx(全球FPGA市场份额最大的公司,其发展动态往往也代表着整个FPGA行业的动态) (1) Xilinx官方软件下载地址链接: https://china.xilinx.com/supp ...

  8. Golang源码学习:调度逻辑(三)工作线程的执行流程与调度循环

    本文内容主要分为三部分: main goroutine 的调度运行 非 main goroutine 的退出流程 工作线程的执行流程与调度循环. main goroutine 的调度运行 runtim ...

  9. windows环境下Kubernetes及Docker安装(那些坑)

    k8s 和 Docker容器技术,当前非常流行的技术. 让人日狗的是,   这套技术栈对CN的donet 程序员不怎么友好.娓娓道来,1. 好多镜像都是需要梯子才能访问: 2. window程序员天生 ...

  10. Android_四大组件之BroadcastReceiver

    一.概述 BroadcastReceiver是广播接收器,接收来自 系统或应用发出的广播信息 并进行相应的逻辑处理. 自定义BroadcastReceiver只需继承android.content.B ...