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

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…
import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt # function that returns dz/dt def model(z,t): dxdt = 3.0 * np.exp(-t) dydt = -z[1] + 3 dzdt = [dxdt,dydt] return dzdt # initial condition z0 = [0,0] # time points t…
import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt # function that returns dy/dt def model(y,t): # u steps from 0 to 2 at t=10 if t<10.0: u = 0 else: u = 2 dydt = (-y + u)/5.0 return dydt # initial condition y0 = 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 # f…
ode45函数无法求出解析解,dsolve可以求出解析解(若有),但是速度较慢. 1.      ode45函数 ①求一阶常微分方程的初值问题 [t,y] = ode45(@(t,y)y-2*t/y,[0,4],1); plot(t,y); 求解 y' – y + 2*t / y且初值y(0) = 1的常微分方程初值问题,返回自变量和函数的若干个值. 若不写返回值,则会自动作出函数随自变量的变化图像. ode45(@(t,y)y-2*t/y,[0,4],1); ②求解一阶微分方程组 x' = -…
#include<iostream> #include<iomanip> using namespace std; int main() { double x, y, h;      //,x为对应的每一步x的值,其中y为对应的每一步y的值 x = 0;      //对x赋初值 y = 1;      //对y赋初值 h = 0.1;      //步长设置为0.1 cout << setiosflags(ios::left); cout << setw(…
#include<iostream> #include<iomanip> using namespace std; int main() { double x,y,h,temp,f; x = 0;      //对x赋初值 y = 1;      //对y赋初值 h = 0.1;      //步长设置为0.1 cout << setiosflags(ios::left); cout << setw(20) << "y的计算值"…
#include<iostream> #include<iomanip> using namespace std; int main() { double x,y,yn,h,temp,f; x=0;      //对x赋初值 y=1;      //对y赋初值 h=0.1;      //步长设置为0.1 cout<<setiosflags(ios::left); cout<<setw(20)<<"y的计算值"; cout&l…
#include<iostream> #include<iomanip> using namespace std; int main() { double x,y,yn,h,temp; x=0;      //对x赋初值 y=1;      //对y赋初值 h=0.1;      //步长设置为0.1 cout<<setiosflags(ios::left); cout<<setw(20)<<"y的计算值"; cout<…
摘自<c++和面向对象数值计算>,代码简洁明快,采用类进行封装实现代码,增强代码的重用性,通过继承可实现代码的重用,采用函数指针,通用性增强,在函数改变时只需要单独改变函数部分的代码,无需对所有代码进行重写,对其中代码稍加改动,源代码有缺陷,没有释放内存,会造成内存泄露,在构造函数当中,将源代码的在函数体中赋值,改为列表赋值,可以稍微提高代码的执行效率. #include<iostream> #include <cmath> #include <algorithm…