Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations pierreick on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Boolean expression in an equality

Status
Not open for further replies.

edmeister

Member
Jun 25, 2002
97
In dealing with a Shear / Moment Diagram .. came across this expression ..
V(x) := R - (x > a) * W
never seen a ">" or "<" operator in an equality expression like this ..
How does this work ? does it multiply W only if x > a ??
else V := R if a >= x ?

if (x > a) is true (=1) then V = R-W
else if (x <= a) is false (=0) then V = R

is this the principle how this works ?
 
Replies continue below

Recommended for you

V = R - x * W when x is greater than a AND there may be more to this equation than shown in your post?
 
It's a notation used in beam element solutions by integration, MacAuley's method from memory. It switches part of the integral on once a certain x is reached to apply local step changes in the SF diagram.

Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
Wow, that never occurred to me, but now that I see it, could be very helpful.
 
In the early days of programming we used to use something like this in programs
TRUE = (1 = 1) and
FALSE = NOT TRUE

because languages often used 0 or -1 for False...

-----*****-----
So strange to see the singularity approaching while the entire planet is rapidly turning into a hellscape. -John Coates

-Dik
 
Back in the "olden days" when memory was tight, and the number of characters of code that could be stored and loaded into a compiler was also a factor, efficiency of code tended to trump all other considerations of clarity etc, and tricks like this were very common.

However, having had to deal with debugging my own software "kludges", and those of my colleagues, if I am coding anything today, I am very liberal with my comments, I use meaningful variable names, and I will use "structured programming" blocks rather than "in-line" workarounds.

E.g.:

V(x) := R - (x > a) * W

gets the job done, but:

IF (x > PointLoadOffset)
THEN
Shear(x) := EndReaction - PointLoad
ELSE
Shear(x) := EndReaction
END IF


is far more comprehensible, and easier to debug.

 
Jhardy1 - agreed .. I could also run a programming routine ..
- but this use of Boolean expressions inside a typical equality statement is quite the "new thing" ..
- been around MathCad & programming for a long time .. never seen this combination before.
makes for a tidy & clean expression.
 
not only obtuse, but a risk that a future software revision changes the default function behavior, causing the code to either crash or produce different results.
 
Agreed - it is pretty common for programming languages to use Logical TRUE = 1 and Logical FALSE = 0 (as Type INTEGER), enabling you to use this sort of shortcut. (Indeed, before the development of true Logical variable types, when Real and Integer variables were all that were available to the programmer, you would commonly define Integer constants TRUE = 1 and FALSE = 0 for exactly this purpose.)

However, a "strong" structured programming language would throw an error when you mix Logical variables (or expressions) with Real and Integer variables in one expression.

 
In the early days, some programming languages would return 0 or -1 for false... hence the earlier noted construction.

-----*****-----
So strange to see the singularity approaching while the entire planet is rapidly turning into a hellscape. -John Coates

-Dik
 
The expression:

R - (x > a) * W

would yield different results if FALSE is assigned a value of -1 rather than 0.

For zero (the most common value in my experience), the expression yields a value of R. For -1, the resulting value is R + W. Using Integer equivalent values for Logical expressions in a Real or Integer expression is ambiguous (and hazardous) if you're not sure of the Integer value which is assigned to FALSE.

 
When the first PCs came out, some programming languages (and different company versions) weren't that friendly, sometimes. That the reason for using the return of an actual boolean value. I have no idea of how the construct works with current languages.

-----*****-----
So strange to see the singularity approaching while the entire planet is rapidly turning into a hellscape. -John Coates

-Dik
 
You could use an "if" function to use Boolean expressions without programming.
V(x):=if(x>a,R-W,R)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor