Sunday, February 28, 2021

TI-84 Plus CE and TI-73 Explorer: Analog Clock

 TI-84 Plus CE and TI-73 Explorer:  Analog Clock


Introduction


The program ANALOG draws a 12-hour analog clock for any given time, given the hour and minute.  The TI-73 program covers the TI-73 Explorer and should be ported to any of the Texas Instruments calculators with monochrome screens with no or little adjustment.


The TI-84 Plus CE adds colors:  hour hand is black, minute hand is brown, the markers are orange.  Adjust colors to your liking.


Notes:


*  The program pauses when the clock is drawn.  Pressing [ENTER] restores turns the Axes back on.


*  The Pt-On command has the syntax Pt-On(x, y, mark, color*).   Mark:  Dot (1 or default), Open Square (2), Plus (3).   Color applies only to the TI-84 Plus CE or TI-84 Plus C Silver Edition.


*  The program sets the calculator to degrees mode.


Math:


Let H be the hour and M be the minute.


Set S = H + M/60,  where S is the decimal hour of the time given.


For a circle of 360°, each hour occupies 30° of the clock (360/12).  Like wise, each minute occupies 6° of the clock  (360/60).


A = 30*S,  B= 6*M


Lines are drawn from the origin (0,0) to a point (x,y).  If we set x and y to an angle θ, then:


x = r * cos θ,  y = r * sin θ, where r is the length of the line.


Angels on a cartesian plane start from the positive x-axis and measured going counter-clockwise.  However, on the analog clock requires angels to measured from the top (due north) and rotate clockwise.  This will require a vertical flip and adjusting the angle by 90°.  The adjusted coordinates are:

 

x = r * cos (θ-90°),  y = -r * sin (θ- 90°), where r is the length of the line.



TI-73 Program: ANALOG

(this includes TI-73 Explorer)


"EWS 2021"

FnOff

PlotsOff

ClrDraw

Degree

Disp "12 HR ANALOG"

Input "HOUR? ",H

Input "MINUTE? ",M

ZStandard

ZSquare

AxesOff

Circle(0,0,8)

For(X,30,360,30)

Pt-On(7*cos(X-90),-7*sin(X-90),2)

End

Line(0,0,5*cos(30H+M-90),-5*sin(30H+M-90))

Line(0,0,7*cos(6M-90),-7*sin(6M-90))

Pause

AxesOn


TI-84 Plus CE Program:  ANALOG


"EWS 2021-01-18"

FnOff 

PlotsOff 

ClrDraw

Degree

Disp "12 HOUR ANALOG CLOCK"

Input "HOUR? ",H

Input "MINUTE? ",M

ZStandard

ZSquare

AxesOff

GridOff

"FACE"

Circle(0,0,8,MEDGRAY)

For(I,30,360,30)

Pt-On(7*cos(I-90),­7*sin(I-90),2,ORANGE)

End

"HOUR"

Line(0,0,5*cos(30H+M/2-90),­5*sin(30H+M/2-90),1,BLACK)

"MINUTE"

Line(0,0,7*cos(6*M-90),­7*sin(6*M-90),1,BROWN)

Pause 

AxesOn 



Next week, more fun with the TI-73 Explorer.  


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. 


Saturday, February 27, 2021

Review: Victor 940

 Review:  Victor 940






Just the Facts


Company:  Victor

Type:  Scientific - Algebraic

Display:  10 digits with 2 digit exponents

Power:  Solar with battery back up LR43 battery

Memory Registers: 8:  A, B, C, D, E, F, X, Y, M

Cost:  about $8 to $10

Website:  https://www.victortech.com/product/940


Features


*  Trigonometry, Exponential, Logarithms

*  Factorial, Combinations, Permutations

*  Algebraic Expression Evaluation with fractions

*  Memory Arithmetic with M+ and M-

*  Statistics

*  Regressions:  Linear, Logarithm, Exponential, Power, Inverse, Quadratic

*  Two Line Display:  the top line is for typing mathematical expressions, the bottom line is for displaying results.


Essentially, the Victor 940 is a clone of the Casio fx-300MS/fx-85WA.  Many calculators are OEM clones, two other examples include the Bazic 300 and Hewlett Packard HP 10s+.  


You can find more information about the Casio fx-300MS/fx-85WA here:  

http://edspi31415.blogspot.com/2019/01/retro-review-casio-fx-85wa.html


Keyboard


The Victor 940 has a white keyboard with sky blue and orange font.   What differs the Victor 940 are:


*  The display is nice and large compared to the rest.  


*  I like the colors on the keyboard and the contrast on the font.  It could be just personal preference.  


*  The placement of the [ ON ], [ MODE ], [ALPHA], and [SHIFT] keys are different:  with the [ ON ] and [ MODE ] keys on the left of the arrow keys and [ALPHA] and [SHIFT] keys on the right of the arrow keys.  


I am not a fan of the plastic cover case.  Removing the case the first time was difficult and will require force.  The case does not cover the entire calculator, leaving the top of the calculator is left uncovered.  The case does cover the screen, keys, and solar panels are covered.


Verdict


I like the big screen on the Victor 940.  Other than that, it is like the Casio fx-300MS: plenty of functions for a low price.  



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. 


Sunday, February 21, 2021

TI-84 Plus CE and HP 17BII+: Euclidian Divison

 TI-84 Plus CE and HP 17BII+: Euclidian Division


What is the ├ symbol on the calculator?

(├ the symbol is a vertical line with a horizontal line coming from the center to the right)


In several scientific calculators sold in Europe such as the Texas Instruments TI-40 Galaxy:


http://www.datamath.org/Sci/Galaxy/TI40_Galaxy.htm


and the current TI-Primaire Plus, which is sold in France, 


http://www.datamath.org/Sci/Modern/TI-PrimairePlus.htm


There is a key marked [ ├ ].  Going through the manual for the TI-40 Galaxy, this is the Euclidean Division key, which returns the quotient and remainder of the division.


x ├ y returns two results:

Q = int(x/y)   (quotient)

R = x - frac(x/y) * y   (remainder)


The TI-84 Plus family has the remainder function (I think it is OS 2.5 and later).  Here are several ways to emulate the Euclidian Division function:


TI-84 Plus CE Program:  EUCDIV


Prompt X,Y

{int(X/Y),remainder(X,Y)}


HP 17BII+ Formula:


EUCDIV: 0=IF(S(Q): IP(X÷Y)-Q: MOD(X:Y)-R)


Inputs: X,Y

Outputs:  Q (quotient), R (remainder)


Examples:


25 ├ 7 ->  Q = 3, R = 4

77 ├ 6 ->  Q = 12, R = 5


Can we use the [ a b/c ] fraction key?  


Calculators such as the Casio fx-260 Solar II calculator could be used to simulate the Euclidean division with the [ a b/c ] key.  The fraction would be illustrated in the mixed fraction format.  Let us illustrate:


56 [ a b/c ] 5 [ = ]   11 _ 1 / 5    

(Q = 11,  R = 1, divisor = 5)


125 [ a b/c ] 14 [ = ]  8 _ 13 / 14

(Q = 8,  R = 14, divisor = 14)


So far so good, but...


9314 [ a b/c ] 60 [ = ]  155 _ 7 / 30

Look at the denominator:  it is 30 not in 60, the fraction has been simplified.   Of course, we know that 7/30 = 14/60, hence Q = 155, R = 14. 


Note:  if you use the [ a b/c ] key, be sure to look at the resulting denominator is not the same,  it is not in the Q _ R / D form.  


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. 


Saturday, February 20, 2021

Sharp EL-501X: Some Complex Powers

 Sharp EL-501X:  Some Complex Powers 


Introduction


This covers the class of calculators, including the Sharp EL-501X, TDE ATC-1335 Scientific Calculator, the 1980s calculator Texas Instruments TI-35 Plus and some scientific calculators (including Jot) that are purchased from dollar stores.


These set of calculators have a complex mode which allows with arithmetic calculations (addition, subtraction, multiplication, division) and conversions between polar and rectangular form.   The keys [ a ] and [ b ] serve as two temporary registers in calculations.


However, since the complex mode does not allow for extended calculations or storing and recalling numbers in the memory register, I am not going to use the complex number mode for today's algorithms.  


Let z = x + yi  (i = √-1), we can calculate the following:


Square of the complex number:  z^2


Square root of the complex number:  √z


Cube Root of the complex number:  z^(1/3)


Reciprocal of the complex number:  1/z  


Recall the complex number can be taken by any power n, where n is a real number, can be found by:


(x + y*i)^n = (r * e^(i*θ))^n = r^n * e^(i*θ*n) 


where 


r = abs(x + yi) = x^2 + y^2

θ = arg(x + yi) = atan2(x,y)

e^(i*θ*n) = cos(θ*n) + i * sin(θ*n)

r^n * e^(i*θ*n) = r^n * cos(θ*n) + i * r^n * sin(θ*n)


We can use the memory register and the polar (→rθ) and rectangular (→xy) conversions.



I used and tested the following calculators:  Sharp EL-501X and TDE ATC-1335 (the calculators pictured above).


Warning:  Pressing the equals key [ = ] clears out the a and b registers.  This limits the range of powers n can be take (without having to write immediate results).  


The Algorithms


Note:  Due to potential keyboard differences, I will leave out the shifted key.  Please refer to your calculator manual for details.  


Please note the sequence of the keystrokes.  Recall that pressing the equals key clears out the a and b registers.  


Also, since there are conversion to and from the polar form, the angle measure does not matter.


Finally, do not switch the calculator to complex number mode.  Be in regular mode. 


Square:  (x + yi)^2 


x [ a ] y [ b ] [ →rθ ] [ STO ]

[ b ] [ × ] 2 [ = ] [ b ] 

[ RCL ] [ x^2 ] [ a ] [ →xy ]

(real part displayed) 

[ b ] (imaginary part displayed)


Example:  (6 - 3i)^2 = 27 - 36i


6 [ a ] 3 [+/-] [ b ] [ →rθ ] [ STO ]

[ b ] [ × ] 2 [ = ] [ b ] 

[ RCL ] [ x^2 ] [ a ] [ →xy ]

27

[ b ] -36


Square Root:  √(x + yi)


x [ a ] y [ b ] [ →rθ ] [ STO ]

[ b ] [ ÷ ] 2 [ = ] [ b ] 

[ RCL ] [ √ ] [ a ] [ →xy ]

(real part displayed) 

[ b ] (imaginary part displayed)


Example:  √(6 - 3i) ≈ 2.52073441 - 0.595064674i


6 [ a ] 3 [+/-] [ b ] [ →rθ ] [ STO ]

[ b ] [ ÷ ] 2 [ = ] [ b ] 

[ RCL ] [ √ ] [ a ] [ →xy ]

2.52073341

[ b ] -0.595064674


Cube Root:  (x + yi)^(1/3)


x [ a ] y [ b ] [ →rθ ] [ STO ]

[ b ] [ ÷ ] 2 [ = ] [ b ] 

[ RCL ] [ ³√ ] [ a ] [ →xy ]

(real part displayed) 

[ b ] (imaginary part displayed)


Example:  (6 - 3i)^(1/3) ≈ 1.863493911- 0.290316636i


6 [ a ] 3 [+/-] [ b ] [ →rθ ] [ STO ]

[ b ] [ ÷ ] 2 [ = ] [ b ] 

[ RCL ] [ ³√ ] [ a ] [ →xy ]

(real part displayed) 

[ b ] (imaginary part displayed)


Reciprocal:  1/(x + yi)


x [ a ] y [ b ] [ →rθ ] [ STO ]

[ b ] [ ÷ ] 1 [ +/- ] [ = ] [ b ] 

[ RCL ] [ 1/x ] [ a ] [ →xy ]

(real part displayed) 

[ b ] (imaginary part displayed)


Example:  1/(6 - 3i) ≈ 0.133333333 + 0.066666667i


6 [ a ] 3 [+/-] [ b ] [ →rθ ] [ STO ]

[ b ] [ ÷ ] 1 [ +/- ] [ = ] [ b ] 

[ RCL ] [ 1/x ] [ a ] [ →xy ]

0.133333333 

[ b ] 0.066666667


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. 


Monday, February 15, 2021

Review: Swiss Micros DM16L

Review: Swiss Micros DM16L






Welcome to a special Monday edition of Eddie’s Math and Calculator blog!


General Information


Company:  SwissMicros, https://www.swissmicros.com

Type:  Programmable Scientific - Boolean Algebra

Memory: 203 steps, shared with memory registers; 32 MB external flash

Battery:  CR 2032

Connection:  USB-B

Cost:  119 CHF, about $132.38 USD (2/5/2021)

Current Software Version:  DM16_31, 7/21/2020

Case Included?  Yes

Operating System: RPN (Reverse Polish Notation)


A Programmer’s Paradise

The Swiss Micros DM16L, and it’s small version, the DM16, is a clone of the highly popular and sought after Hewlett Packard HP 16C.  The functions are suited to computer science, including:


One key conversions between Hexadecimal (base 16), Octal (base 8), Decimal (base 10), and Binary (base 2) integers.  


Boolean features including AND, OR, NOT,  XOR


Bit shift and rotating functions, masking bits, and double division, remainder, and multiplication


There is a separate floating point arithmetic mode, separate from decimal integer mode.


You can customize integers up to 64 bits by the WSIZE function.  A handy shortcut is to set integers up to 64 bits is done by the key sequence:  0 [ f ] [ STO ] (WSIZE)


Negation of integers are determined by one of three modes:  1’s Complement, 2’s Complement, and Unsigned Numbers.    


If that isn’t enough, you can manipulate and test specific bits with the SB (set bit), CB (clear bit), and B? (is the bit set) commands. 


The STATUS command gives the user a three number status #-##-####. 


The first number is the complement mode:  0 for unsigned, 1 for 1’s complement, 2 for 2’s complement.


The second number is the current wordsize, from 1 bit to 64 bits.


The third number is the status of the four user flags 0 to 3, in descending order (flag 3, flag 2, flag 1, flag 0):  0 for clear, 1 for set.  The user flags are used in programming.


Programming


If you have programmed on the original HP-16C, then you would be right at home programming with the DM16L, with all the key codes and positions intact.   There are eight comparison tests available:  x≤y, x<0, x>y, x>0, x≠y, x≠0, x=y, x=0.   Up to 16 labels can be used, labels 0-F.  The special registers I and (I) are used for indirect storage and branching.   The DSE and ISZ use register I.


Curiously missing is storage arithmetic.   For example, instead of STO+ #, the following sequence of commands must be used:  (number), RCL #, +, STO #.  


Sample Programs


Integer Division:  Quotient and Remainder


001 LBL A         43,22,A

002 STO 0 44,0

003 X<>Y 34

004 STO 1 44, 1

005 X<>Y 34

006 ÷ 10

007 R/S 31

008 RCL 1 45, 1

009 RCL 0 45, 0

010 RMD 42, 9   \\ remainder command

011 RTN 43, 21


Example:  Word size = 16


Decimal Integer Mode (DEC):   41 / 7 = 5, remainder 6

Y:  41, X:  7 [ GSB ] [ A ]

Result:   5, [ R/S ], 6


Hexadecimal Integer Mode (HEX):  FE2 / 81 = 1F, remainder 43

Y:  FE2, X: 81 [ GSB ] [ A ]

Result:  1F, [ R/S ], 43


Adding Both the 1’s and 2’s Complement


001 LBL B 43, 22, B

002 STO 1 44, 1

003 Set 1’s 42, 1

004 CHS 49

005 STO 0 44, 0

006 RCL 1 45, 1

007 Set 2’s 42, 2

008 CHS 49

009 RCL 0 45, 0   // storage arithmetic is not available

010 + 40

011 STO 0 44, 0

012 RTN 43, 21


Examples:  Word Size = 8


Hexadecimal Integer Mode (HEX)

x = 2D

Result:  A5  (D2 + D3)


Hexadecimal Integer Mode (HEX)

x = F6

Result:  13  (9 + A)


Remember: Word size is important, as your mileage may vary.  


Verdict

Swiss Micros continues to manufacture quality calculators.  Due to the rarity and highly sought after HP 16C, the price to obtain one may be out of reach.  The DM16L is a much more affordable alternative.  The calculator is solid, keys feel great, and the added connectivity is an added bonus.  


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. 


Sunday, February 14, 2021

HP Prime and Numworks: Luhn Algorithm

 HP Prime and Numworks: Luhn Algorithm


The Luhn Algorithm:   Is Your Credit Card Number Valid?


The Luhn algorithm, created by IBM scientist Hans Peter Luhn in 1954, also known as the modulus 10 algorithm, is a checksum algorithm used to check the validity certain numbers used in financial transactions, such as identification numbers and credit card numbers. The algorithm is in public domain and serves as a basic check.  


The general steps of the Luhn Algorithm:


1.  Starting at the rightmost digit, double every other digit (2nd digit from the rightmost digit, 4th digit from right, 6th digit from right, and so on)


2.  If the digit that is doubled is at least 10, add the digits together.  


Replace 10 with 1.

Replace 12 with 3.

Replace 14 with 5.

Replace 16 with 7.

Replace 18 with 9.


3.  Take the sum of all the digits.


4.  If the sum is a multiple of 10 (sum modulo 10 is equal to zero), the number is considered valid.


Example:  4366357


For illustration purposes, let's separate each of the digits:


4  3  6  6  3  5  7


There are 7 digits.  


2nd digit from the most right:  5.  Double it to 10.  1 + 0 = 1


4  3  6  6  3  1  7


4th digit from the most right:  6.  Double it to 12.  1 + 2 = 3


4  3  6  3  3  1  7


6th digit from the most right:  3.  Double it to 6.  


6  6  3  3  1  7


Now add the digits:  4 + 6 + 6 + 3 + 3 + 1 + 7 = 30


10 divides into 30 evenly, or 30 mod 10 = 0.   The integer 4366357 is valid according to the Luhn algorithm.  


HP Prime Program:  LUNH


EXPORT LUHN()

BEGIN

// Luhn Algorithm - HP Prime

// strings are used to accommodate

// string: type 2

LOCAL s,l,k,c,t,n;


INPUT({{s,[[2]]}},

"Luhn Algorithm",

{"N?"},{"Integer"});

l:=DIM(s);

k:=l;


// total

t:=0;


// loop

WHILE k>0 DO

n:=EXPR(MID(s,k,1));

IF FP((l-k)/2)==0.5 THEN

IF n≠0 THEN

n:=(2*n-1) MOD 9+1;

END;

END;

t:=t+n;

k:=k-1;

END;


// final results

IF t MOD 10==0 THEN

RETURN "VALID";

ELSE

RETURN "NOT VALID";

END;


END;


Numworks Python Script:  luhn.py


from math import *

# Luhn Algorithm

# 2021-01-10 EWS

# Numworks Python


# strings are used

s=str(input('Integer? '))

l=len(s)

k=l


# total

t=0


# loop

while k>0:

  n=float(s[k-1])

  f=(l-k)/2

  if f-int(f)==0.5:

    if n!=0:

      n=fmod(2*n-1,9)+1

  t=t+n

  k=k-1


# final results

if fmod(t,10)==0:

  print("VALID")

else:

  print("NOT VALID")



Examples


38348 returns NOT VALID


14956 returns NOT VALID


4382 returns VALID



Source


"Luhn algorithm" GeeksforGeeks. Noida, Uttar Pradesh.  https://www.geeksforgeeks.org/luhn-algorithm/  Retrieved January 1, 2021.


"Luhn algorithm".  Wikipedia.  Last Updated December 23, 2020.  https://en.wikipedia.org/wiki/Luhn_algorithm  Retrieved January 1, 2021.  



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. 


Saturday, February 13, 2021

HP Prime CHOOSE for Repeated Use - Present Value

 HP Prime CHOOSE for Repeated Use - Present Value


Introduction:  Using the CHOOSE Command to Allow for Repeated Calculations


The use of REPEAT and CHOOSE will allow the programmer to set up a choose from a set of calculations and allows for additional calculations until the user exits the program.  


Here is a sample syntax, with comments followed by double slashes (//):


// Set up local variables:  a choice variable, a list of options, the size of the list

LOCAL ch, lst, s;


// Use a list of options.  Be sure to have the last option as "Exit", "Quit", etc.

lst:={"opiton 1", "option 2", ... , "Exit"};

s:=SIZE(lst);


// Set a choice variable to a starting value. Use a "dummy" value to begin with, like -1.  The choice variable will take on a positive integer value after the CHOOSE command has been executed.

ch:=-1;


// The REPEAT loop

REPEAT

CHOOSE(ch,"title",lst);


IF ch==1 THEN

[choice 1 - calculation]

END;


IF ch==2 THEN

[choice 2 - calculation]

END;


...


IF ch==n-1 THEN

[choice n-1 - calculation]

END;


UNTIL ch==s;   // This is the Exit option


Let's look at an example program.



HP Prime Program: PVACT


*  This is an example program that uses CHOOSE to allow for repeated calculations.   The application is for several types of present value for several types of annuities.


*  As a bonus, you can save some settings, such as format and number of digits, to variables before switching settings that the program requires.  This allows for the programmer to restore settings at the end of the program.  


EXPORT PVACT()

BEGIN

// EWS 2021-01-10

// CHOOSE demonstration

// loop until user exits


// Grab the settings

LOCAL h1,h2;

h1:=HFormat;

h2:=HDigits;


// ch choice varaible

LOCAL ch,n,p,r,m,w,v;

LOCAL lst,s,g;


// Set a "dummy" initial choice

// for ch

ch:=−1;


// Set a list of choices

lst:={"Constant Annuity",

"Growing Annuity",

"Perpetual Annuity",

"Exit"};

s:=SIZE(lst);


// Set decimal fix to 2 places

HFormat:=1;

HDigits:=2;


// Use a Repeat loop to allow

// more than one calculation

REPEAT


CHOOSE(ch,"Present Value",lst);

 

// Constant Annuity - Choice 1

IF ch==1 THEN

INPUT({n,r,m},"Constant Annuity",

{"n?  ","i%? ","PMT? "},

{"number of payments",

"periodic interest rate",

"payment"});

v:=Finance.TvmPV(n,r,−m,0,1);

PRINT();

PRINT("n = "+n);

PRINT("i% = "+r);

PRINT("PMT = "+m);

PRINT("PV = "+v);

// show the screen

// WAIT is needed in a loop

WAIT();

END;


// Growing Annuity - choice 2

IF ch==2 THEN

INPUT({n,r,g,m},"Growing Annuity",

{"n?  ","i%? ","g%? ","PMT? "},

{"number of payments",

"periodic interest rate",

"payment growth rate",

"base payment"});

w:=(1+0.01*g)/(1+0.01*r);

v:=m/(1+0.01*r)*(1-w^n)/(1-w);

PRINT();

PRINT("n = "+n);

PRINT("i% = "+r);

PRINT("g% = "+g);

PRINT("Base Payment = "+m);

PRINT("PV = "+v);

// show the screen

// WAIT is needed in a loop

WAIT();

END;


// Perpetual Annuity - choice 3

IF ch==3 THEN

INPUT({r,m},"Perpetual Annuity",

{"i%? ","PMT? "},

{"interest rate",

"payment"});

v:=m/(0.01*r);

PRINT();

PRINT("r% = "+r);

PRINT("PMT = "+m);

PRINT("PV = "+v);

// show the screen

// WAIT is needed in a loop

WAIT();

END;


// if Exit is selected

UNTIL ch==s;


// Restore the setting

HFormat:=h1;

HDigits:=h2;

END;



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. 


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.


Casio fx-9750GIII and fx-CG 50: Playing Games with the Probability Simulation Mode

Casio fx-9750GIII and fx-CG 50: Playing Games with the Probability Simulation Mode The Probability Simulation add-in has six type...