ex08ch4.m

来自「these codes are for solving OED with mat」· M 代码 · 共 34 行

M
34
字号
function sol = ex08ch4r = 0.5;c = 1/sqrt(2);options = ddeset('Jumps',[(1-c), 1, (2-c)],...                 'RelTol',1e-5,'AbsTol',1e-8);sol = dde23(@ddes,1,10,[0, 10],options,r,c);y10 = deval(sol,10);fprintf('DDE23 computed     y(10) =%15.11f.\n',y10);fprintf('Reference solution y(10) =%15.11f.\n',0.06302089869);plot(sol.x,sol.y)title(['Hoppensteadt-Waltman model with r = ',...       num2str(r),'.'])xlabel('time t')ylabel('y(t)')Ioft = -(1/r)*(sol.yp ./ sol.y);figureplot(sol.x,Ioft)title(['Hoppensteadt-Waltman model with r = ',...       num2str(r),'.'])xlabel('time t')ylabel('I(t)')%============================================================function v = ddes(t,y,Z,r,c)mu = r/10;if     t <= 1 - c   v = -r*y*0.4*(1 - t);elseif t <= 1   v = -r*y*(0.4*(1 - t) + 10 - exp(mu)*y);elseif t <= 2 - c   v = -r*y*(10 - exp(mu)*y);else   v = -r*exp(mu)*y*(Z - y);end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?