-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Summary
It seems like IFDIFF is currently not able to correctly handle nested functions in a RHS. Investigate the following example and implement a fix.
Example
ODE system
An example of a RHS with nested functions that will produce errors during preprocessing.
%%% nested functions are bad !!
function dx = switchedSystem1(t,x,p)
function out = q1(t)
out = 50/27*t.^2 - 100/3*t + 400/3;
end
function out = q2(t, x, p)
out = (1000 - x(2))*(p(1)*(t-19) + p(2));
end
dx = zeros(2,1);
if x(1) <= 750
dx(1) = q1(t);
else
dx(1) = q1(t) - q2(t,x,p);
end
if x(1) <= 750
dx(2) = 0;
else
if x(1) <= 800
dx(2) = -300;
else
dx(2) = 0;
end
end
Ideas for a potential fix
- Nested functions can probably be treated in the same way as the rest of the RHS, i.e. simply keep them and replace statements that induce control flow (i.e. if, abs, sign, etc.) with
ctrlif.- But consider if there could be any caveats. Do we need a
function_indexlike in external helper functions?
- But consider if there could be any caveats. Do we need a
- The source of the issue may be the fact that the first statement in the body of the RHS function is a function definition, which then causes something to go wrong when processing the mtree. However, this is still pure speculation and further investigation is required.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels