Saturday, January 24, 2026

RPN: HP 11C: Surface Gravity and Escape Velocity

RPN: HP 11C: Surface Gravity and Escape Velocity


EQUATIONS


The surface gravity constant of a celestial object (planet, dwarf planet, star, etc.):


g_p = G * M ÷ R²


The escape velocity of a celestial object:


v_esc = √(2 * G * M ÷ R)


where (using SI units):

g_p: surface gravity (m/s)

v_esc: escape velocity (m/s)

M: (measured) mass of the object (kg)

R: (average) radius of the object (m)

G: Universal Gravitational Constant (G ≈ 6.6743 * 10^-11 N m²/kg² (or m³/(s² kg))


The value of G is the 2022 CODATA value (https://physics.nist.gov/cgi-bin/cuu/Value?bg)



Determining Surface Gravity and Escape Velocity



DERIVATION - Determine the surface gravity constant in terms of escape velocity.


Start with the escape velocity:


v_esc = √(2 * G * M ÷ R)

(v_esc)² = 2 * G * M ÷ R


dividing both sides by 2 (we'll see why this important in a bit):


(v_esc)² ÷ 2 = G * M ÷ R

(v_esc)² * 1/2 = G * M * 1/R


Then insert the square of escape velocity in the equation for the surface velocity:


g_p = G * M ÷ R²

g_p = G * M * 1/R²

g_p = G * M * 1/R * 1/R

g_p = (v_esc)² * 1/2 * 1/R

g_p = (v_esc)² ÷ (2 * R)



The equations will the be:


v_esc = √(2 * G * M ÷ R)

g_p = (v_esc)² ÷ (2 * R)


Set the stack up as:

Y: M (mass, kg)

X: R (radius, m)


The results are shown in the stack:

Y: g_p (surface gravity, m/s²)

X: v_esc (escape velocity, m/s)


Algorithm (done with an HP 11C):

ENTER

ENTER

R↑

2

×

6.6743e-11 (Keys: 6 . 6 7 4 3 EEX 1 1 CHS)

×

R↑

÷

ENTER

√ (view escape velocity)

R↓

x<>y

÷

2

÷ (view surface gravity)

R↑ (set surface gravity in the Y stack, escape velocity in the X stack)



Example:


Estimate the surface gravity constant and escape velocity of Venus.


Venus

Mass ≈ 4.8675 * 10^24 kg

Radius ≈ 6.0518 * 10^6 m


Surface gravity ≈ 8.8704 m/s

Escape velocity ≈ 10361.6414 m/s



Determining a Planet's Radius and Escape Velocity


Problem: Given Earth's surface gravity is defined as 9.80665 m/s and mass of 5.972168 * 10^24. Estimate the radius and escape velocity.


Here we are given g_p and M, and we are tasked with finding R and v_esc.


Start by solving for R:


g_p = G * M ÷ R²


Multiply by R² and divide by g_p. Keep this in mind.


R² = G * M ÷ g_p


Take the square root and solve for the radius.


R = √(G * M ÷ g_p)


Note that:


R² = G * M ÷ g_p

g_p * R² = G * M

2 * g_p * R² = 2 * G * M

2 * g_p * R = 2 * G * M ÷ R


This makes for an easy substitution for v_esc.


v_esc = √(2 * G * M ÷ R) = √(2 * g_p * R)


The equations used are:


R = √(G * M ÷ g_p)

v_esc = √(2 * g_p * R)


The algorithm uses one memory register, I just picked R0 (done with an HP 11C):

STO 0

÷

6.6743e-11 (Keys: 6 . 6 7 4 3 EEX 1 1 CHS)

×

√ (view R)

ENTER

RCL 0

×

2

×

√ (view v_esc)



Set the stack up as:

Y: M (mass, kg)

X: g_p (surface gravity, m/s²)


The results are shown in the stack:

Y: R (radius, m)

X: v_esc (escape velocity, m/s)


Results:


Inputs:

Mass of Earth ≈ 5.972168 * 10^24 kg (enter as the y stack)

Surface Gravity = 9.80665 m/s² (enter as a x stack, and yes, surface gravity of Earth is defined to be exactly 9.80665 m/s²)


Outputs:

Y: Radius of Earth ≈ 6375416.060 m

X: Escape Velocity ≈ 11182.2604 m/s



Sources


The NIST Reference on Constants, Units, and Uncertainty. "Newtonian constant of gravitation" Fundamental Physical Constants. Last updated May 9, 2024. https://physics.nist.gov/cgi-bin/cuu/Value?bg Retrieved September 4, 2025.


Research & Education Association. The Essentials of Astronomy Piscataway, New Jersey. 2004. ISBN 0-87891-965-1



Eddie


All original content copyright, © 2011-2026. 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, January 18, 2026

HP 15C: Distance and Slope Between Two Points Using Polar Conversion and the Stack

HP 15C: Distance and Slope Between Two Points Using Polar Conversion and the Stack



HP 15C Program: Distance and Slope



This short program calculates the slope and distance between two Cartesian points (x1, y1) and (x2, y2) using the four level stack and rectangular-polar conversion. The code can be adopted to other Hewlett Packard, Swiss Micros, and other RPN with four-stacks. RPL will need a short adjustment.



Input Stack:

T: y2

Z: x2

Y: y1

X: x1



Code:

LBL A

001

42, 21, 11

Program start

X<>Y

002

34


R↓

003

33


-

004

30


R↓

005

33


-

006

30


CHS

007

16


R↑

008

43, 33

Y: Δy, X: Δx

→P

009

43, 1

Rectangular to polar conversion; calculate distance

X<>Y

010

34


TAN

011

25

Calculate slope

X<>Y

012

34


RTN

013

43, 32

Program end









Reference formulas



Distance = √((x2^2 – x1^2) + (y2^2 – y1^2))

Slope = (y2 – y1) ÷ (x2 – x1) = tan(Θ)



Derivation:

Let y’ = y2 – y1 and x’ = x2 – x1

Then by rectangular to polar function, angle:

Θ = arctan( y’ / x’ )

tan Θ = y’ / x’

tan Θ = (y2 – y1) ÷ (x2 – x1)



Examples



Example 1: (-3, 8) to (11, 16)

Stack:

T: 16

Z: 11

Y: 8

X: -3

Result:

Y: slope ≈ 0.5714

X: distance ≈ 16.1245



Example 2: (5, 6) to (7, 9)

Stack:

T: 9

Z: 7

Y: 6

X: 5

Result:

Y: slope = 1.5000

X: distance ≈ 3.6056


Eddie


All original content copyright, © 2011-2026. 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, January 17, 2026

BASIC vs. Python: Mean and Standard Deviation by an Iterative Method

BASIC vs. Python: Mean and Standard Deviation by an Iterative Method



Calculators Used:

BASIC: Sharp EL-5500 III

Python: Casio fx-CG 100


Introduction


The following code calculates the sum, mean, and standard deviation of a data set. The method that will be used is from voidware.com, which suggests an iterative method, as follows (Voidware):


M_0 = 0, S_0 = 0, n = 0


Loop with data point X:

M_n+1 = M_n + (X – M_n) ÷ (n + 1)

S_n+1 = S_n + (X – M_n) × (X – M_n+1)

n = n + 1


When all the data as been tabulated:

S = √(S ÷ (n – 1))


M: mean

S: standard deviation


Source

“Standard Deviation” Voidware. http://www.voidware.com/sd.htm Website was last updated in 2018. Last Retrieved July 4, 2025.



BASIC: Sharp EL-5500 III



10 PRINT "ONE VAR STATS"

12 CLEAR

30 INPUT "DATA? "; X

32 E=M+(X-M)*(N+1)

34 S=S+(X-M)*(X-E)

36 N=N+1

38 M=E

40 U=U+X

42 INPUT "MORE? (1=YES) "; C

44 IF C=1 THEN 30

60 S=√(S/(N-1))

70 PRINT "# DATA= "; N

72 PRINT "SUM= "; U

74 PRINT "MEAN= "; M

76 PRINT "STD DEV= "; S

78 END



Notes:

CLEAR: clears all the variables A-Z and resets their values to zero

PRINT: pauses the screen while the message is displayed



Python: Casio fx-CG 100

(Can be we used with any calculator with Python)



# one var stat without the math module

# voidware.com/sd.htm



def onevar(data):

  # set up

  m,s,u,n=0,0,0,0

  for i in data:

    e=m+(i-m)/(n+1)

    s+=(i-m)*(i-e)

    n+=1

    m=e

    u+=i

  s=(s/(n-1))**0.5

  return [n,u,m,s]



Notes:

We can store multiple values to variables at once. Example:

var4, var3, var2, var1 = value1, value2, value3, value4



Storage Arithmetic:

s+=expression -> s=s+expression

s-=expression -> s=s-expression

s*=expression -> s=s*expression

s/=expression -> s=s/expression



Example



Data set:

n = 1: x = 105

n = 2: x = 107

n = 3: x = 86

n = 4: x = 96

n = 5: x = 113



Data Structure: [105, 107, 86, 96, 113]



Results:

# DATA: 5 (N)

SUM: 507 (U)

MEAN: 101.4 (M)

STD DEV: 10.54988151 (S)


Eddie


All original content copyright, © 2011-2026. 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.


The author does not use AI engines and never will.



Saturday, January 10, 2026

RPN: A Comparison of Programming Methods: Stack vs. Storage Arithmetic with the HP 32SII

RPN: A Comparison of Programming Methods: Stack vs. Storage Arithmetic with the HP 32SII


News: The RPN series will continue for 2026: Every second Sunday!


Today we will compare two methods to tackle mathematical problems with the HP 32SII. The code presented here will also work with the HP 32S original and the Swiss Micros DM32.


Method 1 (left column): Use of the stack and when necessary, variables to store immediate results.


Method 2 (right column): Use of storage arithmetic to most, if not all, of the arithmetic operations.



What is Storage Arithmetic?


Storage arithmetic executes an arithmetic operation while simultaneously storing the result in the variable.


In all the examples, assume the variable Z starts with the value of 10.


STO+: Storage Addition

Adds the value in the display to the value stored in the variable and stores the result. Outside of RPN and Hewlett Packard calculators, storage addition is the most common storage arithmetic function. On four function calculators and adding machines, storage arithmetic is symbolized with M+. On Texas Instruments scientific calculators, such as the TI-30Xa and the classic TI-30 series, storage addition occurs with the SUM key.


2 STO+ Z adds 2 to Z. The value of Z is now 12.


In Python, the general syntax for storage addition:

var+=<expression>


STO-: Storage Subtraction


Subtracts the value in the display from the value stored in the variable and stores the result. On four function calculators and adding machines, storage arithmetic is symbolized with M-. If you have a TI-55 (1970s version), TI-57 (1970s version), TI-58, TI-59, or T-66, storage subtraction is executed by INV SUM.


2 STO- Z subtracts 2 from Z. The value of Z is now 8.


In Python, the general syntax for storage subtraction:

var-=<expression>



STO×: Storage Multiplication


Multiplies the value in the display from the value stored in the variable and stores the result. If you have a TI-55 (1970s version), TI-57 (1970s version), TI-58, TI-59, or T-66, storage subtraction is executed by Prod (or Prd).


2 STO× Z multiplies 2 to Z. The value of Z is now 20.


In Python, the general syntax for storage multiplication:

var*=<expression>



STO÷: Storage Multiplication


Multiplies the value in the display from the value stored in the variable and stores the result. If you have a TI-55 (1970s version), TI-57 (1970s version), TI-58, TI-59, or T-66, storage subtraction is executed by INV Prod (or Prd).


2 STO÷ Z divides Z by 2. The value of Z is now 5.


In Python, the general syntax for storage multiplication:

var/=<expression>


Example Problems


For fairness, both methods store the final result in Z. Only storage arithmetic is used because not all RPN calculators have recall arithmetic.


Problem 1: (1 + √5) ÷ 2 ≈ 1.61803398875


LBL A

5

SQRT

1

+

2

÷

STO Z

RTN


15.0 bytes

LBL B

1

STO Z

5

SQRT

STO+ Z

2

STO÷ Z

RCL Z

RTN


15.0 bytes


Problem 2: 4² + 3 × 4 – 5 = 4 × (4 + 3) – 5 = 23


LBL C

4

STO X

3

+

RCL X

×

5

-

STO Z

RTN


15.0 bytes

LBL D

4

STO X

STO Z

3

STO+ Z

4

STO× Z

5

STO- Z

RCL Z

RTN


18.0 bytes



Problem 3: √(8.5² + 9.6²) ≈ 12.8222462931


LBL E

8.5

9.6

+

SQRT

STO Z

RTN


29.5 bytes

LBL F

8.5

STO Z

STO× Z

9.6

STO Y

STO× Y

RCL Y

STO+ Z

RCL Z

SQRT

STO Z

RCL Z

RTN


37.0 bytes


Problem 4: (7 × 12) ÷ (7 + 12) ≈ 4.42105263158


LBL G

7

STO X

12

STO Y

×

RCL X

RCL Y

+

÷

STO Z

RTN


18.0 bytes

LBL H

7

STO X

STO Y

12

STO× X

STO+ Y

RCL X

RCL Y

÷

STO Z

RTN


19.5 bytes


Problem 5: 1 ÷ (1 ÷ 4.5 + 1 ÷ 8 + 1 ÷ 6.7) ≈ 2.01419624217


LBL I

4.5

1/x

8

1/x

6.7

1/x

+

+

1/x

STO Z

RTN


35.5 bytes

LBL J

4.5

1/x

STO Z

8

1/x

STO+ Z

6.7

1/x

STO+ Z

RCL Z

1/x

STO Z

RCL Z

RTN


38.5 bytes


Problem 6: 2 × (10.3 – 4.9) + 3 × (5.4 – 2) = 21


LBL K

10.3

4.9

-

2

×

5.4

2

-

3

×

+

STO Z

RTN


45.0 bytes

LBL L

10.3

STO Y

4.9

STO- Y

2

STO× Y

5.4

STO Z

2

STO- Z

3

STO× Z

RCL Y

STO+ Z

RCL Z

RTN


49.5 bytes



Findings


I like storage arithmetic. However from these results, storage arithmetic uses a bit more memory than merely using the stack. Storage arithmetic can be handy dandy technique in programming, not just in keystroke programming but other programming languages like Python.



Eddie


All original content copyright, © 2011-2026. 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.


The author does not use AI engines and never will.


RPN: HP 11C: Surface Gravity and Escape Velocity

RPN: HP 11C: Surface Gravity and Escape Velocity EQUATIONS The surface gravity constant of a celestial object (planet, dwarf p...