ODEINT 求解常微分方程(4)

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)的更多相关文章
- ODEINT 求解常微分方程(3)
import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt # function tha ...
- ODEINT 求解常微分方程(2)
import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt # function tha ...
- ODEINT 求解常微分方程(1)
An example of using ODEINT is with the following differential equation with parameter k=0.3, the ini ...
- MATLAB求解常微分方程:ode45函数与dsolve函数
ode45函数无法求出解析解,dsolve可以求出解析解(若有),但是速度较慢. 1. ode45函数 ①求一阶常微分方程的初值问题 [t,y] = ode45(@(t,y)y-2*t/y, ...
- 欧拉法求解常微分方程(c++)
#include<iostream> #include<iomanip> using namespace std; int main() { double x, y, h; ...
- 改进欧拉公式求解常微分方程(c++)
#include<iostream> #include<iomanip> using namespace std; int main() { double x,y,h,temp ...
- 梯形法求解常微分方程(c++)
#include<iostream> #include<iomanip> using namespace std; int main() { double x,y,yn,h,t ...
- 后退欧拉法求解常微分方程(c++)
#include<iostream> #include<iomanip> using namespace std; int main() { double x,y,yn,h,t ...
- 欧拉法求解常微分方程(c++)【转载】
摘自<c++和面向对象数值计算>,代码简洁明快,采用类进行封装实现代码,增强代码的重用性,通过继承可实现代码的重用,采用函数指针,通用性增强,在函数改变时只需要单独改变函数部分的代码,无需 ...
随机推荐
- 【蓝桥杯C/C++组】备赛基础篇之差分算法
一.个人理解 前面学习了前缀和算法,对于访问任意区间的速度是比较快的,但如果我们要修改某个区间的数呢,对于前缀和算法来说这还是有点棘手. 所以我们来学学新的算法:差分算法! 前缀和数组储存的是前n个数 ...
- mysql小白系列_08 zabbix添加自定义监控项items和触发器
监控mysql存活 1.配置agent自定义参数 vi /usr/local/zabbix/etc/zabbix_agentd.conf Include=/usr/local/zabbix/etc/z ...
- C# 数据操作系列 - 13 SugarSql初探
0. 前言 前言,暂时挥别NHibernate(虽然我突然发现这玩意还挺有意思的,不过看得人不多).大步进入了有很多小伙伴向我安利的SQLSugar,嗯,我一直叫SugarSQL,好像是这个吧? 这是 ...
- oracle 多表连接查询 join
转 简介: 多表连接查询通过表之间的关联字段,一次查询多表数据. 下面将依次介绍 多表连接中的如下方法: 1.from a,b 2.inner join 3.left outer join 4.rig ...
- Web前端:1、HTML&CSS概述及结构
万维网联盟(World Wide Web Consortium)简称W3C,专门为了定义网页相关的标准而成立,如网页中的HTML.CSS.DOM.HTTP.XML等标准. 根据W3C标准,一个网页主要 ...
- SpringBoot外部化配置使用Plus版
本文如有任何纰漏.错误,请不吝指正! PS: 之前写过一篇关于SpringBoo中使用配置文件的一些姿势,不过嘛,有句话(我)说的好:曾见小桥流水,未睹观音坐莲!所以再写一篇增强版,以便记录. 序言 ...
- Asp.Net Core入门之配置文件
ASP.NET Core配置框架已内建支持 JSON.XML 和 INI 配置文件,内存配置(直接通过代码设置值),环境变量配置等方式配置参数. 本文主要和大家讲一下我们在项目中常用的以配置文件的方式 ...
- xshell行号显示
xshell显示行号: 输入命令: vim ~/.vimrc 输入: set nu 之后在打开文件 就可以 看到行号显示.
- SpringBoot整合SpringSecurity实现JWT认证
目录 前言 目录 1.创建SpringBoot工程 2.导入SpringSecurity与JWT的相关依赖 3.定义SpringSecurity需要的基础处理类 4. 构建JWT token工具类 5 ...
- Linux显示行号设置
linux显示行号设置 第一步,打开vim vi ~/.vimrc 第二步,在该文件中加入一行,命令如下: set nu # 显示行号 set nonu # 不显示行号 微信公众号:喵哥解说 公众号介 ...