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

The If statement

Callum1995
6-Contributor

The If statement

Hello all, 

 

I am currently trying to create a worksheet for calculating beam deflection. I have a template I am using as a guide and in the template sheet the if statement is of the following form: 

 

CC_10223533_0-1647258974924.png

I am trying to write this into my program however when I insert an if statement I get the following issue:

CC_10223533_1-1647259050011.png

 

As you can see the if statement takes up multiple lines. How do I get the if statement to become the more compact form?

 

Thanks,

Callum 

 

ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:Callum1995)

Your first example technically doesn't use the IF statement, but the if function (notice how Prime set the if in bold font, as opposed to the if in your second example.

There are (at least) three different ways to make 'decisions' in Mathacd and Prime:

LucMeekes_0-1647271467390.png

 

With the if function, you get a result from the function that you can calculate further with, but you can only make one assignment. (Well, admitted, you can assign an array of values...)

With the if statement you can put one or more assignements or other statement(s) for either result of the comparison.

With the boolean expression you get either a 1 (true) or a 0 (false) out of the comparison, which you (may) have to use in further calculations.

 

Success!
Luc

View solution in original post

6 REPLIES 6

You can write an if statement in line, like the if statements in EXCEL:  if(condition,true,false).

Fred_Kohlhepp_0-1647261529034.png

But I have a question:  Are you solving for multiple loads, summing up VG[i to get a total?  Then try:

Fred_Kohlhepp_1-1647261889065.png

 

 

Hi Fred thanks for the reply. 

 

I am considering loads that are acted on by different loading factors depending if it is a permanent or variable load so I have gone for the summation in a separate line. 

Callum1995_0-1647272487960.png

 

Best Regards,

Callum 

I'm assuming that yG is your loading factor.  If so, you could make it a vector the same size as xG and FG; then the summation would still work.

LucMeekes
23-Emerald III
(To:Callum1995)

Your first example technically doesn't use the IF statement, but the if function (notice how Prime set the if in bold font, as opposed to the if in your second example.

There are (at least) three different ways to make 'decisions' in Mathacd and Prime:

LucMeekes_0-1647271467390.png

 

With the if function, you get a result from the function that you can calculate further with, but you can only make one assignment. (Well, admitted, you can assign an array of values...)

With the if statement you can put one or more assignements or other statement(s) for either result of the comparison.

With the boolean expression you get either a 1 (true) or a 0 (false) out of the comparison, which you (may) have to use in further calculations.

 

Success!
Luc

Callum1995
6-Contributor
(To:LucMeekes)

Very useful information LucMeekes, as you seem very knowledgeable do you have any books that you could recommend to learn Mathcad prime. I am using the book "Engineering with Mathcad: Using Mathcad to create and organize your engineering calculations by Brent Maxfield" but it is very old and not up to date with the information. 

 

Thanks,

Callum 

LucMeekes
23-Emerald III
(To:Callum1995)

You don't learn Prime from a book, you learn it by using it, facing the challenges before you and requesting help and/or explanation where you need it. There's a number of people frequenting this community that are generally willing to help; be sure to attach your worksheet (not just a picture) with any problems you face using Prime.

So the best book I can recommend is to visit this community with any questions you may have, and to read questions and answers from others.

 

Success!
Luc

Announcements

Top Tags