MATLAB ode45 OutputFcn监控中频回路的变化值
我试图保存/查看在ode45微分方程求解过程中被if循环更改的变量mMATLAB ode45 OutputFcn监控中频回路的变化值,matlab,variables,output,ode45,Matlab,Variables,Output,Ode45,我试图保存/查看在ode45微分方程求解过程中被if循环更改的变量m %Some parameter setting above myfun=fprintf('m', num2str(m)) options = odeset('NonNegative',[1:3],'RelTol',1e-5,'AbsTol',1e-8, 'OutputFcn', @myfun); [t,x] = ode45('myfunction', tspan, x0, options); %calculation if循
%Some parameter setting above
myfun=fprintf('m', num2str(m))
options = odeset('NonNegative',[1:3],'RelTol',1e-5,'AbsTol',1e-8, 'OutputFcn', @myfun);
[t,x] = ode45('myfunction', tspan, x0, options); %calculation
if循环位于方程式文件中,所有其他方程式如下所示:
if x(1)>=threshold
m=1 ;
return
else
m=0 ;
end
我已经看过了ode45的OutputFcn选项的matlab描述,并阅读了
没有正确理解它。我也愿意使用其他解决方案来“查看”ode计算期间m的值。创建一个单独的文件,并使用以下代码将其称为
myOutputFcn.m
function status = myOutputFcn(t,y,flag,threshold)
switch(flag)
case 'init' % code to run before integration
;
case '' % code to run after each integration step
% act on state
if y(1)>=threshold
m = 1;
else
m = 0;
end
% print m
fprintf('% 4.3f\t%i, t, m\n',t,m);
case 'done' % code to run when integation is finished
;
end
status = 0; % need to set status, otherwise integration will halt
end
然后,要在每次迭代中使用正确的阈值调用此输出函数,必须执行以下操作
threshold = 10; % idk, your threshold
options = odeset('NonNegative',[1:3],'RelTol',1e-5,'AbsTol',1e-8, 'OutputFcn', @(t,y,flag) myOutputFcn(t,y,flag,threshold));
[t,x] = ode45('myfunction', tspan, x0, options); %calculation
您问题中的链接不是针对
ode
相关输出函数的,请参阅有关ode outputFcnThanks的相关信息,我已经研究了此链接。我刚才提到了上面的第一个链接,因为我看到它推荐了一个关于OutputFCSensory的类似问题,我可以在周末测试你的代码。非常感谢@rinkert这是我最初打算做的:D它帮助了我很多。也谢谢你在小脚本中的评论,所以我大致了解了哪个部分在做什么。