Showing posts with label rectangular coordinates. Show all posts
Showing posts with label rectangular coordinates. Show all posts

Sunday, April 26, 2020

Casio fx-CG 50: Shortcuts Study

Casio fx-CG 50: Shortcuts Study

Introduction

When programming in calculators, sometimes it is useful to use alternate ways of accomplishing the task.  The alternate way could save keystrokes and memory, which can become important with older programming calculators and calculators where the number of steps available is about 150 or lower. 

Complex Number Functions

Some of the shortcut methods involves complex numbers and complex number operations, particular involving polar-rectangular conversions.

Below are the four common conversion calculations needed and alternate ways to accomplish them: 

√(x^2 + y^2) = abs(x + y ⅈ) = R>Pr(x,y) 

atan( y / x ) = arg(x + y ⅈ) = R>Pθ(x,y)**

r cos θ = real( r ∠ θ) = P>Rx(r,θ)

r sin θ = imag(r ∠ θ) = P>Ry(r,θ)

** The domain in the atan function is (-90°, 90°) while the arg (sometimes named atan2 and angle) and R>Pθ functions takes the (x,y) coordinates to account and the domain is (-180°, 180°).

Casio fx-CG50 Program: SHORTCUT

The program SHORTCUT illustrates six shortcut techniques regarding:

1.  Law of Cosines - Calculating the Third Side of a triangle

c = √(a^2 + b^2 - 2ab cos θ)
Complex Number Alternate: c = abs( real(a∠θ) - b + imag(a∠θ)*ⅈ )

2.  Rounding to the Nearest Integer

Alternate to the round function:  int( frac x + x 0

3.  √(1 - x^2),  |x| < 1

Trigonometric Alternate:  sin(acos x )

4.  x / √(1 + x^2),  any x

Trigonometric Alternate:  sin(atan x)

5.  √(a^2 + b^2 + c^2)

Complex Number Alternate:  abs(c + abs(a + b*ⅈ) * ⅈ)

6.  √(a^2 + 2*b^2)

Two Step Alternate (this is just one of many ways):
abs(a + b*ⅈ)
abs(b + ans*ⅈ)

Program:

Anything that follows // is a comment.  Don't type the comment in. 

a+bⅈ       // turn complex mode on
"BETTER PROG HP67/97"    // credit to source, slash character from CHAR menu
"EWS 2020-03-09"
Menu "SHORTCUTS","LAW OF COSINES",1,"ROUND TO INTEGER",2,
"√(1-X^2)",3," X÷√(1+X^2)",4,"√(A^2+B^2+C^2)",5,"√(A^2+2*B^2)",6

Lbl 1
"θ"?→θ
"A"?→A
"B"?→B
"√(A^2+B^2-2AB cos θ)"→Str 1
Exp(Str 1)→R            
"Abs(Rep(A∠θ)-B+Imp(A∠θ)ⅈ"→Str 2
Exp(Str 2)→S
Goto R

// Exp numerically evaluates a string 

Lbl 2
"NUMBER"?→X
"RndFix(X,0)"→Str 1
RndFix(X,0)→R      
// Exp(RndFix(a,b)) leads to an error message
"Int (Frac X+X)"→Str 2
Exp(Str 2)→S
Goto R

Lbl 3
"-1
"√(1-X^2) "→Str 1
Exp(Str 1)→R
"sin cos^-1 X"→Str 2
Exp(Str 2)→S
Goto R

Lbl 4
"X"?→X
"X÷√(1+X^2)"→Str 1
Exp(Str 1)→R
"sin tan^-1 X"→Str 2
Exp(Str 2)→S
Goto R

Lbl 5
"A"?→A
"B"?→B
"C"?→C
"√(A^2+B^2+C^2)"→Str 1
Exp(Str 1)→R
"Abs (C+Abs (B+A×ⅈ)×ⅈ)"→Str 2
Exp(Str 2)→S
Goto R

Lbl 6
"A"?→A
"B"?→B
"√(A^2+2B^2)"→Str 1
Exp(Str 1)→R
"Abs (A+Bⅈ):Abs (Ans+Bⅈ)"→Str 2
Exp(Str 2)→S
Goto R

Lbl R
ClrText
Black Locate(1,1,Str 1)
Black Locate(1,2,R)
Blue Locate(1,4,Str 2)
Blue Locate(1,5,S)

//  If you are using a monochrome screen such as the Casio fx-9750gII or fx-9860gII, leave out the Black and Blue commands.


You can download the program file here (fx-CG 50, 696 bytes):
https://drive.google.com/open?id=1b4PzPWEdQ0bV_l3l7vIcThVGxjOR94pb 

Source:
William Kob, John Kennedy, Richard Nelson.  Better Programming On The HP-67/97 PPC 1978

Eddie

All original content copyright, © 2011-2020.  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, March 5, 2017

HP Prime: Parabolic Cylindrical Coordinates



HP Prime:  Parabolic Cylindrical Coordinates




(This is post # 700! Yay!   Thank you for sticking with me on this wonderful journey!)

The Formulas

The relationship and conversion factors between parabolic cylindrical coordinates (μ, v, ϕ) and rectangular coordinates (x, y, z) are as follows:

x = 1/2 * (μ^2 – v^2)
y = μ * v
z = z

μ = √(x + √(x^2 + y^2))
v = y / μ
z = z
(note the sequence)

where μ ≥ 0

Derivation

The formulas to find the rectangular coordinates are given.  We can derive the formulas for the parabolic cylindrical coordinates by the following:

Obviously the z coordinate remains the same in both systems.

Assume μ ≠ 0.  Then:
y = μ * v
v = y / μ

With substitution and simplification:
x = 1/2 * (μ^2 – v^2)
2*x = μ^2 – v^2
2*x = μ^2 – (y^2/μ^2)
2*x*μ^2 = μ^4 – y^2
0 = μ^4 – (2*x)*μ^2 – y^2

We have a quadratic equation in terms of μ^2.  Since μ≥0, only the positive root is considered:
μ^2 = ( 2*x + √(4*x^2 + 4*y^2) ) /2
μ^2 = ( 2*x + 2*√(x^2 + y^2) )/2
μ^2 = x + √(x^2 + y^2)
μ = √( x + √(x^2 + y^2) )

HP Prime Program PCC2REC (Parabolic Cylindrical to Rectangular)

EXPORT PCC2REC(μ,v,z)
BEGIN
// 2017-02-27 EWS
// Parabolic Cylindrical
// to Rectangular
// μ≥0
LOCAL x:=1/2*(μ^2-v^2);
LOCAL y:=μ*v;
RETURN {x,y,z};
END;

HP Prime Program REC2PBC (Rectangular to Parabolic Cylindrical)

EXPORT REC2PCC(x,y,z)
BEGIN
// 2017-02-27 EWS
// Rectangular to
// Parabolic Cylindrical
// μ≥0
LOCAL μ:=√(x+√(x^2+y^2));
LOCAL v:=y/μ;
RETURN {μ,v,z};
END;

Example

μ = 2, v = 3, z = 1
Result:  x = -2.5, y = 6, z = 1

  
Source:
P. Moon and D.E. Spencer.  Field Theory Handbook:  Including Coordinate Systems Differential Equations and Their Solutions.  2nd ed. Springer-Verlag:  Berlin, Heidelberg, New York.  1971.  ISBN 0-387-02732-7

This blog is property of Edward Shore, 2017.

HP Prime: Parabolic Coordinates



HP Prime:  Parabolic Coordinates



The Formulas

The relationship and conversion factors between parabolic coordinates (μ, v, ϕ) and rectangular coordinates (x, y, z) are as follows:

x = μ * v * cos ϕ
y = μ * v * sin ϕ
z = 1/2 * (μ^2 – v^2)

ϕ = atan(y/x)
v = √( -z + √(x^2 + y^2 + z^2))
μ = √( 2*z + v^2)
(note the sequence)

where μ ≥ 0 and v ≥ 0

Derivation

The formulas to find the rectangular coordinates are given.  We can derive the formulas for the parabolic coordinates by the following:

Assume that μ > 0 and v > 0 (neither are zero).  Then:

x = μ * v * cos ϕ  
y = μ * v * sin ϕ
x / y = (μ * v * cos ϕ)/( μ * v * sin ϕ)
x / y = 1 / tan ϕ
y / x = tan ϕ
ϕ = atan (y / x)

Express μ in terms of z:

z = 1/2 * (μ^2 – v^2)
2 * z = μ^2 – v^2
μ^2 = 2*z + v^2

Since μ is positive, only the positive square root is considered:
μ = √(2*z + v^2)

Can we find an expression for v?  If we can, we have found our formulas:

x = μ * v * cos ϕ

Square both sides:
x^2 = μ^2 * v^2 * cos^2 ϕ    (I)

Note that for a given variable w, cos(atan w) = 1 / √(w^2 + 1)
In this case, w = y/x or:
cos^2 ϕ
= (cos (atan ϕ))^2
= √(1 / ((y/x)^2 + 1))^2
= 1 / ((y/x)^2 + 1)
= x^2 / x^2 * 1 / ((y/x)^2 + 1)
= x^2 / (x^2 + y^2)

Back to (I):
x^2 = μ^2 * v^2 * cos^2 ϕ    (I)
‘x^2 = (2*z + v^2) * v^2 * x^2 / (x^2 + y^2)

Assuming x≠0, divide both sides by x^2:
1 = (2*z + v^2) * v^2 * 1 / (x^2 + y^2)
1 = (2*z*v^2 + v^4) * 1/(x^2 + y^2)
0 = 1/(x^2 + y^2) * v^4 + (2*z)/(x^2 + y^2) * v^2 – 1

Here we have a quadratic equations in the form of Av^4 + Bv^2 + C = 0 where:
A = 1/(x^2 + y^2)
B = (2*z)/(x^2 + y^2)
C = -1

The solution is v^2 = (-B + √(B^2 – 4*A*C)/(2*A).  Remember that v > 0, so only positive roots will be considered.  Then:
-B/(2*A)  = -(2*z)/(x^2 + y^2) * (x^2 + y^2)/2 = -z


And:
B^2 – 4*A*C = (4*z^2 + 4*(x^2 + y^2))/(x^2 + y^2)^2
√( B^2 – 4*A*C) = 2 * √(x^2 + y^2 + z^2)/(x^2 + y^2)
√( B^2 – 4*A*C)/(2*A) = √(x^2 + y^2 + z^2)

Hence:
v^2 = -z + √(x^2 + y^2 + z^2)
v = √(-z + √(x^2 + y^2 + z^2))

HP Prime Program PBC2REC (Parabolic to Rectangular)

EXPORT PBC2REC(u,v,φ)
BEGIN
// Parabolic to Rectangular
// u≥0, v≥0, 0≤φ<2π
// EWS 2017-02-28
LOCAL x:=u*v*COS(φ);
LOCAL y:=u*v*SIN(φ);
LOCAL z:=1/2*(u^2-v^2);
RETURN {x,y,z};
END;

HP Prime Program REC2PBC (Rectangular to Parabolic)

EXPORT REC2PBC(x,y,z)
BEGIN
// Rectangular to Parabolic
// u≥0, v≥0, 0≤φ<2π
// EWS 2017-02-28
LOCAL φ:=ATAN(y/x);
LOCAL v:=√(−z+√(x^2+y^2+z^2));
LOCAL u:=√(2*z+v^2);
RETURN {u,v,φ};
END;

Examples (angles are in radians)

μ = 1, v = 3, ϕ = 0.4
Result:  x ≈ 2.76318, y ≈ 1.16826, z = -4

x = 1.69042, y = 7.9006. z = -2.76432
Result:  μ ≈ 2.40311, v ≈ 3.36208, ϕ ≈ 1.36000

Source:
P. Moon and D.E. Spencer.  Field Theory Handbook:  Including Coordinate Systems Differential Equations and Their Solutions.  2nd ed. Springer-Verlag:  Berlin, Heidelberg, New York.  1971.  ISBN 0-387-02732-7

This blog is property of Edward Shore, 2017.

Earth's Radius by Latitude

Earth's Radius by Latitude Introduction: Calculating the Earth’s Radius In quick, general calculations, we assume that the...