
%DDEX1 Example 1 for DDE23.
% This is a simple example of Wille' and Baker that illustrates the
% straightforward formulation, computation, and plotting of the solution
% of a system of delay differential equations (DDEs).
%
% The differential equations
%
%y'_1(t) = y_1(t-1)
%y'_2(t) = y_1(t-1)+y_2(t-0.2)
%y'_3(t) = y_2(t)
%
% are solved on [0, 5] with history y_1(t) = 1, y_2(t) = 1, y_3(t) = 1 for
% t <= 0.
%
% The lags are specified as a vector [1, 0.2], the delay differential
% equations are coded in the subfunction DDEX1DE, and the history is
% evaluated by the function DDEX1HIST. Because the history is constant it
% could be supplied as a vector:
% sol = dde23(@ddex1de,[1, 0.2],ones(3,1),[0, 5])
%
% See also DDE23, FUNCTION_HANDLE.
% Jacek Kierzenka, Lawrence F. Shampine and Skip Thompson
% Copyright 1984-2004 The MathWorks, Inc.
% $Revision: 1.2.4.2 $ $Date: 2005/06/21 19:24:16 $
sol = dde23(@ddex1de,[1, 0.2],@ddex1hist,[0, 5])
figure
plot(sol.x,sol.y)
title('An example of Wille'' and Baker.')
xlabel('time t')
ylabel('solution y')
% --------------------------------------------------------------------------
function s = ddex1hist(t)
% Constant history function for DDEX1.
s = ones(3,1)
% --------------------------------------------------------------------------
function dydt = ddex1de(t,y,Z)
% Differential equations function for DDEX1.
ylag1 = Z(:,1)
ylag2 = Z(:,2)
dydt = [ ylag1(1)
ylag1(1) + ylag2(2)
y(2) ]
可以借助于嵌套函数或匿名函数实现附加参数的传递,例如functionmainy0=[1.40.10.1]A=linspace(eps,10,20)Y=A*NaNforii=length(A)a=A(ii)y=ode45(@eq2,[0a],y0)Y(ii)=y(end,1)endplot(A,Y)functiondy=eq2(t,y)dy=y*0dy(1)=-(a*y(2))/(4*exp(a*t/4))dy(2)=-(a/4)*(exp(a*t/4))*(y(1)+0.5)+(a/4)*y(2)-y(3)*((exp(a*t/4))^2)dy(3)=4*y(2)endend但微分方程组似乎是刚性的,不过换用ode15s、ode23s等适合刚性系统的算法效果也不理想(可以调用ode*函数时不返回参数,观察求解的过程)。欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)