Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
I am looking to write some code for a structural connection design template. One of the things that needs to be checked is plate geometry. More specifically the distance from the centerline of a bolt hole to the edge of the plate the hole is in. The table below outlines the general parameters I am trying to meet.
lets call the bolt diameter "d" and the min edge distance "x",
for 0.5 <= d <= 1
if x >= d + 0.25 then return "meets spec". if not then return "violates spec"
for 1 < d <= 1.25
if x >= d + 0.375 then return "meets spec". if not then return "violates spec"
for d > 1.25
if x >= d * 1.25 then return "meets spec". if not then return "violates spec"
Basically, I want to put in various values for "d" and "x" and have it tell me whether or not I meet the spec per the rules above. I feel like this should be rather simple to code in but I have no coding experience so I am struggling hard with it.
Above is a snippet of the code I have tried to write for it (note that "x" = "lev" in the actual code
Solved! Go to Solution.
The other construct, is also supported by Prime 9.
To code an IF you can use the programmatic IF, that you used in you program.
Terry used the IF function which is defined as:
if ( <boolean> , <value if true> , <value if false> )
Example:
b := if ( x > 0 , 5 , 3 )
Assign to b the value 5 if x >0, and 3 otherwise.
To your program:
Your first test check if d is within 0.5 to 1 and if that's the case, then you have other tests, such as whether d is between 1 and 1.25. Well, the program only gets to that test if d is between 0.5 and 1, so the test for d between 1 and 1.25 always returns false.
The else statement at the end returns false for all values of d outside the range from 0.5 to 1...
Success
Luc
Hello, thanks for the help, I am using mathcad prime 9.0.0.0 so the visual of the syntax is different:
I have tried to match what you had coded, it seems to work for values of 0.5 < d < 1 but anything over 1 it doesnt work as seen in my snippet where it should say "meets spec" when I input a value of 1.5 for d and 1.875 for lev
For a single range, you don't need an AND construct,
Instead of : 0.5 < d AND d < 1
you can use: 0.5 < d < 1
Success!
Luc
The other construct, is also supported by Prime 9.
To code an IF you can use the programmatic IF, that you used in you program.
Terry used the IF function which is defined as:
if ( <boolean> , <value if true> , <value if false> )
Example:
b := if ( x > 0 , 5 , 3 )
Assign to b the value 5 if x >0, and 3 otherwise.
To your program:
Your first test check if d is within 0.5 to 1 and if that's the case, then you have other tests, such as whether d is between 1 and 1.25. Well, the program only gets to that test if d is between 0.5 and 1, so the test for d between 1 and 1.25 always returns false.
The else statement at the end returns false for all values of d outside the range from 0.5 to 1...
Success
Luc