BoundaryValueDiffEq.jl
BoundaryValueDiffEq.jl copied to clipboard
Request: `minsol, maxsol` for finding the lowest/highest values of solutions
This would allow MTK to specify boundary constraints that look like [x(t) < 3], where we want every value of the solution to be less than 3. Thinking the codegen would look like
function ineqs!(resid, sol, p, t)
resid[1] = minsol(sol, (0., 1.)) - 3
end
I have not tested on a real problem, but since all the sol in boundary conditions are solution objects, it seems we can just do resid[1] = max(sol)-3?
That's not necessarily a good approximation and would converge as O(h) since it's equivalent to the maximum approximation given a linear interpolation. For a BVP intermediate solution, we don't just have a solution at points but a whole collocation polynomial. What you'd want to do is differentiate that polynomial w.r.t. t and solve for the roots. This can be done analytically ahead of time and stored. That would give the critical points. The maximum and minimum of the continuous solution is then O(h^n) approximated by the polynomial at the critical point. So then minsol(sol, (0., 1.)) would evaluate the interpolation at every interval at the critical points, and then take the min/max of the evaluated points.
We can start with just the discrete min/max as a starting point, but there are lots of scenarios where the latter would be much more accurate. And since this would be used for constraints, the more accurate form would likely be highly preferred down the line.