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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

else and else if return incorrect answers!

h_nas
4-Participant

else and else if return incorrect answers!

Dear All,

I have found a fault in MP, (else and else if) is not working properly! Please see attached file.

I think they stop working properly, when there is (+ or -) in the equation.

Enjoy the discovery

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:h_nas)

It's not an error in Prime but rather an error in using it.

In Mathcad, as in other programming languages, too, the result of boolean expressions are represented as numbers. 0 denotes FALSE and any other number would mean TRUE.

You write "if i=1 OR 2" which is equivalent to "if i=1 OR TRUE" . This condition is TRUE in every case (because the second part of the OR, the 2, is considered to be TRUE) and so the else if branch is never executed.

You would have to write "if i=1 OR i=2" to get what you want.

I don't see any reason for the augment function you use, simply using tr would do the same, even better if you place it after the for-loop and not inside.

See attached some ways to achieve what you want for the last example you posted.

if.png

View solution in original post

7 REPLIES 7
AlanStevens
17-Peridot
(To:h_nas)

My copy of Prime 2 won't open your document.

Alan

h_nas
4-Participant
(To:AlanStevens)

Hi,

Its in MP 3.0

AlanStevens
17-Peridot
(To:h_nas)

You'll need someone with MP3 to look at it then (you might consider renaming the file!).

Alan

h_nas
4-Participant
(To:AlanStevens)

Please see attached Pic.

Use please tr[i<--if(...,...,...)

Work in Prime Express too!

Probably a syntax issue - issue replicated in MP2;

I think that because you have the IF as { if {i=0} or {2} } it is evaluating 2 as true & it always calculates the first block.

In the correct cases there are no differences to show the error.

Regards

Andy

Werner_E
25-Diamond I
(To:h_nas)

It's not an error in Prime but rather an error in using it.

In Mathcad, as in other programming languages, too, the result of boolean expressions are represented as numbers. 0 denotes FALSE and any other number would mean TRUE.

You write "if i=1 OR 2" which is equivalent to "if i=1 OR TRUE" . This condition is TRUE in every case (because the second part of the OR, the 2, is considered to be TRUE) and so the else if branch is never executed.

You would have to write "if i=1 OR i=2" to get what you want.

I don't see any reason for the augment function you use, simply using tr would do the same, even better if you place it after the for-loop and not inside.

See attached some ways to achieve what you want for the last example you posted.

if.png

Announcements

Top Tags