cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

4-Participant

## Inequality Help

Hello, sorry if this isn't the correct place to post but please help me out. I have the following eqn.

X:= a + b <= c + d = 0

How do I get X to be defined as the lesser of the two. I want it to be defined as C+D if it is smaller, Not 0 or 1.

It is only returning 0 or 1 depending on if the statement is true or false.

1 ACCEPTED SOLUTION

Accepted Solutions
4-Participant
(To:LucMeekes)

Thanks for the response but a better solution I figured out is as follows:

X := if(a+b<=c+d,a+b,c+d) This allows the inequality to return the value instead of 1 or 0

5 REPLIES 5
23-Emerald III
(To:LL_10336639)

Then you probably want:

X:=min(a+b, c+d)

X will get the value of a+b if that is smaller than (or equal to) c+d.

Success!
Luc

4-Participant
(To:LucMeekes)

Thanks for the response but a better solution I figured out is as follows:

X := if(a+b<=c+d,a+b,c+d) This allows the inequality to return the value instead of 1 or 0

23-Emerald III
(To:LL_10336639)

Your IF statement is equivalent to the use of the min() function. The min() function is more compact.

Success!
Luc

4-Participant
(To:LL_10336639)

Sure its more compact but in other instances when I want to get the inequality to work, the min function will not. My question was not just in regards to the instance i posted, it was how to get an inequality function to return the value, not 1 or 0 for true or false. Thanks for the suggestion though, i will consider using min and max functions more in the future for simple inequality substitutes.

23-Emerald III
(To:LL_10336639)

Your 'inequality function' is in fact what commonly known as a 'boolean expression'. That is an expression, it is a statement that should always result in either true (1) or false (0). You can use boolean expressions in programming constructs such as an IF or a WHILE to make decisions based upon the statement. And you can assign (the result of) a boolean expression to a variable and use that variable in the IF or WHILE.

Note that in your posting at the start of this thread, you assigned a boolean expression to the variable X:

X:= a + b <= c + d

X will get the result of the statement: "a+b is less than or equal to c+d". That statement is either true or false.

You could follow it up with:

X := IF(X, a+b,c+d)

Success!
Luc

Announcements
Top Tags