0

I need to make the output of a variable positive, for both negative and positive inputs.

Since I am using it in the linear optimization problem, no squares, self-division or self-multiplication is allowed.

Need a mathematical solution, No prebuilt functions of programming languages are allowed

Blue
  • 75,673
  • does the absolute value appear on the correct side of the inequality, or is the feasible region not convex? – LinAlg Feb 16 '19 at 23:38
  • I am trying to achive: solve for x1 and x2. One of Constraint should be: abs(x15-x27)<= 10, without the use of abs function – Manish Arora Feb 16 '19 at 23:48

3 Answers3

1

Let the input value be $x$. Then compare $x$ with $0$, if it is greater than $0$ we are done. If it is less than $0$, return $-x$.

Peter Foreman
  • 19,947
1

Define a function $$f(x)=\mid x\mid=\left\{\begin{array}{ll}x&\text{if }x>0\\-x&\text{otherwise}\end{array}\right..$$

pshmath0
  • 10,565
1

$$|5 x_1-7x_2| \leq 10$$ is equivalent to the two linear constraints $$5 x_1-7x_2 \leq 10 \text{ and } -(5 x_1-7x_2) \leq 10$$

LinAlg
  • 19,822