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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

11-Garnet

## 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
24-Ruby V
(To:idahoan)

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:

21 REPLIES 21
24-Ruby V
(To:idahoan)

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:

How about defining some functions to do the job?

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.

11-Garnet
(To:Werner_E)

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.

11-Garnet
(To:Werner_E)

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

any ideas?

24-Ruby V
(To:idahoan)

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

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

11-Garnet
(To:Werner_E)

Great. Thank you!

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

23-Emerald III
(To:idahoan)

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'.

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

That makes them different beasts, so Prime complains.

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

Success!
Luc

24-Ruby V
(To: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").

23-Emerald III
(To:Werner_E)

You're right, I missed the =

Luc

23-Emerald III
(To:idahoan)

It appears like this could be what you are after:

11-Garnet
(To:LucMeekes)

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?

24-Ruby V
(To:idahoan)

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:

11-Garnet
(To:Werner_E)

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

23-Emerald III
(To:idahoan)

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

Success!
Luc

11-Garnet
(To:LucMeekes)

Thank you Luc for the information and help provided.

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

24-Ruby V
(To:idahoan)

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

11-Garnet
(To:Werner_E)

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.

24-Ruby V
(To:idahoan)

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.

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.

11-Garnet
(To:Werner_E)

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

11-Garnet
(To:idahoan)

It has been awhile since I requested assistance with this worksheet.  It got put on the back burner for a few months.  I am still struggling to correct errors in the final calculation.  Please see attached worksheet.

24-Ruby V
(To:idahoan)

Not sure but can it be that you are looking for something like this:

And why do you think the result should be 0.878?

If I look at the tables with the values Phi.f=34 and delta.Phif you provide, the result 0.89 seems to be correct - slightly larger than the 0.883 the table names for Phi.f=35.

You get 0.878 with the input value 35.616

11-Garnet
(To:Werner_E)

Werner, thank you again for your assistance.  That is what I was looking for.

Previous to developing the MathCAD worksheet, I had prepared an Excel spreadsheet that used lookup tables and interpolation.  I will have to look at the spreadsheet to see why it is providing a different result.

Thank you!

Announcements
Top Tags