我遇到的问题是必须计算 ode45 在事件函数中生成的解决方案的导数(实时)。
一些伪代码来解释我的意思是,
function dx = myfunc(t,x,xevent)
persistent xevent
% xevent is the solution at the event
dx(1) = x(2);
dx(2) = complicated function of x(1),x(2), and xevent;
end
function [value,isterminal,direction] = myeventfcn(t,x)
position = function of x(1), x(2), and dx(2);
isterminal = 1;
direction = 0;
end
我知道,如果我不需要在事件中使用解决方案,myfunc
我可以dx=myfunc(t,x)
在我的事件函数中计算并使用dx(2)
,但由于在事件xevent
中使用,myfunc
我无法输入xevent
。
我知道有一种在事件函数中输入常量参数的方法,但由于它是事件位置的解决方案,它也会发生变化,我不知道该怎么做。
dx(2)
我的解决方法是使用解决方案来近似x
。我想知道的是,在这里仅使用有限差分近似是否令人满意,使用相对于 od45 采用的步长(可变步长)较小的固定步长。
谢谢你的帮助!