Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vyudu opened this issue Feb 10, 2025 · 2 comments
Open

Comments

@vyudu
Copy link
Member

vyudu commented Feb 10, 2025

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
@ErikQQY
Copy link
Member

ErikQQY commented Feb 11, 2025

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?

@ChrisRackauckas
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants