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.
Solved! Go to Solution.
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:
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.
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?
You can't evaluate a function definition (unless its a constant function).
Delete the evaluation (= sign) and it should work OK
Great. Thank you!
I have also tried using the min function, but it does not provide the correct answer.
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
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").
You're right, I missed the =
Luc
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?
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:
Thank you very much for your assistance! I appreciate it very much.
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/
So I would suggest to include that interpolation in the function "get_k":
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.
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.
Werner, thank you very much for your assistance! It is greatly appreciated!