The issue I have is having to compute the derivative (in real time) of the solution produced by ode45 within the events function.
Some pseudo-code to explain what I'm mean is,
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
I know that if I didn't need to use the solution at the event within
myfunc I could just compute
dx=myfunc(t,x) within my event function and use
dx(2), yet since
xevent is used within
myfunc I can't input
I know there is a way of inputting constant parameters within the event function, but since it's the solution at the event location, which also changes, I'm not sure how to go about doing that.
My work around to this is to approximate
dx(2) using the solution
x. What I wanted to know is if it will be satisfactory to just use a finite difference approximation here, using a small fixed step size relative to the step size od45 takes, which is a variable step size.
Thanks for any help!