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. React:Lifting State Up

    在学习React的组件的时候,我也好奇组件间需要共享状态或通信的时候,React是如何处理的.在文档的QUICK START的提到Lifting State Up(状态提升),并不是什么新鲜东西.只是 ...

  2. P5410 【模板】扩展 KMP

    P5410 [模板]扩展 KMP #include<bits/stdc++.h> using namespace std; ; int q, nxt[maxn], extend[maxn] ...

  3. 模板:JSP公共内容

    page页面标签指令 <%@ page %> taglib标准标签指令 <%@ taglib %> 标签内基本属性 language="设置JSP页面使用的语言&qu ...

  4. CentOS7初始化服务器开发环境——根据个人习惯而定

    目录 修改hostname 创建个人账户和组 修改hostname 编辑主机名称,注意:执行以下指令,无需重启服务器,因为此指令实时写入linux 内核 hostnamectl --static se ...

  5. 使用Buildpacks高效构建Docker镜像

    1. 前言 Spring Boot 2.3.0.RELEASE 正式发布了几天了,其中有个新的特性:可以将Spring Boot应用代码直接打包为Docker镜像.这是什么科技?我赶紧去官网查了一番才 ...

  6. 4.Linux的目录结构

    Linux的目录结构 (1)"/"目录 Linux文件系统的入口,也是出于最高一级的目录 (2)"/bin" 基础系统所需要的那些命令位于此目录.也是最小系统所 ...

  7. 没找到工作的Java软件工程师是屌丝中的屌丝啊

    Java软件开发的工作咋就那么难找呢?

  8. [PHP学习教程 - 文件]001.高速读写大数据“二进制”文件,不必申请大内存(Byte Block)

    引言:读写大“二进制”文件,不必申请很大内存(fopen.fread.fwrite.fclose)!做到开源节流,提高速度! 每天告诉自己一次,『我真的很不错』.... 加速读写大文件,在实际工作过程 ...

  9. String类的内存解析

    package com.aff.equals; public class TestString { public static void main(String[] args) { String st ...

  10. nodejs版本代码注释率统计上新啦~~~

    github链接在这 Installation $ npm install jscrs -g Usage $ npx jscrs or $ jscrs options 不建议使用自定义配置 confi ...