matlab定步长ode,[转载]matlab ode45 函数传自定义参数用法及定步长ode
要用的时候总是忘记,这回给把它写在这里!
%%程序1
arg1 = 2;
arg2 = 1;
[T,Y] = ode45('vdp1000',[0 10],[2 0], [], arg1, arg2);
plot(T,Y(:,1),'-o');
%%程序2
function dy = vdp1000(t, y, flag, arg1, arg2)
dy =
zeros(2,1); %
a column vector
dy(1) = y(2);
dy(2) = arg1*(arg2 - y(1)^2)*y(2) - y(1);
%%ode5
function Y = ode5(odefun,tspan,y0,varargin)
%ODE5 Solve differential equations with a non-adaptive method of
order 5.
% Y = ODE5(ODEFUN,TSPAN,Y0) with TSPAN = [T1, T2, T3, ... TN]
integrates
% the system of differential equations y' = f(t,y) by stepping from
T0 to
% T1 to TN. Function ODEFUN(T,Y) must return f(t,y) in a column
vector.
% The vector Y0 is the initial conditions at T0. Each row in the
solution
% array Y corresponds to a time specified in TSPAN.
%
% Y = ODE5(ODEFUN,TSPAN,Y0,P1,P2...) passes the additional
parameters
% P1,P2... to the derivative function as
ODEFUN(T,Y,P1,P2...).
% This is a non-adaptive solver. The step sequence is determined by
TSPAN
% but the derivative function ODEFUN is evaluated multiple times
per step.
% The solver implements the Dormand-Prince method of order 5 in a
general
% framework of explicit Runge-Kutta methods.
%
% Example
% tspan = 0:0.1:20;
% y = ode5(@vdp1,tspan,[2 0]);
% plot(tspan,y(:,1));
% solves the system y' = vdp1(t,y) with a constant step size of
0.1,
% and plots the first component of the solution.
if ~isnumeric(tspan)
error('TSPAN
should be a vector of integration steps.');
end
if ~isnumeric(y0)
error('Y0
should be a vector of initial conditions.');
end
h = diff(tspan);
if any(sign(h(1))*h <= 0)
error('Entries of TSPAN are not in order.')
end
try
f0 =
feval_r(odefun,tspan(1),y0,varargin{:});
catch
msg =
['Unable to evaluate the ODEFUN at t0,y0. ',lasterr];
error(msg);
end
y0 = y0(:); % Make a column vector.
if ~isequal(size(y0),size(f0))
error('Inconsistent sizes of Y0 and f(t0,y0).');
end
neq = length(y0);
N = length(tspan);
Y = zeros(neq,N);
% Method coefficients -- Butcher's tableau
%
% C | A
% --+---
% | B
C = [1/5; 3/10; 4/5; 8/9; 1];
A = [ 1/5, 0, 0, 0, 0
3/40, 9/40, 0, 0, 0
44/45 -56/15, 32/9, 0, 0
19372/6561, -25360/2187, 64448/6561, -212/729, 0
9017/3168, -355/33, 46732/5247, 49/176, -5103/18656];
B = [35/384, 0, 500/1113, 125/192, -2187/6784, 11/84];
% More convenient storage
A = A.';
B = B(:);
nstages = length(B);
F = zeros(neq,nstages);
Y(:,1) = y0;
for i = 2:N
ti =
tspan(i-1);
hi =
h(i-1);
yi =
Y(:,i-1);
% General
explicit Runge-Kutta framework
F(:,1) =
feval_r(odefun,ti,yi,varargin{:});
for stage =
2:nstages
tstage = ti + C(stage-1)*hi;
ystage = yi + F(:,1:stage-1)*(hi*A(1:stage-1,stage-1));
F(:,stage) = feval_r(odefun,tstage,ystage,varargin{:});
end
Y(:,i) = yi
+ F*(hi*B);
end
Y = Y.';
matlab定步长ode,[转载]matlab ode45 函数传自定义参数用法及定步长ode相关推荐
- C++给函数传数组参数C++给函数传数组参数
C++给函数传数组参数 在C++中,如果要给一个函数传入一个数组,一般都是传入两个参数一个数组指针和一个数组大小 例: void print_1 (int n, int *datas ) { ...
- lyapunov函数 matlab,科学网-[转载]Matlab的Lyapunov、Sylvester和Riccati方程的Matlab求解-吴雄君的博文...
一.连续Lyapunov方程连续Lyapunov方程可以表示为 Lyapunov方程来源与微分方程稳定性理论,其中要求C为对称正定的n×n方阵,从而可以证明解X亦为n×n对称矩阵,这类方程直接求解比较 ...
- MATLAB阶段性方程组,[转载]matlab 解方程组
1.解方程 最近有多人问如何用matlab解方程组的问题,其实在matlab中解方程组还是很方便的,例如,对于代数方程组Ax=b(A为系数矩阵,非奇异)的求解,MATLAB中有两种方法: (1)x=i ...
- matlab水汽计算公式,[转载]matlab 解方程组
1.解方程 最近有多人问如何用matlab解方程组的问题,其实在matlab中解方程组还是很方便的,例如,对于代数方程组Ax=b(A为系数矩阵,非奇异)的求解,MATLAB中有两种方法: (1)x=i ...
- matlab灰度归一化,[转载]matlab图像处理为什么要归一化和如何归一化?
matlab图像处理为什么要归一化和如何归一化?一.为什么归一化 1. 基本上归一化思想是利用图像的不变矩寻找一组参数使其能够消除其他变换函数对图像变换的影响.也就是转换成唯一的标准形式以抵抗仿射变换 ...
- matlab二进制操作,[转载]Matlab二进制类型数据相关操作
Matlab逻辑运算 &: 逻辑与 A&B 返回值:当A.B中元素均为非零元素是,返回1,否则,为0,还可表示成and(a,b); | :逻辑或 A|B.还可以表示成or(A,B). ...
- python调用c函数传字符串参数_Python使用ctypes模块调用DLL函数之传递数值、指针与字符串参数...
在Python语言中,可以使用ctypes模块调用其它如C++语言编写的动态链接库DLL文件中的函数,在提高软件运行效率的同时,也可以充分利用目前市面上各种第三方的DLL库函数,以扩充Python软件 ...
- vant 组件库中的 图片上传组件(多张图片上传,删除图片传自定义参数)
html部分 js部分 图片上传前,限制图片格式.图片上传后,上传七牛云接口返回图片url,赋值给图片路径变量. 图片删除 坑:vant上传组建中内置的删除事件,默认携带两个参数,file和detai ...
- matlab 比较日期,[转载][Matlab]关于时间的函数的不完全总结
一.日期和时间 三种表示格式 (1)日期字符串: NowDate=date NowDate = 08-Aug-2008 year(NowDate) %提取日期的年份 ans = 2008 (2)连续的 ...
最新文章
- oracle sqlstate 22023,DB2 开发常遇到一些错误
- MongoError: topology was destroyed解决方法
- php serialize unserialize 数据序列化 与 反序列化
- 图像处理之简单脸谱检测算法
- 多项目同步进行“交叉编译”
- 蚂蚁金服发布「定损宝」,推动图像定损技术在车险领域的应用
- Python初识与简介【开篇】
- 软件测试用例编号命名规则,在TD的测试用例中显示测试用例编号的方法
- 人人译视界 for Mac(智能协同翻译)
- python求excel的最大行_解决使用Pandas 读取超过65536行的Excel文件问题
- gerund - 动名词
- iOS开发证书、bundle ID、App ID、描述文件、p12文件,及企业证书打包发布详述
- 计算机网络(十九)其他IP相关技术
- pbl和sbl_探讨:PBL教学法
- rk1808交叉编译opencv_ubuntu16.04交叉编译opencv 移植到rk1808上
- 中兴通讯提前批综合面试
- 并发容器J.U.C -- AQS组件(一)
- STM32学习 基于STM32F103C8t6
- AAC音频格式详解和实战解析
- Abaqus2021关联Solidworks2022成功方法