import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt # function that returns dz/dt
def model(z,t,u):
x = z[0]
y = z[1]
dxdt = (-x + u)/2.0
dydt = (-y + x)/5.0
dzdt = [dxdt,dydt]
return dzdt # initial condition
z0 = [0,0] # number of time points
n = 401 # time points
t = np.linspace(0,40,n) # step input
u = np.zeros(n)
# change to 2.0 at time = 5.0
u[51:] = 2.0 # store solution
x = np.empty_like(t)
y = np.empty_like(t)
# record initial conditions
x[0] = z0[0]
y[0] = z0[1] # solve ODE
for i in range(1,n):
# span for next time step
tspan = [t[i-1],t[i]]
# solve for next step
z = odeint(model,z0,tspan,args=(u[i],))
# store solution for plotting
x[i] = z[1][0]
y[i] = z[1][1]
# next initial condition
z0 = z[1] # plot results
plt.plot(t,u,'g:',label='u(t)')
plt.plot(t,x,'b-',label='x(t)')
plt.plot(t,y,'r--',label='y(t)')
plt.ylabel('values')
plt.xlabel('time')
plt.legend(loc='best')
plt.show()

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

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

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

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

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

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

    An example of using ODEINT is with the following differential equation with parameter k=0.3, the ini ...

  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. 微信小程序上传文件时弹出当前系统代理不是安全代理,是否信任

    我的开发环境是.net core 启用了https,而微信的开发者工具不认这个证书. 解决办法1:关闭https 然后在 Startup.cs 中关闭注释掉 app.UseHttpsRedirecti ...

  2. webpack指南(一)HRM+Tree Shaking

    参考:https://www.cnblogs.com/PasserByOne/p/12084323.html https://blog.csdn.net/qq593249106/article/det ...

  3. XShell 评估到期

    刚刚打开XShell弹出”评估到期“,点击确定后自动打开中文官网,得购买后才能使用. 当初下载的时候没留意到会有这一天.. 手头拮据的朋友可以通过下面方法绕过: 删除XShell. 到英文官网下载页找 ...

  4. MySQL 数据库的基本使用

    MySQL 是一个关系型数据库管理系统,由瑞典 MySQL AB 公司开发,而MySQL AB 公司被 Oracle 公司收购,故 MySQL 现在属于 Oracle 公司.MySQL 是一种关联数据 ...

  5. AJAX一

    一.http协议 1.URL http://www.baidu.com/md/index.html 结构:协议+主机名称+目录结构+文件名称 URL完整的结构 <scheme>://< ...

  6. MySQL索引及查询优化

    mysql 索引 1.索引介绍 索引按数据结构分可分为哈希表,有序数组,搜索树,跳表: 哈希表适用于只有等值查询的场景 有序数组适用于有等值查询和范围查询的场景,但有序数组索引的更新代价很大,所以最好 ...

  7. Django之form.Form字段校验

    RegexValidator校验器: 在自定义的form组件类设置字段validators的值,引入RegexValidator模块 from django import forms from dja ...

  8. DPDK Mbuf Library(学习笔记)

    1 Mbuf库 Mbuf库提供了分配和释放缓冲区(mbufs)的功能,DPDK应用程序可以使用这些mbufs来存储消息缓冲. 消息缓冲存储在内存池中,使用Mempool库. 数据结构rte_mbuf通 ...

  9. IDEA三种注释详解

    三种注释方式 行注释.块注释.方法或类说明注释. 一.快捷键:Ctrl + / 使用Ctrl+ /, 添加行注释,再次使用,去掉行注释 二.演示代码 if (hallSites != null &am ...

  10. [Android应用开发] 04.页面跳转和数据传输

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...