# Piecewise function as a constraint on Julia JuMP

**URL:** https://discourse.julialang.org/t/piecewise-function-as-a-constraint-on-julia-jump/105854
**Category:** Optimization (Mathematical)
**Tags:** question, jump, linearalgebra, optimization
**Created:** [November 6, 2023, 11:46am UTC](https://discourse.julialang.org/t/piecewise-function-as-a-constraint-on-julia-jump/105854 "2023-11-06T11:46:19Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Jesper](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jesper/32/202994_2.png) [@Jesper](https://discourse.julialang.org/u/Jesper)
#### Post date: [November 6, 2023, 11:46am UTC](https://discourse.julialang.org/t/piecewise-function-as-a-constraint-on-julia-jump/105854/1 "2023-11-06T11:46:20Z")

</div>

I have an optimization model to which I need to add the following piecewise function as a constraint:

C\_{i,k} = { PR\_{i} \* HSE\_{k} i∈Ω, k = 1,…,M ,  
1 i∈Ω, k = 1,…,M (otherwise)  
I read PR and HSE from excel cells  
¿Is there a nice way to do this in Julia? I have not found any documentation of this in Julia

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [November 6, 2023, 8:56pm UTC](https://discourse.julialang.org/t/piecewise-function-as-a-constraint-on-julia-jump/105854/2 "2023-11-06T20:56:39Z")

</div>

Hi @Jesper, welcome to the forum.

I’m not sure I fully understand your question. What is the `(otherwise)` part? Are PR and HSE constants or decision variables?

There is a small section of the docs on piecewise linear here:

> **[Tips and tricks · JuMP](https://jump.dev/JuMP.jl/stable/tutorials/linear/tips_and_tricks/#Piecewise-linear-approximations)**
>
> Documentation for JuMP.
