BoundaryValueDiffEq.jl icon indicating copy to clipboard operation
BoundaryValueDiffEq.jl copied to clipboard

Request: `minsol, maxsol` for finding the lowest/highest values of solutions

Open vyudu opened this issue 9 months ago • 2 comments

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

vyudu avatar Feb 10 '25 14:02 vyudu

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?

ErikQQY avatar Feb 11 '25 18:02 ErikQQY

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.

ChrisRackauckas avatar Feb 11 '25 19:02 ChrisRackauckas