cancel
Showing results for 
Search instead for 
Did you mean: 
Security Alert Log4j Security Vulnerability. Click here to know more.
cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple Nested If Statements

1aidaho
10-Marble

Multiple Nested If Statements

I would like to create a series of nested If statements to calculate kp_figure for Multiple values of Θ (120, 110. 100, 90, 80, 70, 60, and 50), with a secondary If statement for each value of Θ as shown in the calculation for Θ =120.

 

Any assistance would be appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Werner_E
24-Ruby IV
(To:1aidaho)

You have an (implicit) multiplication dot between the 15.15 and the polynomial.

You have to separate the two arguments of the min function by a comma:

Werner_E_2-1616647087869.png

 

 

 

View solution in original post

18 REPLIES 18
Werner_E
24-Ruby IV
(To:1aidaho)

You don't need an if-statement to calculate the k value. After all its inefficient to calculate the polynomial twice. Let the min-function do the job:

Werner_E_0-1616562425414.png

 

 

How about defining some functions to do the job?

Werner_E_0-1616561864326.png

I was assuming that both, the polynomial and the max value are different dependent on theta. If thats not the case, the solution can be quite simpler. If for instance the polynomial is the very same for all values of theta (and only dependent on Phi.f, you won't need theta and the conditionals in the function "poly" and you also may consider providing the values for theta and the appropriate max-values in vectors and use "Lookup" to chose the correct value instead of the cascaded if's.

 

Yes, the maximum value and polynomial are different for each value of theta.  I am trying to develop a  program/routine to calculate k when the values of theta and phi are changed/entered. I like the efficiency of the min function.

I have programmed the poly, maxval, and get functions, but have some undefined variables.

any ideas?

Werner_E
24-Ruby IV
(To:1aidaho)

You can't evaluate a function definition (unless its a constant function).

Delete the evaluation (= sign) and it should work OK

Werner_E_0-1616623924462.png

 

Great. Thank you!

 

I have also tried using the min function, but it does not provide the correct answer.

LucMeekes
23-Emerald I
(To:1aidaho)

You've been hit by Prime's (in)famous 'autolabelling' feature.

The theta in the function declaration for the poly() function is labelled as a 'variable'.

LucMeekes_0-1616624428506.png

All theta's appearing in the if statement conditions are 'automatic'.

LucMeekes_1-1616624503872.png

That makes them different beasts, so Prime complains.

Make sure that all variables that should be the same variable, are labelled identically.

 

Success!
Luc

@LucMeekes 

Prime's autolabelling often is a PITA and the cause of quite some unexplainable (on first sight) errors.

But this time, for once, this feature is blameless.

The combination of "Variable" and "(-)" works OK. Its usually a problem when used with symbolic evaluations.

 

Prime is simply complaining that it can't evaluate the function without knowing the value of theta. Thats OK, even though we wished for an error message more to the point (something like "numeric evaluation of function definition not possible").

 

LucMeekes
23-Emerald I
(To:Werner_E)

You're right, I missed the =

 

Luc

LucMeekes
23-Emerald I
(To:1aidaho)

It appears like this could be what you are after:

LucMeekes_0-1616625994978.png

 

I'll post this at the end of the replies also.

 

With the = deleted, the poly function works correctly.  Thank you!

 

Now for the min function.  Is this a mislabeling error?

Werner_E
24-Ruby IV
(To:1aidaho)

You have an (implicit) multiplication dot between the 15.15 and the polynomial.

You have to separate the two arguments of the min function by a comma:

Werner_E_2-1616647087869.png

 

 

 

Thank you very much for your assistance!  I appreciate it very much.

LucMeekes
23-Emerald I
(To:1aidaho)

Werner already explained the error you made here.

What about values of theta other than 180, 170 etc.. What about, e.g. 175?

 

Success!
Luc

Thank you Luc for the information and help provided. 

Intermediate values will require interpolation between the provided values of theta/

Werner_E
24-Ruby IV
(To:1aidaho)

So I would suggest to include that interpolation in the function "get_k":

Werner_E_0-1616708510647.png

 

Werner, Thank you for the help with the interpolation.  That is a great help.

I have attempted to use the interpolation tools with some additional equations that are related to the first set, There is an error in the get_k function that says 3 arguments are required.  Any ideas.

Werner_E
24-Ruby IV
(To:1aidaho)

Prime is right - linterp requires 3 arguments and you provided only two.

Watch the closing parenthesis and the missing comma, to separate the third argument.

Furthermore I guess you meant to switch phi.f and delta .phi.f.

Werner_E_0-1616839225137.png

Furthermore you must move down the region a little but as otherwise it uses the definition of kvec from above.

Not sure if you really intend to get negative values but thats the way you defined your new kvec function.

Werner_E_0-1616839622799.png

 

 

Werner, thank you very much for your assistance!  It is greatly appreciated!

Announcements
Check out the latest
Mathcad Tip
"PTC Mathcad 15 / Prime 1-6 Update."