multi criteria IF statement
|
06-11-2021, 11:06 AM
Post: #1
|
|||
|
|||
multi criteria IF statement
Hello,
I'm trying to write a program for directional angle calculation. But my issue are the IF statements. I have to test two variables in 4 different scenarios. example Local y,x,n; IF ( y>0 and x>0) then n:=ATAN( y/x); /// 1' scenario if the y or x is not greater next test IF( y>0 and x<0) then n:=ATAN (y/x)+180; //// 2' scenario IF( y<0 and x<0) then n:=ATAN(y/x)+180; //// 3' scenario IF ( y<0 and x>0) then n:=ATAN(y/x)+360; ///// 4' And i'm not sure how to write it. Code: IF ( y>0) THEN I have tried like that, but i't doesnt give the correct awnser. And also at end of program i have to write END; like 6 times or so. |
|||
06-11-2021, 11:37 AM
Post: #2
|
|||
|
|||
RE: multi criteria IF statement
I would probably use a case statement for that task:
Code: EXPORT Amer7scode(x,y) -road |
|||
06-11-2021, 11:59 AM
Post: #3
|
|||
|
|||
RE: multi criteria IF statement
Thanks,
that worked like charm. I wonder where, and how you learn these tricks and expressions. Here is the complete code for Directional Angle - Geodesy - HP Prime Code: EXPORT Directional() |
|||
06-11-2021, 02:04 PM
Post: #4
|
|||
|
|||
RE: multi criteria IF statement
(06-11-2021 11:06 AM)Amer7 Wrote: Hello, Why write a function when one is already built in? look up ARG(X+i*Y) Tom L Cui bono? |
|||
06-11-2021, 10:09 PM
Post: #5
|
|||
|
|||
RE: multi criteria IF statement
As a new prime user I appreciate seeing smaller programs even if they replicate built-in functions.
I have several questions. 1. How does the program know that the calculator is in degrees mode versus radians? 2. What does "c:=→HMS(n);" mean? It probably has to do with the HMS function which I haven't used yet. 3. What is the english translation for the word "tacke" Thanks. |
|||
06-12-2021, 03:05 AM
Post: #6
|
|||
|
|||
RE: multi criteria IF statement
I can answer the 1st 2
1 there is a system varable HAngle you can set to 0 for radian and 1 for degrees, by default it is set in the setup screen or app 2 →HMS() changes a degree to DMS HMS→() changes DMS to degree 3 I dont know |
|||
06-12-2021, 11:53 AM
Post: #7
|
|||
|
|||
RE: multi criteria IF statement
(06-12-2021 03:05 AM)Dougggg Wrote: there is a system varable HAngle you can set to 0 for radian and 1 for degrees, by default it is set in the setup screen or app On HP Prime emulator, HAngle cannot be set to 0 in CAS (Why?) CAS> HAngle := 0 → "HAngle(0) Error: Bad Argument Value" It might be better to use AAngle instead, see http://edspi31415.blogspot.com/2018/02/h...mcalc.html Code: EXPORT bearing(x,y) // x=north, y=east (06-11-2021 02:04 PM)toml_12953 Wrote: Why write a function when one is already built in? Because there is a bug in ARG ? see https://www.hpmuseum.org/forum/thread-16977.html We can use atan2 instead. Code: EXPORT bearing(x,y) // x=north, y=east |
|||
06-12-2021, 02:28 PM
Post: #8
|
|||
|
|||
RE: multi criteria IF statement
Don't forget to handle points on the vertical axis, including the origin. I'll arbitrarily assign 0 to atan(0,0). I haven't had nearly enough coffee yet and I'm not fluent in PPL, but in C++:
Code: if (x==0) { |
|||
06-13-2021, 05:35 AM
Post: #9
|
|||
|
|||
RE: multi criteria IF statement
(06-12-2021 11:53 AM)Albert Chan Wrote:(06-12-2021 03:05 AM)Dougggg Wrote: there is a system varable HAngle you can set to 0 for radian and 1 for degrees, by default it is set in the setup screen or app The bug must have been fixed again. I get the proper 45 with all the examples in that thread. Tom L Cui bono? |
|||
06-13-2021, 01:10 PM
Post: #10
|
|||
|
|||
RE: multi criteria IF statement
(06-13-2021 05:35 AM)toml_12953 Wrote:(06-12-2021 11:53 AM)Albert Chan Wrote: Because there is a bug in ARG ? Strange... my G2 running firmware 14588 (2021 05 05) still has that bug (namely, arg(3+3.*i) in CAS view returns its answer in radians even when Prime is in Degrees mode). Make sure you're in CAS view, degree mode, and include the decimal point. <0|ɸ|0> -Joe- |
|||
06-13-2021, 03:19 PM
Post: #11
|
|||
|
|||
RE: multi criteria IF statement
(06-13-2021 01:10 PM)Joe Horn Wrote:(06-13-2021 05:35 AM)toml_12953 Wrote: The bug must have been fixed again. I get the proper 45 with all the examples in that thread. I just checked it again. Now it comes up with radians. I was sure I checked the angular mode before but I must not have. Of course in Home mode, it does work properly and that's the mode I always use so I never would have run into this bug. Tom L Cui bono? |
|||
06-16-2021, 02:58 AM
Post: #12
|
|||
|
|||
RE: multi criteria IF statement
I found that while in CAS mode the prime allows HAngle to be set to one or two.
After an attempt to do HAngle:=0 an error message appears, namely: "HAngle(0) Error: Bad Argument Value" I wonder if this a feature or a bug and if it is causing the problems noted in this thread. It seems that setting AAngle is not affected. Thanks. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 5 Guest(s)