ODEINT 求解常微分方程(1)
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)的更多相关文章
- ODEINT 求解常微分方程(4)
import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt # function tha ...
- 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 ...
- 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++和面向对象数值计算>,代码简洁明快,采用类进行封装实现代码,增强代码的重用性,通过继承可实现代码的重用,采用函数指针,通用性增强,在函数改变时只需要单独改变函数部分的代码,无需 ...
随机推荐
- Nodejs模块使用
一.fs模块 (1)查看文件状态 fs.stat(path, callback) / statSync(path) (2)创建目录 fs.mkdir(path, callback) / mkdirSy ...
- 关于mysql中的锁总结
一.锁的基本信息: 共享锁(s):又称读锁.允许一个事务去读一行,阻止其他事务获得相同数据集的排他锁.若事务T对数据对象A加上S锁,则事务T可以读A但不能修改A,其他事务只能再对A加S锁,而不能加X锁 ...
- Redis-主从
主从复制过程 1.从服务器开始连接主服务器时,会向主服务器发送一个SYNC同步命令 2.主服务器接收到命令后,执行BGSAVE,异步的将写命令保存到一个缓冲区里 3.主服务器执行完BGSAVE之后,就 ...
- shiro认证通过之后的授权
subject.hasRole("") ; subject.hasRoles(List); subject.hasAllRoles(); subject.isPermitted(& ...
- vue过渡动画样式
在进入/离开的过渡中,会有 6 个 class 切换. v-enter:定义进入过渡的开始状态.在元素被插入之前生效,在元素被插入之后的下一帧移除. v-enter-active:定义进入过渡生效时的 ...
- 粒子群优化算法对BP神经网络优化 Matlab实现
1.粒子群优化算法 粒子群算法(particle swarm optimization,PSO)由Kennedy和Eberhart在1995年提出,该算法模拟鸟集群飞行觅食的行为,鸟之间通过集体的协作 ...
- sql语句中的删除操作
drop: drop table tb; 删除内容和定义,释放空间.简单来说就是把整个表去掉.以后不能再新增数据,除非新增一个表. truncate: truncate table tb; 删除内容. ...
- CentOS 安装 git2.x.x 版本
方法一 源码方式安装 第一步:卸载旧的git版本. $ yum remove git 第二步:下载git $ wget --no-check-certificate https://www.kerne ...
- GNS3配置问题(持续更新)
GNS3配置问题 1.关于All in One的GNS3提示"判断dynamips版本失败"的解决办法 当我们找到GNS3根目录里的dynamips.exe,执行会报错告诉我们缺少 ...
- 【已解决】Ubuntu U盘启动出现“Failed to load ldlinux.c32”问题
利用UltraISO制作了Ubuntu的U盘启动,在USB启动时出现了 Failed to load ldlinux.c32 Boot failed: please change disks and ...