Showing posts with label HP 48. Show all posts
Showing posts with label HP 48. Show all posts

Saturday, August 15, 2026

HP 48G Collection

 HP 48G Collection 


Contents: 

Intensity of Spherical Light Source 

Speed of Light in Dry Air 

Pressure of Air 

Earth's Gravity at a Specific Latitude 

Light of Sight: Altitude


Intensity of the Spherical Light Source



INTSP: 

<< '1_cm' * '1_m' CONVERT SQ 4 * π * →NUM SWAP '1_W' * SWAP / >>


I = P/(4π(r/100)^2)


Input: 

2: power in Watts (W) 

1: spherical radius in centimeters (cm) No need to enter units.

Output: 

1: intensity (W/m^2) with unit object attached



Example:

Input: 

2: 1368 (W) 1: 5 (cm)

Output: 

1: ≈ 43544.7924_W/m^2



Speed of Sound in Dry Air


CAIR: 

<< '1_°C' * '1_K' CONVERT 1.4 * 'R' CONST * '.289647_kg/mol' / UBASE √ >>


c_air = √(φR(T°C+273.15)/M_air) 

φ = 1.4, ideal adiabatic of air 

M_air = 0.289647 kg/mol, mole of air molecule 

R ≈ 8.314462 J/(mol K), ideal gas constant


Input: 

1: temperature in degrees Celsius (°C) No need to enter units


Output: 

1: speed of sound in air (m/s) with unit object attached


Example:


Input: 

1: 18 (°C)

Output: 

1: ≈ 342.0631_m/s


Pressure of Air


ρAIR (ρ character: [ α ] [ |→ ] [ R ]): 

<< '1_°C' * '1_K' CONVERT 287.05007 '1_J' * '1_kg' / '1_K'

* INV 'StdP' CONST '1_Pa' CONVERT * UBASE >>


ρ = P/(R*(T°C+273.15)) 

P = 101325 Pa, Standard temperature of pressure 

R = 287.05007 J/(kg K)


Input: 

1: temperature in degrees Celsius (°C) No need to enter units

Output: 

1: air pressure_J/(kg K) with unit object attached


Example:


Input: 

1: 18 (°C)

Output: 

1: ≈ 1.2124_kg/m^3


Earth's Gravity at a Specific Latitude


The true earth gravity force depends on several factors, such as latitude and altitude. This estimation takes the latitude (north/south) into account.

The constant 9.80665 m/s^2 is an accepted average, the true force varies.


gLAT: 

<< RAD HMS→ 90 / π * →NUM COS .026 * 9.806 SWAP - '1_m/s^2' * >>


g_Earth = g_45-(g_poles + g_equ) / 2 * cos(lat * π / 90 radians) 

Simplified: g_Earth = 9.806 – 0.026 * cos(lat * π / 90)

g_45 ≈ 9.806 m/s^2 

g_poles ≈ 9.832 m/s^2 

g_equ ≈ 9.78 m/s^2 Take the cosine of (latitude * π / 90) radians


Input: 

1: latitude in D.MMSS (degrees, minutes, seconds) No need to enter units

Output:

1: Earth's gravity at latitude_m/s^2 with unit object attached



Example:

Input:
1: 20.2214 (20°22'14")

Output: 

1: ≈ 9.7863_m/s^2

Source: Grainger Engineering Office of Marketing and Communications. (answer written by Rebecca H.) (2016, November 21). “How gravitational force varies at different locations on Earth.” Illinois. https://van.physics.illinois.edu/ask/listing/64061. Retrieved March 10, 2026.



Light of Sight: Altitude

The program calculates altitude required for an airplane to receive a signal from an airplane.


Program LOSALT: 

<< '1_nmi' * 3 ROLLD '1_ft' * '1_nmi' CONVERT '3440_nmi' + SQ 3 ROLLD '1_ft' * '1_nmi' CONVERT '3440_nmi' + SQ DUP 4 ROLL SWAP - √ 3 ROLL SWAP - SQ + √ '3440_nmi' - '1_ft' CONVERT >>


Inputs: 

3: height of the antenna in feet 

2: average height of the terrain between the airplane and antenna 

1: horizontal distance from airplane to antenna in nautical miles

Enter numbers only, no need to attach units.


Output: 

1: required height in feet, _ft unit object attached


Example: 


height of antenna: 426 ft 

average terrain height: 846 ft 

horizontal distance: 57 nautical mi

required altitude: ≈1519.7282 ft

Note: An average Earth radius is 3440 nautical miles is used. Results will vary since Earth is a spheroid.


Formulas Used:

R_ter: terrain height, Rt = radius_Earth + R_ter 

R_atn: antenna height, Ra = radius_Earth + R_atn 

D: distance to antenna 

R_alt: altitude 1 nmi ≈ 6076.1155 ft R_alt = √(Ra^2 + (D - √(Ra^2 - Rt^2))^2) – radius_Earth



This is a partial adaption of the line of sight distance program of the HP 67.

Source: Hewlett Packard. "Line of Sight Distance" HP-67/HP-97 User's Library Solutions: Avigation. Corvallis, OR. Rev. E. April 1979. pp. 18-22


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, November 4, 2017

HP Prime: Best Regression Fit

HP Prime:  Best Regression Fit

The program BESTFIT compares a set of regressions to determine a best fit.  This simulates a feature presented on the Hewlett Packard HP 48S, HP 48G, HP 49G, and HP 50g.  BESTFIT compares the correlations of the following four regression models:

1.  Linear:  y = a * x + b
2.  Logarithmic:  y = a * ln x + b
3.  Exponential:  y = b * a^x   (y = b * e^(ln a * x))
4.  Power: y = b * x^a

The output is a two element list:  a string of the best fit equation and its corresponding correlation.

HP Prime Program:  BESTFIT

EXPORT BESTFIT(L1,L2)
BEGIN
// 2017-11-02 EWS
// Simulate Best Fit
// HP 48GX,49G,50g

// initialize
LOCAL clist,m,c,v,s,n;
clist:={0,0,0,0};

// test
// correlation is linear only
// requires approx()
// linear y=a*x+b
clist[1]:=approx(correlation(L1,L2));
// log y=a*LN(x)+b
c:=approx(correlation(LN(L1),L2));
IF IM(c)==0 THEN
clist[2]:=c;
END;
// exponential y=b*e^(a*x)
c:=approx(correlation(L1,LN(L2)));
IF IM(c)==0 THEN
clist[3]:=c;
END;

// power y=b*a^x
c:=approx(correlation(LN(L1),LN(L2)));
IF IM(c)==0 THEN
clist[4]:=c;
END;

// test
// POS(L0^2,MAX(L0^2))
m:=POS(clist^2,MAX(clist^2));
c:=clist[m];

IF m==1 THEN
v:=linear_regression(L1,L2);
s:=STRING(v[2])+"+"+STRING(v[1])+
"*X";
RETURN {s,c};
END;

IF m==2 THEN
v:=logarithmic_regression(L1,L2);
s:=STRING(v[2])+"+"+STRING(v[1])+
"*LN(X)";
RETURN {s,c};
END;

IF m==3 THEN
v:=exponential_regression(L1,L2);
s:=STRING(v[2])+"*"+STRING(v[1])+
"^X";
RETURN {s,c};
END;

IF m==4 THEN
v:=power_regression(L1,L2);
s:=STRING(v[2])+"*X^"+
STRING(v[1]);
RETURN {v,s};
END;

END;

Examples – BESTFIT:

Example 1:

X
y
1.05
10.45
2.28
11.33
4.20
16.38
6.34
28.87

Result: {“7.78250037344*1.21713132288^X”, 0.981261724397}
Example 2:

X
Y
-10
82
-5
41
5
-42
10
-79

Result:  {“0.5+ -8.1*X”, -0.999801918343}


Example 3:

X
Y
10
2.278
11
2.666
12
2.931
13
3.212

Result:  {“-5.79464870365+3.51429873838*LN(X)”, 0.998295735284}

BESTFIT2:  An Extended Version

Version 2 adds the following regressions: 

5.  Inverse:  y = b + a/x
6.  Simple Logistic:  y = 1/(b + a*e^(-x))
7.  Simple Quadratic:  y = b + a*x^2
8.  Square Root:  y = √(a*x + b)

HP Prime Program:  BESTFIT2

EXPORT BESTFIT2(L1,L2)
BEGIN
// 2017-11-02 EWS
// Simulate Best Fit
// HP 48GX,49G,50g
// additional models

// initialize
LOCAL clist,m,c,v,s;
clist:={0,0,0,0,0,0,0,0};

// test
// correlation is linear only
// requires approx()

// linear y=a*x+b
clist[1]:=approx(correlation(L1,L2));

// log y=a*LN(x)+b
c:=approx(correlation(LN(L1),L2));
IF IM(c)==0 THEN
clist[2]:=c;
END;

// exponential y=b*e^(a*x)
c:=approx(correlation(L1,LN(L2)));
IF IM(c)==0 THEN
clist[3]:=c;
END;

// power y=b*a^x
c:=approx(correlation(LN(L1),LN(L2)));
IF IM(c)==0 THEN
clist[4]:=c;
END;

// inverse y=b+a/x
IF POS(L1,0)==0 THEN
clist[5]:=approx(correlation(1/L1,
L2));
END;

// simple logistic
IF POS(L2,0)==0 THEN
clist[6]:=approx(correlation(e^(−L1),
1/L2));
END;

// simple quadratic
clist[7]:=approx(correlation(L1^2,
L2));

// square root
IF ΣLIST(L2≥0)==SIZE(L2) THEN
clist[8]:=approx(correlation(L1,
L2^2));
END;



// test
// POS(L0^2,MAX(L0^2))
m:=POS(clist^2,MAX(clist^2));
c:=clist[m];

IF m==1 THEN
v:=linear_regression(L1,L2);
s:=STRING(v[2])+"+"+STRING(v[1])+
"*X";
END;

IF m==2 THEN
v:=logarithmic_regression(L1,L2);
s:=STRING(v[2])+"+"+STRING(v[1])+
"*LN(X)";
END;

IF m==3 THEN
v:=exponential_regression(L1,L2);
s:=STRING(v[2])+"*"+STRING(v[1])+
"^X";
END;

IF m==4 THEN
v:=power_regression(L1,L2);
s:=STRING(v[2])+"*X^"+
STRING(v[1]);
END;

// inverse
IF m==5 THEN
v:=linear_regression(1/L1,L2);
s:=STRING(v[2])+"+"+STRING(v[1])+
"/X";
END;

// simple logistic
IF m==6 THEN
v:=linear_regression(e^(−L1),
1/L2);
s:="1/("+STRING(v[2])+"+"+
STRING(v[1])+"*e^(−X))";
END;

// simple quadratic
IF m==7 THEN
v:=linear_regression(L1^2,L2);
s:=STRING(v[2])+"+"+STRING(v[1])+
"*X^2";
END;

// square root
IF m==8 THEN
v:=linear_regression(L1,L2^2);
s:="√("+STRING(v[2])+"+"+
STRING(v[1])+"*X)";
END;

RETURN {s,c};
END;

Examples – BESTFIT2:

Example 4:

X
y
1.05
10.45
2.28
11.33
4.20
16.38
6.34
28.87

Result:  {“9.0573970192+0.48023219108*X^2”, 0.994491728382}

Example 5:

X
y
1
8.4853
2
8.9443
4
9.7980
7
10.9546

Result: {“√(63.9995089183+8.00048914762*X”, 0.999999999759}

Example 6:

X
y
1
1
2
-0.5
3
-1
4
-1.25

Result:  {“-2+3/X”, 1}

Eddie

This blog is property of Edward Shore, 2017

Python: Drawing a Ring of Circles

Python: Drawing a Ring of Circles The goal: Draw a number of circles that revolve around the origin (0,0). The center of each circle i...