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

**URL:** https://discourse.julialang.org/t/implementing-a-squarewave-cant-take-remainder-of-infiniteopt-generalvariableref/111955
**Category:** Optimization (Mathematical)
**Tags:** question, infiniteopt
**Created:** [March 21, 2024, 10:16pm UTC](https://discourse.julialang.org/t/implementing-a-squarewave-cant-take-remainder-of-infiniteopt-generalvariableref/111955 "2024-03-21T22:16:00Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![lpz18](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@lpz18](https://discourse.julialang.org/u/lpz18)
#### Post date: [March 21, 2024, 10:16pm UTC](https://discourse.julialang.org/t/implementing-a-squarewave-cant-take-remainder-of-infiniteopt-generalvariableref/111955/1 "2024-03-21T22:16:00Z")

</div>

I have a squarewave implemented like so:

```julia
function sqw(t; period::Float64=1, duty::Float64=0.5)
	return t % period < duty*period ? 1.0 : 0.0
end

```

I am running an InfiniteOpt.jl optimization where I pass in `sqw` as a parameter and call it with an infinite parameter:

```julia
@infinite_parameter(model, t ∈ [0, T], num_supports = n)
@constraint(model, ∂(x, t) == sqw(t))

```

I get the error

```julia
MethodError: no method matching rem(::InfiniteOpt.GeneralVariableRef, ::Float64)

```

Clearly, the `rem` has not been implemented for InfiniteOpt

So I have two options:

1. find another way to model the signal
2. implement `rem` for the `GeneralVariableRef`

If #1 is do-able in a InfiniteOpt.jl compatible way, I would love to hear suggestions.

Otherwise, how can I get started on #2?

---

<div class="post-metadata">

### Author: ![pulsipher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pulsipher/32/10461_2.png) [@pulsipher](https://discourse.julialang.org/u/pulsipher)
#### Post date: [March 27, 2024, 1:50am UTC](https://discourse.julialang.org/t/implementing-a-squarewave-cant-take-remainder-of-infiniteopt-generalvariableref/111955/2 "2024-03-27T01:50:25Z")

</div>

Hi @lpz18,

See my post on the InfiniteOpt forum for the solution: [Implementing a squarewave: Can’t take remainder of InfiniteOpt.GeneralVariableRef · infiniteopt/InfiniteOpt.jl · Discussion #337 · GitHub](https://github.com/infiniteopt/InfiniteOpt.jl/discussions/337#discussioncomment-8922340)
