Skip to main content
12-Amethyst
Mar 24, 2021 2:09 AM UTC
Solved

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.

Werner_E
Werner_EAnswer
25-Diamond I
Mar 25, 2021 4:38 AM UTC

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

 

 

 

21 replies

Werner_E
25-Diamond I
Mar 24, 2021 4:59 AM UTC

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.

 

Translate
idahoan12-AmethystAuthor
12-Amethyst
Mar 24, 2021 2:18 PM UTC

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.

Translate
23-Emerald V
Mar 24, 2021 10:48 PM UTC

It appears like this could be what you are after:

LucMeekes_0-1616625994978.png

 

Translate
idahoan12-AmethystAuthor
12-Amethyst
Mar 25, 2021 12:47 AM UTC

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?

Translate
Werner_E
Werner_E25-Diamond IAnswer
25-Diamond I
Mar 25, 2021 4:38 AM UTC

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

 

 

 

Translate