Matlab “事件”的倍频程错误
我使用odepkg 0.8.4以八度音阶运行代码。第一个名为'poin2.m'的.m文件用于获取庞加莱图。此文件中的ode45命令调用“spp.m”函数Matlab “事件”的倍频程错误,matlab,octave,Matlab,Octave,我使用odepkg 0.8.4以八度音阶运行代码。第一个名为'poin2.m'的.m文件用于获取庞加莱图。此文件中的ode45命令调用“spp.m”函数 clc;clear; OMEG=1.02; trans=2000; N=2000; xfin=zeros(N+1,2); options=odeset('RelTol',1e-9,'AbsTol',1e-9,'events','on'); xin=0.2; xdin=-0.2; for i=1:trans if rem(i,50)=
clc;clear;
OMEG=1.02;
trans=2000;
N=2000;
xfin=zeros(N+1,2);
options=odeset('RelTol',1e-9,'AbsTol',1e-9,'events','on');
xin=0.2;
xdin=-0.2;
for i=1:trans
if rem(i,50)==0
disp(i);
end
[t,x,te,xe,ie]=ode45('spp',[0 2*pi/OMEG],[xin xdin],options);
xin=x(end,1);
xdin=x(end,2);
end
xfin(1,1)=xin;
xfin(1,2)=xdin;
disp('Steady state starts');
for i=1:N
if rem(i,50)==0
disp(i);
end
[t,x,te,xe,ie]=ode45('spp',[0 2*pi/OMEG],[xin xdin],options);
xin=x(end,1);
xdin=x(end,2);
xfin(i+1,1)=x(end,1);
xfin(i+1,2)=x(end,2);
end
function [xdot,isterminal,dircn]=spp(t,x,flag)
omega=1.02;
alpha=-0.01;q0=0.01;zhi=0.07;epsilon1=0.7;epsilon2=0.005;%epsilon2=0;temp=1;
if nargin<3 || isempty(flag)
if x(1)>1
fh=x(1)-(1-alpha);
elseif x(1)<-1
fh=x(1)+(1-alpha);
else
fh=alpha*x(1);
end
xdot=[x(2);-2*zhi*x(2)-(1+2*epsilon2*cos(omega*t))*fh+q0+(omega^2)*epsilon1*cos(omega*t);];
else
switch flag
case 'events'
xdot=x(1)^2-1;
isterminal=0;
dircn=0;
otherwise
error('function not programmed');
end;
end;
函数“spp.m”包含要与所需的“事件”函数集成的分段线性ODE
clc;clear;
OMEG=1.02;
trans=2000;
N=2000;
xfin=zeros(N+1,2);
options=odeset('RelTol',1e-9,'AbsTol',1e-9,'events','on');
xin=0.2;
xdin=-0.2;
for i=1:trans
if rem(i,50)==0
disp(i);
end
[t,x,te,xe,ie]=ode45('spp',[0 2*pi/OMEG],[xin xdin],options);
xin=x(end,1);
xdin=x(end,2);
end
xfin(1,1)=xin;
xfin(1,2)=xdin;
disp('Steady state starts');
for i=1:N
if rem(i,50)==0
disp(i);
end
[t,x,te,xe,ie]=ode45('spp',[0 2*pi/OMEG],[xin xdin],options);
xin=x(end,1);
xdin=x(end,2);
xfin(i+1,1)=x(end,1);
xfin(i+1,2)=x(end,2);
end
function [xdot,isterminal,dircn]=spp(t,x,flag)
omega=1.02;
alpha=-0.01;q0=0.01;zhi=0.07;epsilon1=0.7;epsilon2=0.005;%epsilon2=0;temp=1;
if nargin<3 || isempty(flag)
if x(1)>1
fh=x(1)-(1-alpha);
elseif x(1)<-1
fh=x(1)+(1-alpha);
else
fh=alpha*x(1);
end
xdot=[x(2);-2*zhi*x(2)-(1+2*epsilon2*cos(omega*t))*fh+q0+(omega^2)*epsilon1*cos(omega*t);];
else
switch flag
case 'events'
xdot=x(1)^2-1;
isterminal=0;
dircn=0;
otherwise
error('function not programmed');
end;
end;
“poin2.m”中的第12行实际上是发布的第一个代码中的第6行。我在“事件”中搜索了很多这个问题,但没有找到解决方案。有人能帮我吗?我想您可能使用了一种过时的方法来使用odeset–PDF指定事件函数。您使用的是什么文档?另外,由于分段元素的存在,你的方程非常复杂。除非您使用事件功能仔细地集成到分段元素发生变化的状态,否则您可能应该寻找一个刚性解算器Matlab可能是比octave更好/更容易的选择。无论如何,将代码更改为您提供的链接中的样式是可行的。谢谢!