ArcTan(x,y)?

04052017, 12:07 PM
Post: #1




ArcTan(x,y)?
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 builtin function if possible. I cant find anything on it in the manual.
Tom L PHP Code: arctanxy(x, y) Tom L Cui bono? 

04052017, 12:20 PM
Post: #2




RE: ArcTan(x,y)?
(04052017 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). <0ɸ0> Joe 

04052017, 12:26 PM
Post: #3




RE: ArcTan(x,y)?
(04052017 12:20 PM)Joe Horn Wrote:(04052017 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 Tom L Cui bono? 

04052017, 03:00 PM
(This post was last modified: 04052017 03:08 PM by StephenG1CMZ.)
Post: #4




RE: ArcTan(x,y)?
(04052017 12:26 PM)toml_12953 Wrote:(04052017 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:
Stephen Lewkowicz (G1CMZ) https://my.numworks.com/python/steveg1cmz 

04052017, 03:39 PM
(This post was last modified: 04052017 03:42 PM by toml_12953.)
Post: #5




RE: ArcTan(x,y)?
(04052017 03:00 PM)StephenG1CMZ Wrote:(04052017 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 Tom L Cui bono? 

04052017, 06:22 PM
(This post was last modified: 04052017 06:42 PM by StephenG1CMZ.)
Post: #6




RE: ArcTan(x,y)?
(04052017 03:39 PM)toml_12953 Wrote:(04052017 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 midflight, 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. Stephen Lewkowicz (G1CMZ) https://my.numworks.com/python/steveg1cmz 

04052017, 07:28 PM
Post: #7




RE: ArcTan(x,y)?  
04052017, 07:33 PM
Post: #8




RE: ArcTan(x,y)?
(04052017 06:22 PM)StephenG1CMZ Wrote: Mathematically, (0,0) is undefined, although in the interests of having the code not break midflight, 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. 

04052017, 07:47 PM
Post: #9




RE: ArcTan(x,y)?
(04052017 07:28 PM)KeithB Wrote:(04052017 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. Stephen Lewkowicz (G1CMZ) https://my.numworks.com/python/steveg1cmz 

04052017, 07:53 PM
(This post was last modified: 04052017 07:58 PM by StephenG1CMZ.)
Post: #10




RE: ArcTan(x,y)?
(04052017 07:33 PM)KeithB Wrote:(04052017 06:22 PM)StephenG1CMZ Wrote: Mathematically, (0,0) is undefined, although in the interests of having the code not break midflight, 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). Stephen Lewkowicz (G1CMZ) https://my.numworks.com/python/steveg1cmz 

04052017, 08:10 PM
Post: #11




RE: ArcTan(x,y)?
Harbison and Steele.
Except if x and y are 0, what angle should you return? 

04052017, 09:08 PM
Post: #12




RE: ArcTan(x,y)?
As a general comment on atan2 / ArcTan and floatingpoint: 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). 

04052017, 09:17 PM
(This post was last modified: 04052017 09:29 PM by StephenG1CMZ.)
Post: #13




RE: ArcTan(x,y)?
(04052017 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 realworld 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 realworld 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. Stephen Lewkowicz (G1CMZ) https://my.numworks.com/python/steveg1cmz 

04052017, 09:42 PM
(This post was last modified: 04052017 09:43 PM by KeithB.)
Post: #14




RE: ArcTan(x,y)?
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. 

04052017, 10:38 PM
Post: #15




RE: ArcTan(x,y)?
(04052017 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. Stephen Lewkowicz (G1CMZ) https://my.numworks.com/python/steveg1cmz 

04052017, 10:41 PM
Post: #16




RE: ArcTan(x,y)?
So if the limit of atan2(x,x) as x approaches 0 is 45, maybe that is what atan2() should return?


04052017, 10:47 PM
Post: #17




RE: ArcTan(x,y)?
(04052017 07:28 PM)KeithB Wrote:(04052017 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. 

04062017, 10:27 AM
Post: #18




RE: ArcTan(x,y)?
(04052017 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 

04062017, 02:38 PM
Post: #19




RE: ArcTan(x,y)?
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 

04062017, 03:22 PM
Post: #20




RE: ArcTan(x,y)?
(04062017 10:27 AM)DrD Wrote:(04052017 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. Stephen Lewkowicz (G1CMZ) https://my.numworks.com/python/steveg1cmz 

« Next Oldest  Next Newest »

User(s) browsing this thread: