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. 关于RAID小结

    独立硬盘冗余阵列(RAID, Redundant Array of Independent Disks),旧称廉价磁盘冗余阵列(Redundant Array of Inexpensive Disks ...

  2. iOS开发常用技能点(持续更新中。。。)

    1,以屏幕原点开始布局  (默认从导航栏原点布局) self.extendedLayoutIncludesOpaqueBars = YES;   2,向button发送点击事件 [self.playB ...

  3. Python之字符串中是否包含子串的几种方法

    #第一种方式 :in a='abcdaac' b='a' c='db' print(b in a) print(c in a)  预览结果 #第二种方式:count()方法 a='abcdefgab' ...

  4. 仿开源框架从零到一完整实现高性能、可扩展的RPC框架 | 6个月做成教程免费送

    去年年就在写一本付费小册,今年年初基本上就写完了,本来预计计划是春节上线结果由于平台的原因一直拖着没上.五一前跟平台联系给的反馈是五月份能上,结果平台又在重构,停止小册的申请和上线,最后我考虑了一下决 ...

  5. 掌握了Docker Layer Caching才敢自称精通Dockerfile

    长话短说: 本次原创将向您展示在Docker中使用Layer Cache以加快镜像构建. 这个话题的初衷在于:应用程序打包过程是很慢的(下载并安装框架&第三方依赖包.生成assets),这在D ...

  6. Python 绘制全球疫情地图

    国内疫情得到控制后,我就没怎么再关心过疫情,最近看到一条新闻,全球疫情累计确诊人数已经突破 500w 大关,看到这个数字我还是有点吃惊的. 思来想去,还是写一篇全球疫情的分析的文章,本文包括网络爬虫. ...

  7. web自动化之alert弹窗操作

    from selenium import webdriver from selenium.webdriver.support.wait import WebDriverWait from seleni ...

  8. equals()方法练习

    1: package com.aff.equals; public class TestOrder { public static void main(String[] args) { Order o ...

  9. Rocket - diplomacy - TransferSizes

    https://mp.weixin.qq.com/s/Sf0owQxWzxacVvykJZ5oTQ   介绍TransferSizes的实现.   ​​   1. 基本定义   从min到max的闭合 ...

  10. c#tcp多线程服务器实例代码

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...