Skip to content

Add sgnsqr external function f(X) = sgn(x)*x^2 #3622

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

eslickj
Copy link
Contributor

@eslickj eslickj commented Jun 9, 2025

Fixes None

Summary/Motivation:

This adds a signed square function to the contributed external function demonstration.

Here is an example of where this can be useful.

Say you have a pressure-flow relationship that says the mass flow is proportional to the square root of pressure drop, where pa is inlet pressure and pb is outlet pressure. Like this: mdot^2 = k(pb - pa).

The direction of flow is forward if the pressure drop is positive or backward if the pressure drop is negative. There are both positive and negative solutions to the equation. If we use the proposed sgnsqr function, there is now only one solution to the equation, and the sign of flow matches the sign of pressure drop.

The sign squared function is still smooth and replacing square with sgnsqr still gives us solutions to the original equation. It just limits us to one correct solution instead of two possibilities. I expect there could be many situations where it would be useful to limit the solutions of y = x^2 to a single solution.

Changes proposed in this PR:

  • add sgnsqr external function to the ampl_external_demo library.

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

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

Successfully merging this pull request may close these issues.

1 participant