• ×
    Information
    Need Windows 11 help?
    Check documents on compatibility, FAQs, upgrade information and available fixes.
    Windows 11 Support Center.
  • post a message
  • ×
    Information
    Need Windows 11 help?
    Check documents on compatibility, FAQs, upgrade information and available fixes.
    Windows 11 Support Center.
  • post a message
Guidelines
The HP Community is where owners of HP products, like you, volunteer to help each other find solutions.
Archived This topic has been archived. Information and links in this thread may no longer be available or relevant. If you have a question create a new topic by clicking here and select the appropriate board.
HP Recommended

Is there a two-argument ATAN function on the HP50g that will return the correct quadrant as well as a numerical answer? I found this thread but I can't seem to make heads or tails of the long RPL program he provides at the end.

9 REPLIES 9
HP Recommended

refer to the following comp.sys.hp48 post for additional userrpl programs written for a function 'atan2'

 

https://groups.google.com/forum/?fromgroups#!searchin/comp.sys.hp48/atan2/comp.sys.hp48/0m1bqZ83Dfc/...

 

 

however, what you are trying to achieve is still not clear...

 

have you read the AUR definition of how the ARG function is calculated?

-------------

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

----------------

 

wikipedia is not the most accurate source, however, a quick comparison of the ARG calculation reveals the resulting calculation to be identical.

 

the quadrant result for ARG appears to be correct.

 

In the yahoo post you referenced, the OP had a specific issue to provide a solution where all angles were shown as positive values..

 

so for example (in degrees),

(-1, -1)

ARG

result: -135

 

the yahoo OP wanted a positive result of 225.

so per Wessman's suggestion...

 

-135

360 (or 2PI, etc)

MOD

result: 225

 

 

::: fyi, the first listing of  'code' that Wessman provided is sysrpl (and appears to have at least one typing error in the code...should be %rec>%pol... there may be more errors). The function that Wessman's code appears to perform is to automatically type-check the input, convert the X,Y value into R, ANGLE and then convert the angle to a positive value by either MOD 360 or MOD 2PI or MOD 400)

 

the 'code' with the SYSEVAL's is likely outdated and based on a prior ROM version. It is the same function as the SysRPL code, only written with SYSEVALs for the specific version of ROM Wessman was using at the time

 

 

HP Recommended

Hi!, jason331:

 

Try, with this formula ...

Configure FLAG ...

03 Function -> num

  

ATAN2_0.JPG create, a global variables 'X' and 'Y' and assign values

Examples:

1) X= -1; Y= -1

In RAD

-2.3561944902

In DEG

-135

2) X= 1; Y= 1

In RAD

0.785398163398

In DEG

45

3) X= 0; Y= -1

In RAD

-1.57079632679

In DEG

-90

HP Recommended

No, all those pointers should not have moved. It should still work fine. 2008... shesh. That is a while ago. 🙂

 

That being said, the OP seems to want the quadrant number as well to be returned if I am reading that properly.

 

A simple direct approach is to get the angle using a MOD, and then divide by a 1/4 of your circle and do the FLOOR function on that result.

 

TW

Although I work for the HP calculator group as a head developer of the HP Prime, the views and opinions I post here are my own.
HP Recommended

@Tim Wessman wrote:

A simple direct approach is to get the angle using a MOD, and then divide by a 1/4 of your circle and do the FLOOR function on that result. 



you mean "do the FLOOR function and then add 1"   OR do the CEIL function.

 

FYI to the OP.... the originator of the program in question in the yahoo forum post, Tim Wessman, has exception knowledge of the internal structures of the 50G.

 

Further, Tim has specifically stated the values for the SYSEVAL's used are not outdated and still contain valid pointer locations.

 

programs from unknown sources that use SYSEVAL's should be used with caution since the SYSEVAL can potentially delete memory....

 

you should back up the 50g memory before using any programs from any source that contains SYSEVALs.  If the SYSEVAL values are incorrectly typed in, calculator memory loss can occur !

 

programs downloaded from hpcalc.org should be O.K.

 

 

 

 

HP Recommended

you mean "do the FLOOR function function and then add 1"   OR do the CEIL function.



Nuts.

 

That was my programming braing kicking in there. Everyone knows you start counting at 0...   CEIL is the one you'd want of course. 🙂

TW

Although I work for the HP calculator group as a head developer of the HP Prime, the views and opinions I post here are my own.
HP Recommended

Thanks everyone, I'll try out the suggestions here and see what works for me.

 

To recap, I want to be able to enter two numbers on the stack with one of them potentially being negative, take the arctangent, and have it return an angle with respect to the positive x-axis. For example, if I enter 0.936 and -1.12, take the acrctangent, I get -40 degrees as the answer. That's not very meaningful. I would like the result to show 140 degrees instead (if my math is correct)

 

 

HP Recommended

Hi!, jason331:

 

If you use, with the indicated equation ...

FLAG 03 Function -> num

ATAN2_0.JPG and assign, values ...

 

X = -1.12

Y = 0.936

You can obtein, with EVAL ...

DEG

140.114013832 (locate, in Quadrant II)

RAD

2.44545086954

 

Note:

Quadrant I = +X; +Y; (between 0° and 90°)

Quadrant II = -X; +Y; (between 90° and 180°)

Quadrant III = -X ; -Y; (between 180° and 270°)

Quadrant IV = +X; -Y; (between 180° and 360°)

 

Quadrants.JPG

 

HP Recommended

That is about the slowest possible way to calculate this and doesn't actually get the result wanted which includes the quadrant number...

TW

Although I work for the HP calculator group as a head developer of the HP Prime, the views and opinions I post here are my own.
HP Recommended

<< R->C ARG 360 MOD DUP 90 / CEIL >>

 

INPUT: -1.12, .936

OUTPUT:  140.11...   2

 

 

This makes some assumptions about your angle mode settings and that you are working in RPN, but you can clean thaose up. 🙂

 

 

TW

Although I work for the HP calculator group as a head developer of the HP Prime, the views and opinions I post here are my own.
Archived This topic has been archived. Information and links in this thread may no longer be available or relevant. If you have a question create a new topic by clicking here and select the appropriate board.
† The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the <a href="https://www8.hp.com/us/en/terms-of-use.html" class="udrlinesmall">Terms of Use</a> and <a href="/t5/custom/page/page-id/hp.rulespage" class="udrlinesmall"> Rules of Participation</a>.