![]() |
ArcTan(x,y)? - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: ArcTan(x,y)? (/thread-8117.html) Pages: 1 2 |
ArcTan(x,y)? - toml_12953 - 04-05-2017 12:07 PM Is there a single function on the Prime to compute ArcTan(x,y)? I know the function below returns the correct values for the different quadrants but I'd like to use a built-in function if possible. I cant find anything on it in the manual. Tom L PHP Code: arctanxy(x, y) RE: ArcTan(x,y)? - Joe Horn - 04-05-2017 12:20 PM (04-05-2017 12:07 PM)toml_12953 Wrote: Is there a single function on the Prime to compute ArcTan(x,y)? ARG((x,y)) = ARG(x+y*i) is like ATAN(y/x) but it respects the quadrants better than ATAN. Here's its description from the 50g AUR (same info applies to the Prime): ARG Type: Function Description: Argument Function: Returns the (real) polar angle θ of a complex number (x, y). The polar angle θ is equal to: • atan y/x for x ≥ 0 • atan y/x + π sign y for x < 0, Radians mode • atan y/x + 180 sign y for x < 0, Degrees mode • atan y/x + 200 sign y for x < 0, Grads mode A real argument x is treated as the complex argument (x,0). RE: ArcTan(x,y)? - toml_12953 - 04-05-2017 12:26 PM (04-05-2017 12:20 PM)Joe Horn Wrote:(04-05-2017 12:07 PM)toml_12953 Wrote: Is there a single function on the Prime to compute ArcTan(x,y)? Wow! Thanks, Joe! You always answer so quickly, you must have a small parish to have this much time for the calculators! ![]() Tom L RE: ArcTan(x,y)? - StephenG1CMZ - 04-05-2017 03:00 PM (04-05-2017 12:26 PM)toml_12953 Wrote:(04-05-2017 12:20 PM)Joe Horn Wrote: ARG((x,y)) = ARG(x+y*i) is like ATAN(y/x) but it respects the quadrants better than ATAN. However, unlike ATAN2, ARG will not always work Code:
RE: ArcTan(x,y)? - toml_12953 - 04-05-2017 03:39 PM (04-05-2017 03:00 PM)StephenG1CMZ Wrote:(04-05-2017 12:26 PM)toml_12953 Wrote: Wow! Thanks, Joe! You always answer so quickly, you must have a small parish to have this much time for the calculators! I don't understand what the first test is for. ARG((0,0)) returns 0 even without it. Tom L RE: ArcTan(x,y)? - StephenG1CMZ - 04-05-2017 06:22 PM (04-05-2017 03:39 PM)toml_12953 Wrote:(04-05-2017 03:00 PM)StephenG1CMZ Wrote: However, unlike ATAN2, ARG will not always work Mathematically, (0,0) is undefined, although in the interests of having the code not break mid-flight, atan2 implementations normally return 0. On the 8151 Android emulator, ARG fails for 0,0 rather than returning 0... Glad to see this has improved. By the way, I notice there is an error in the Help for ARG (in the new version too): The Syntax is described as ARG(3+3i) but this gives a syntax error. Actually (3+3*i) is required. RE: ArcTan(x,y)? - KeithB - 04-05-2017 07:28 PM (04-05-2017 06:22 PM)StephenG1CMZ Wrote: The Syntax is described as ARG(3+3i) but this gives a syntax error.Not on my Prime, it works fine. Guess I have a special one. RE: ArcTan(x,y)? - KeithB - 04-05-2017 07:33 PM (04-05-2017 06:22 PM)StephenG1CMZ Wrote: Mathematically, (0,0) is undefined, although in the interests of having the code not break mid-flight, atan2 implementations normally return 0. While it might return 0 - I don't have a compiler handy to check it out - H&S say that for atan2(0,0) "a domain error occurs". i.e., it might return 0, but set errno to EDOM. RE: ArcTan(x,y)? - StephenG1CMZ - 04-05-2017 07:47 PM (04-05-2017 07:28 PM)KeithB Wrote:(04-05-2017 06:22 PM)StephenG1CMZ Wrote: The Syntax is described as ARG(3+3i) but this gives a syntax error.Not on my Prime, it works fine. Guess I have a special one. Unless I made a typo, both 8151 and the new Android app required 3+3*i rather than 3+3i. RE: ArcTan(x,y)? - StephenG1CMZ - 04-05-2017 07:53 PM (04-05-2017 07:33 PM)KeithB Wrote:(04-05-2017 06:22 PM)StephenG1CMZ Wrote: Mathematically, (0,0) is undefined, although in the interests of having the code not break mid-flight, atan2 implementations normally return 0. H&S? Health&Safety? I'd prefer ATAN2 to deliver what it is supposed to - an ANGLE. Then you know what angle to move your flaps to. Having it return a Domain Error is not what I want as a passenger (though it might be useful whilst developing on the ground). RE: ArcTan(x,y)? - KeithB - 04-05-2017 08:10 PM Harbison and Steele. Except if x and y are 0, what angle should you return? RE: ArcTan(x,y)? - jte - 04-05-2017 09:08 PM As a general comment on atan2 / ArcTan and floating-point: this is one of the places where signed zeroes can light a clear path. (For those less familiar with the numerical details of the prime: some of the number systems used in the Prime have signed zeroes, some do not.) Signed zeroes and atan2 / ArcTan can also surprise some programmers (depending on their numerical outlook). RE: ArcTan(x,y)? - StephenG1CMZ - 04-05-2017 09:17 PM (04-05-2017 08:10 PM)KeithB Wrote: Harbison and Steele. Judging by the reviews, H&S looks like a useful update of K&R. Most of my programming has been functional, with the emphasis on returning real-world values. I'd be looking for: (A) Values not significantly different from atan2(0 .000001,0.00001) etc., assuming the 0 is a rounding error - no discontinuous jumps. (B) Values that are portable and compatible. Every atan2 that I have seen since the 1980's has used 0, so I would need some convincing that a different incompatible value were useful. (C) For real-world use: In the case of Atan2, I don't see 0,0 as being a real domain error, assuming the 0,0 was a rounding error from valid inputs like 0.001,0.001...what the pilot wants to see is an angle... I'd keep domain error for truly exceptional error conditions, like if the input (0,0) were instead (NaN,NaN) because the compass had dropped off, and you really cannot return an angle. (D) But in maths class, I would like to see it highlighted as indeterminate. RE: ArcTan(x,y)? - KeithB - 04-05-2017 09:42 PM Note that EDOM is a "back channel error", this is not the return from the function, but a value in a separate errno variable. I believe the function still returns 0. ETA: atan2(0.0001, 0.0001) != 0. RE: ArcTan(x,y)? - StephenG1CMZ - 04-05-2017 10:38 PM (04-05-2017 09:42 PM)KeithB Wrote: Note that EDOM is a "back channel error", this is not the return from the function, but a value in a separate errno variable. I believe the function still returns 0. Oh... I should have checked that example instead of assuming it would be near 0. RE: ArcTan(x,y)? - KeithB - 04-05-2017 10:41 PM So if the limit of atan2(x,x) as x approaches 0 is 45, maybe that is what atan2() should return? RE: ArcTan(x,y)? - KeithB - 04-05-2017 10:47 PM (04-05-2017 07:28 PM)KeithB Wrote:(04-05-2017 06:22 PM)StephenG1CMZ Wrote: The Syntax is described as ARG(3+3i) but this gives a syntax error.Not on my Prime, it works fine. Guess I have a special one. I think I just stumbled across the problem you had: arg(1+i1) is OK arg(.1+i.1) is a syntax error arg(0.1+i0.1) is OK arg(.1+.1i) is OK So you get the error when the decimal point is adjacent to i. RE: ArcTan(x,y)? - DrD - 04-06-2017 10:27 AM (04-05-2017 10:47 PM)KeithB Wrote: I think I just stumbled across the problem you had: Implicit multiplication isn't supported: arg(.1+i.1) is a syntax error arg(.1+i*.1) ==> returns ARG(0.1+i*0.1); 0.79 RE: ArcTan(x,y)? - KeithB - 04-06-2017 02:38 PM implicit multiplication seems to work just fine for: arg(1+i1) is OK arg(0.1+i0.1) is OK arg(.1+.1i) is OK It seems to be the decimal point that causes the Prime to be confused RE: ArcTan(x,y)? - StephenG1CMZ - 04-06-2017 03:22 PM (04-06-2017 10:27 AM)DrD Wrote:(04-05-2017 10:47 PM)KeithB Wrote: I think I just stumbled across the problem you had: It seems to work for some, and is specified in the ARG HELP - but ARG implicit multiplication doesnt work for me on the Android, regardless of decimal point. |