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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

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

ACCEPTED SOLUTION

Accepted Solutions
25-Diamond I
(To:shammett-2)

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:

7 REPLIES 7
25-Diamond I
(To:shammett-2)

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:

18-Opal
(To:Werner_E)

Here's another:

24-Ruby IV
(To:shammett-2)

1-Newbie
(To:shammett-2)

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!

18-Opal
(To:shammett-2)

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.

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

25-Diamond I
(To:shammett-2)

> 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.

Announcements

Top Tags