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++和面向对象数值计算>,代码简洁明快,采用类进行封装实现代码,增强代码的重用性,通过继承可实现代码的重用,采用函数指针,通用性增强,在函数改变时只需要单独改变函数部分的代码,无需 ...
随机推荐
- java 精确加减
/** * 提供精确的加法运算. * @param v1 被加数 * @param v2 加数 * @return 两个参数的和 */ public double add(double v1, dou ...
- Oracle备份与恢复详解
http://www.360doc.com/content/10/1015/15/3267996_61218717.shtml --------摘自 360doc 为了能有效地备份和恢复数据库,建议大 ...
- Windows系统下Git的下载和配置
简介:Git是一款免费.开源的分布式版本控制系统,可记录文件每次改动,便于多人协作编辑. 下载:git-for-windows下载地址https://git-for-windows.github.io ...
- spring cloud系列教程第六篇-Eureka集群版
spring cloud系列教程第六篇-Eureka集群版 本文主要内容: 本文来源:本文由凯哥Java(kaigejava)发布在博客园博客的.转载请注明 1:Eureka执行步骤理解 2:集群原理 ...
- [JavaWeb基础] 021.Action中result的各种转发类型
在struts2中, struts.xml中result的类型有多种,它们类似于struts1中的forward,常用的类型有dispatcher(默认值).redirect.redirectActi ...
- [优文翻译]001.真正程序员该是什么样的(How To Be A Real Programmer)
01.Real Programmers don't write specs -- users should consider themselves lucky to get any programs ...
- for循环结构的使用
/* for循环格式: for(①初始化条件; ②循环条件 :③迭代部分){ //④循环体 } 执行顺序:①-②-④-③---②-④-③-----直至循环条件不满足 退出当前循环 * */ publi ...
- switch-case与if-else的转换
对学会成绩大于60分的,输出合格,低于60分的输出不合格 import java.util.Scanner; public class TestSwitch3 { public static void ...
- 04.Django-视图与路由
视图层 1. HTTP请求 HttpRequest对象 request.path #使用GET方法时,只会得到路径. request.get_full_path() #使用GET方法时,会得到包括路径 ...
- 50个SQL语句(MySQL版) 问题八
--------------------------表结构-------------------------- student(StuId,StuName,StuAge,StuSex) 学生表 tea ...