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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Possible problem with Boolean operator.

shammett-2
1-Newbie

Possible problem with Boolean operator.

I have encountered what appears to be a problem with a Boolean operator I am using in a short routine.  I have attached a pdf of the routine for anyone interested.  The values for "TestLeft" and "TestRightIncorrect" should both be 3; however, the "TestRightIncorrect" value is 6.  I have included a modified routine called "TestRightCorrect" that gives me the correct answer, but I do not think this modification should be required.

Any advice or guidance on this issue would be greatly appreciated!

Thanks!

Steve

1 ACCEPTED SOLUTION

Accepted Solutions

Mathcad is working as it should - no bug!

Either you have to set Fiber to zero in each round before you compare or you put the increment of count in the yes-branch of the if statement.

Se here for some other ways to do what you want:

View solution in original post

7 REPLIES 7

Mathcad is working as it should - no bug!

Either you have to set Fiber to zero in each round before you compare or you put the increment of count in the yes-branch of the if statement.

Se here for some other ways to do what you want:

MJG
18-Opal
18-Opal
(To:Werner_E)

Here's another:

Thanks to Valery, Mark and Werner.  All of your responses make sense and are very helpful!

Werner -- I especially like the vector summation for its simplicity.  This is probably what I will use in my work.

One other question though:  Why does the "TestLeft" routine appear to work properly even though it is set up as "TestRightIncorrect"?

Thanks again!

Because for i=1..3, Fiber is undefined.  When Mathcad performs the operation Count <- Count + Fiber, it treats the undefined Fiber as zero.  It's not until i=4 that Fiber gets defined, so Count sums to 3.

If you rearrange the same values in your initial vector you will get different results.

shammett-2
1-Newbie
(To:MJG)

Mark,

I just played around with the initial vector and the results changed depending on where the negative values occurred.  I am glad I decided to test this small routine before including it in a larger, much more complex one.  It could have been very difficult to find or even notice an error.

Take care!

Steve

> Werner -- I especially like the vector summation for its simplicity.

Glad you found something you like.

The vector in fact is a vector of boolean values but in Mathcad TRUE is 1 and FALSE is 0 (in fact every value different from 1 is taken as TRUE in an evaluation.)

So summing up the vector gives us the number of case which meet the condition.

Vectorization would not be really necessary in that case and was just applied as a matter of habit and to be on the safe side.

Top Tags