Showing posts with label argument. Show all posts
Showing posts with label argument. Show all posts

Monday, February 8, 2021

An Alternative Way of Finding the Angle in a Rectangular to Polar Conversion

An Alternative Way of Finding the Angle in a Rectangular to Polar Conversion


Welcome to a special Monday edition of Eddie’s Math and Calculator Blog. 


The Traditional Method


Often we are required to find polar coordinates of a given point (x,y).   Finding the radius, r, is fairly simple:


r = √(x^2 + y^2) 


When talking about complex numbers, r represents the absolute value of x + yi where i = √-1.


Finding the angle, θ, often uses the formula:


θ = atan(y/x)


In complex numbers, θ represents the argument (arg) function.


On a scientific calculator the range of the arctangent function is ( -90°, 90° ).  (open interval).   In finding the true angle, adjustments will be required:





Let a = atan(y/x). Then: 


Quadrant I (x and y are both positive):  θ = a

Quadrant II (x is negative, y is positive): θ = a + 180°

Quadrant III (x and y are both negative):  θ = a - 180°

Quadrant IV (x is positive, y is negative):  θ = a 


If you are working with radian angle measures, know that 90° = π/2, and 180° = π.


This does not take into consideration situations where either x or y is 0:


If x > 0 and y = 0:  θ = 0°

If x = 0 and y > 0:  θ = 90°

If x < 0 and y = 0:  θ = 180°

If x = 0 and y < 0:  θ = -90°


Is there a shorter way to calculate θ?  


The Vector Method


Consider the point (x, y) as a vector [x, y].   Now draw another vector [x, 0].  In a regular Cartesian coordinate system, angles are measured from the x-axis counter clockwise.  





Let a and b represent two vectors.  Then the angle between two vectors are:


cos θ = (a ● b) / ( ||a|| ||b|| ) = dot(a,b) / ( norm(a) * norm(b) )


with:

dot(a,b) = a1 * b1 + a2 * b2

norm(a) = √(a1^2 + a2^2)

norm(b) = √(b1^2 + b2^2)


Let a = [x, y] and b = [x, 0].  Then:


cos θ = (x^2) / (√(x^2 + y^2) * √(x^2))

cos θ = (x^2) / (√(x^2 + y^2) * x)

cos θ = x / √(x^2 + y^2)

θ = acos( x / √(x^2 + y^2) )


The range of the arccosine function of a calculator is [ 0°, 180° ].  


If y < 0, the angle would be measured clockwise, and therefore I would make the adjustment:

θ = -acos( x / √(x^2 + y^2) )


In summary:

If y ≥ 0, θ = acos( x / √(x^2 + y^2) )

If y < 0, then θ = -acos( x / √(x^2 + y^2) )


Examples:


Find the angle, in degrees, in a rectangular to polar conversions:


Quadrant I  (2, 4):  y ≥ 0:   θ = acos( 2 / √(2^2 + 4^2) ) ≈ 63.43494882°


Quadrant II (-2, 4):  y ≥ 0:    θ = acos( -2 / √((-2)^2 + 4^2) ) ≈ 116.5650512°


Quadrant II (-2, -4):  y < 0:  θ = -acos( (-2) / √((-2)^2 + (-4)^2) ) ≈ -116.5650512°


Quadrant IV (2, -4):  y < 0:  θ = -acos( 2) / √(2^2 + (-4)^2) ) ≈ -63.43494882°


Vector Method for Navigation


In navigation, angles start from true North (up) and rotate clockwise towards East (right).  Angles are measured from 0° to 360°.


Use the vectors [0, N] and [E, N], then the angle between these vectors are:

If E ≥ 0,  θ = acos( N / √(E^2 + N^2))

If E < 0, θ = 360° - acos( N / √(E^2 + N^2))


Note:  This is the first blog entry that I have typed on Google Docs.  I have been using Windows app Wordpad for the last three years.   I am testing Google apps as I am considering buying a Chromebook.


Eddie


All original content copyright, © 2011-2021.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.


Friday, December 28, 2018

HP 42S/DM 42/Free42: Argument, Real Part, Imaginary Part, and Sign Function

HP 42S/DM 42/Free42: Argument, Real Part, Imaginary Part, and Sign Function

Introduction

The HP 42S* has only one extraction function for complex numbers: ABS (absolute value) by default.  To complete the list, here are some programs for ARG (argument), REAL (real part), and IMAG (imaginary part).  The three functions take a complex number, in either rectangular or polar form. 

Using stack commands and flag checks, I am able to get obtain results without affecting the stack much (although the z and t stacks will have the same value).

Also included is the SIGN (signum) function.

* This applies to the Swiss Micros DM42 (it should work), Free42 from Thomas Oakken, and any other HP 42S emulator apps.  The print out is from Free42 (and I also have a physical HP 42S).

HP 42S Program: ARG

00 { 19-Byte Prgm }
01▸LBL "ARG"
02 COMPLEX
03 X<>Y
04 FC? 73
05 →POL
06 R↑
07 STO ST Y
08 R↓
09 R↓
10 RTN
11 .END.

HP 42S Program:  REAL

00 { 21-Byte Prgm }
01▸LBL "REAL"
02 COMPLEX
03 X<>Y
04 FS? 73
05 →REC
06 X<>Y
07 R↑
08 STO ST Y
09 R↓
10 R↓
11 RTN
12 END

HP 42S Program: IMAG

00 { 20-Byte Prgm }
01▸LBL "IMAG"
02 COMPLEX
03 X<>Y
04 FS? 73
05 →REC
06 R↑
07 STO ST Y
08 R↓
09 R↓
10 RTN
11 END

Example - Rectangular Mode:

7+8i   (7 [ENTER] 8 [ (shift) ] (COMPLEX) )
XEQ ARG:  48.8141 (Degrees)
XEQ REAL: 7.0000
XEQ IMAG: 8.0000

Example - Polar Mode: (Degrees):

4 ∡ 60  (4 [ENTER] 60 [ (shift) ] (COMPLEX) )
XEQ ARG:  60.0000
XEQ REAL:  2.0000
XEQ IMAG:  3.4641

HP 42S Program:  SIGN

00 { 15-Byte Prgm }
01▸LBL "SIGN"
02 X=0?
03 RTN
04 ENTER
05 ABS
06 X<>Y
07 ÷
08 RTN
09 END

Example:

-1.4641  XEQ SIGN returns -1
5.525 XEQ SIGN returns 1
0 XEQ SIGN returns 0

Eddie

All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

Monday, November 25, 2013

ATAN2 using tan^-1 and angle/ARG (Various Calculators)

ATAN2

The function atan2(y,x) is defined as:

atan2(y,x) = tan^-1 (y/x) with respect to the quadrant the point (x, y) is in. In case you didn't know, with respect to point (x, y):

(x, y) is in Quadrant I if x > 0 and y > 0
(x, y) is in Quadrant II if x < 0 and y > 0
(x, y) is in Quadrant III if x < 0 and y < 0
(x, y) is in Quadrant IV if x > 0 and y < 0

Visually:

This is different from the two common calculator functions used to find the arctangent: Arctangent and Argument.

The Arctangent Function

TI and Casio Calculators*: tan^-1(y/x)
Hewlett Packard Calculators*: atan (y/x)

* The majority of them

Range (Output): -90° to 90°, -π/2 to π/2 radians

How to use Arctangent to get atan(y,x)

If the point is in quadrant I:
Use atan(y/x)

If the point is in quadrant II or III:
Use atan(y/x) + 180° in degrees mode
Use atan(y/x) + π in radians mode

If the point is in quadrant IV:
Use atan(y/x) + 360° in degrees mode
Use atan(y/x) + 2*π in radians mode

Special cases have to be used x or y is equal to 0:

If x=0 and y<0, the angle is 270° (3*π/2 radians)
If x=0 and y>0, the angle is 90° (π/2 radians)
If y=0 and x<0, the angle is 180° (π radians)
If y=0 and x>0, the angle is 360° or 0° (2*π or 0 radians)


The Argument Function

The complex number x + yi is used.

TI Calculators: angle(x + y*i)
Casio and Hewlett Packard Calculators: ARG(x + y*i)

Range: -180° to 180°, -π to π radians

How to use the Argument function to get atan2(y,x)

This is a great way to get atan2, which cleverly makes the use of complex numbers. In addition, there are a lot fewer things to remember:

If y≥0 (Quadrants I and II):
Use ARG(x+yi)*

(*The angle function if you are using a TI calculator)

If y<0 (Quadrants III and IV):
Use ARG(x+yi) + 360° for degrees mode
Use ARG(x+yi) + 2*π for radians mode


I hope this tip is helpful. Happy Thanksgiving and I am very thankful for all who have read, followed, and supported my blog over the last two years.

Eddie

This blog is property of Edward Shore. 2013

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues The programs are listed for the Swiss Micros DM42 an...