Solved

# Linearizing step function

• 2 replies
• 564 views

• Newcomer
hi all,
need help for linearizing step function.

say "y" is depending on "x" such that,
y= ax if x is between 1 and 2
y= bx if x is between 3 and 4
y= cx if x is between 5 and 6

a, b and c are parameters/constant which will have values 8 or 9.
"y" is not final objective function and a, b and c must choose value either 8 or 9.

solution requested for maximizing/minimizing "y".

thanks.
icon

Best answer by mohansx 6 August 2019, 23:33

View original

### 2 replies

Userlevel 5
+5
Hi @chrdttchavan ,

One way of linearizing this is to use binary variables. I would recommend you to create a set Ranges (with index r) - each element in this set corresponds to the different steps/ranges you have for x.

Set
Ranges := data{Range-1, Range-2, Range-3}.

Parameters,

LowerLimit(r) := {1, 3, 5};
UpperLimit(r) := {3, 4, 6};
MultiplicationFactor(r) := {a, b, c};.

BinaryVariable(r).

Now have the following constraints.

Constraint_1
y = sum[r, BinaryVariable(r)*MultiplicationFactor(r)]

Constraint_2
sum[r, BinaryVariable(r)] = 1

Constraint_3(r)
x >= BinaryVariable(r) * LowerLimit(r)

Constraint_4(r)

X <= (1-BinaryVariable(r))*M + UpperLimit(r)

Here, M is a sufficiently large positive number. You can use M = 10 for your case.

You are essentially using BinaryVariable(r) to track in which range does the value of x lie in, and based on the value of BinaryVariable(r), you can calculate the value of y.
Userlevel 6
+6
Hi @chrdttchavan did this help solve your problem? Or did you find another way? It may help others to know. Thanks 🙂
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}