Skip to main content
1-Visitor
January 3, 2017
Solved

Possible problem with Boolean operator.

  • January 3, 2017
  • 3 replies
  • 3110 views

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

Best answer by Werner_E

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:

3 replies

Werner_E25-Diamond IAnswer
25-Diamond I
January 3, 2017

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:

1-Visitor
January 3, 2017

Here's another:

24-Ruby IV
January 3, 2017

1-Visitor
January 3, 2017

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!

1-Visitor
January 4, 2017

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-Visitor
January 4, 2017

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