Skip to content

Implementing a squarewave: Can’t take remainder of InfiniteOpt.GeneralVariableRef #337

Answered by pulsipher
codercahol asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @codercahol, sorry for the late response (I missed the notification for this post).

Like JuMP, InfiniteOpt is a symbolic optimization language where expressions like t % period < duty*period ? 1.0 : 0.0 are not readily supported (see https://jump.dev/JuMP.jl/stable/manual/nonlinear/#Supported-operators).

However, since your sqw function only depends on an infinite parameter, InfiniteOpt provides a way around this limitation via the use of a modeling object called a parameter function. Parameter functions provide a way to embed an arbitrary Julia function the takes infinite parameter(s) as input and outputs a single number.

In your case we can write:

function sqw(t; period::Float64=1, duty

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@codercahol
Comment options

Answer selected by codercahol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants