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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Translate the entire conversation x

Mathcad Programming

IA_12699372
10-Marble

Mathcad Programming

Hi all, 

 

Looking for some help with writing a program shown in the image provided? Engineering code provided alongside for context. I'll accompany this with the Mathcad file (working with Mathcad Prime 10.0.0.0). 

 

Kind regards, 

Iain 

ACCEPTED SOLUTION

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

After "if SR<=100" it is clear that SR must be >100 in the "else" branch and so you don't need to ask if SR>100.

The program covers SR<=100 and also SR>100, so all possibilities for SR are covered. But the program should also cover all possibilities for the "shape" variable - it should also be able to deal with a "shape"  not being one of the five 'legal' possibilities.

Find attached one possible way to cover all cases.

You may also consider using the "return" statement. Once a program has to execute a "return" the program is terminated. So could could collect all cases for an OK by simply using "If's" (without "else" or "elseif"). And at the end of your program you write "NOT OK". So if none of the conditions resulting in an "OK" is met, this "NOT OK" is returned.

An example is included

 

Prime 10 file attached

View solution in original post

5 REPLIES 5
Werner_E
25-Diamond I
(To:IA_12699372)

You may replace the various "NOT OK"  by "NOT OK 1", "NOT OK 2", etc. so you can see at which point you program exits and can then investigate, why.

 

I wonder, why you don't follow the logic of the text to the right of your program: First use if-statements to distinguish between the value of the ratio and then look for the shape. Your program does it the other way round. That's not necessarily a failure but it may be more failure prone to implement that way, I think.

Thanks for the response, I just want to make sure my application of the programming is correct based on the code. I have amended it to review the SRmax ratio first and then shape code next but this throws up an error, "The program has no return value. You must account for all cases when using conditional statements in a Mathcad program"

This example should come out as OK 4, but there's an error in the programming. 

Werner_E
25-Diamond I
(To:IA_12699372)

After "if SR<=100" it is clear that SR must be >100 in the "else" branch and so you don't need to ask if SR>100.

The program covers SR<=100 and also SR>100, so all possibilities for SR are covered. But the program should also cover all possibilities for the "shape" variable - it should also be able to deal with a "shape"  not being one of the five 'legal' possibilities.

Find attached one possible way to cover all cases.

You may also consider using the "return" statement. Once a program has to execute a "return" the program is terminated. So could could collect all cases for an OK by simply using "If's" (without "else" or "elseif"). And at the end of your program you write "NOT OK". So if none of the conditions resulting in an "OK" is met, this "NOT OK" is returned.

An example is included

 

Prime 10 file attached

Many thanks Werner_E 

Announcements

Top Tags