Gaussian Integration - Decimal to Fraction - Base Conversion - Prime factors - Numerical Derivative - Modulo - Big Factorial - 2D Coordinate Rotation - Stair Calculation - Triangle Solution - RNEAR - Hyperfocal Distance

Description

J E Patterson - jepspectro.com - 20180413

This program works with the DM15C series of calculators by SwissMicros. The extended memory firmware should be installed. The hp15c Simulator by Torsten Manz can be used as well if the DM15C preferences are set to 229 registers. The programs are self-contained so they can be extracted as separate programs.

**********************************************************************************************************************

Gaussian Integration - Valentín Albillo


Gaussian Integration starts at line 1 and finishes at line 51

Numerical integration on the 11C
Numerical Integration: HP, TI, etc.


This is a test program adapted for the hp15c, from a hp11c program by Valentín Albillo. The only real difference is the DSE statement. Also the documentation has been edited.

Enter equation code between LBL . 1 and RTN

Store the number of sub-intervals in Register I. N must be an integer number equal or greater than 1. The larger N, the more precise the result will be and the longer it will take to run.

N STO I
Enter limit a ENTER and limit b
GSB A

The integral is displayed.

Where divide by zero may be a problem enter 1E-99 for one limit of zero.

Examples:
1. Compute the integral of f(x) = 6x5 between x=-6 and x=45.

As f(x) is a 5th degree polynomial, we expect an exact result, save for minor rounding errors in the very last place. Let's compute it:

- Define f(x): LBL . 1 5 yx 6 * RTN
- Store the number of subintervals, just one will do: 1 STO I
- Enter the limits and compute the integral: 6 CHS ENTER 45 GSB A

- The result is returned within 6 seconds: -> 8,303,718,967

The exact integral is 8,303,718,969, so our result is exact to 10 digits within 2 ulps, despite using just one subinterval and despite the large interval of integration.

2. Compute the integral of f(x)=Sin(x)/x between x=0 and x=2

- Set RAD mode and define f(x): LBL . 1 SIN LSTX ÷ RTN
- Store the number of subintervals, let's try just 1: 1 STO I
- Enter the limits and compute the integral: 1 EEX 9 9 CHS ENTER 2 GSB A

- The result is returned within 5 seconds: -> 1.605418622

Testing with 2,3, and 4 subintervals we get (the exact integral being 1.605412977):

N subintervals Computed integral Time
-------------------------------------------
1 1.605418622 5 sec.
2 1.605413059 11 sec.
3 1.605412984 16 sec.
4 1.605412978 22 sec.

so even using just 2 subintervals does provide 8-digit accuracy, and using 4 nails down the result to 10 digits save for a single unit in the last place.

That's all. I think you'll agree this simple Gaussian method beats Simpson's and Trapezoidal Rules hands down. :-)

**********************************************************************************************************************

Decimal to Fraction - Joseph Horn


Decimal to Fraction starts at line 52 and ends at line 96

Decimal to Fraction for the HP-15C

Version 1.2
Converts any positive decimal number to a fraction. Accuracy is controlled by the current FIX setting.

Instructions:
(1) Use a FIX setting as desired.
(2) Place decimal number in X.
(3) GSB B ➯ see numerator.
(4) X<>Y ➯ see denominator.

Optional:
÷ RCL - 0 ➯ “error” (difference between input and output)

Example:
Convert π to a fraction accurate to 5 decimal places.
(1) FIX 5
(2) π
(3) GSB B ➯ 355 (4) X<>Y ➯ 113
Answer: 355/113

Notes:
(a) The program uses registers 0 through 2, so make sure that enough register memory is allocated.
(b) As always, turning off USER mode makes it easier to key in the program.
(c) When the program finishes, register 0 contains your original input. Registers 1 and 2 are used for
temporary storage.
(d) The Golden ratio, 1.618033989, is the most challenging (takes longest time).

**********************************************************************************************************************

Base Conversion - Thomas Klemm


Base Conversion starts at line 97 and ends at line 121

The Museum of HP Calculators - hp11C Base Conversion
The Museum of HP Calculators - hp67 Base Conversion

Description:
This program allows to convert numbers from one base to another.

Register:
Reg 1: from-base
Reg 2: to-base
N GSB C to run

Examples:
Convert decimal 21 to binary
Reg 1: 1 0 STO 1
Reg 2: 2 STO 2
2 1 GSB C
Display: 10101

Convert CAFE Hexadecimal to decimal
Reg 1: 1 6 STO 1
Reg 2: 1 0 0 STO 2 - note larger decimal number used because of the 2 digit hexadecimal number representation
Hexadecimal CAFE = 12:10:15:14
1 2 1 0 1 5 1 4 GSB C
Display: 51966

**********************************************************************************************************************

Prime Factorization - Eddie Shore


Prime Factorization starts at line 122 and ends at line 150

Prime Factorization
The Museum of HP Calculators - Prime Factorization

N GSB D for prime factors of N

This program factors an integer N.
Fix 0 mode is activated during execution.
Each factor is displayed by pressing R/S.
The calculator is returned to FIX 4 mode when the program is completed.
If the integer is a prime number, the program just returns the integer entered.

Example: 150 GSB D.
Factors, displayed with R/S, are 2, 3, 5, 5 (when the display reads 150.0000 the factorization ends)

**********************************************************************************************************************

Numerical Derivative - Eddie Shore


Numerical Derivative starts at line 151 and ends at line 191

Numerical Derivative
The Museum of HP Calculators - Numerical Derivative

Calculate numerical derivatives of f(x).

Computing accurate numerical derivatives can present a challenge.
Often, calculation involves a small increment, usually named h.
Generally, the smaller h is, the better the calculation.
However with certain methods, if h is too small, the final result may be unexpected.

This program uses a five-point formula:

f′(x) ≈ (f(x - 2h) - 8 * f(x - h) + 8 * f(x + h) - f(x + 2h)) / (12h)

The error is of the order of h^4.

Source: Burden, Richard L. and J. Douglas Faires. "Numerical Analysis 8th Edition" Thomson Brooks/Cole Belton, CA 2005

Instructions:
1. Press GTO 8.
2. Enter program mode P/R.
3. Enter the function f(R1) between GSB 8 and the following RTN.
4. Exit program mode P/R.
5. Enter X, press ENTER.
6. Enter h, press GSB E.
7. The approximate numerical derivative is displayed.

Example 1

Let f(x) = x*ex

Estimate f'(2) with h = 0.0001

The function that follows has already been entered. Edit for other functions as in example 2.
LBL 8
ENTER
e^x
×
RTN

To find the derivative:

Press 2 ENTER . 0 0 0 1 GSB E

Result: f(2) ≈ 22.1672

Example 2
Let f(x) = -x2 + 2x + 3
Estimate f'(1.5) with h = 0.0001
We can rewrite f(x) as:
f(x) = -x2 + 2x + 3
-1 * (x2 - 2x - 3)
-1 * (x * (x - 2) - 3)

Use the last form as the function.

GTO 8 g P/R

Step through and alter content between LBL 8 and RTN as required.
For example:

LBL 8
ENTER
ENTER
2
-
×
3
-
CHS
RTN

To find the derivative:

1 . 5 ENTER . 0 0 0 1 GSB E

Result: f'(1.5) ≈ -1

**********************************************************************************************************************

Modulo - Gamo


Modulo starts at line 192 and ends at line 203

The Museum of HP Calculators - (12C) Modulo (the remainder after division)

x mod y = x – y*int(x/y) is more accurate than the alternative x mod y = y*frac(x/y) which displays roundoff errors.

x ENTER y GSB 0

Example:
156511533 MOD 1546223
156511533 ENTER 1546223 GSB 0 result 343010

**********************************************************************************************************************

Big Factorial program for the HP-15C - Torsten Manz


Big Factorial starts at line 204 and ends at line 258

Torsten Manz

This program computes the factorial of large numbers up to 1x108.

It computes the mantissa separately from the exponent. Enter the number to factorialize in the X register. Then press GSB 1.

The mantissa is shown and then the exponent, after a short delay

X<>Y allows either to be seen.

**********************************************************************************************************************

2D Coordinate Rotation - Eddie Shore


2D Coordinate Rotation starts at line 259 and ends at line 279

2D Coordinate Rotation
The Museum of HP Calculators - 2D Coordinate Rotation

Input:
Store the following: X in R4, Y in R5, and θ in R3. Run the program - GSB 2.

Results are stored in R6 and R7, for X’ and Y’, respectively. X’ is displayed first, press R/S to get Y’.

This program uses the Polar to Rectangular conversion.

Formulas Used:
X’ = X * cos θ – Y * sin θ
Y’ = X * sin θ + Y * cos θ

Examples:
X (R4) = 1, Y (R5) = 2, θ (R3) = 30°. Results: X’ (R6) ≈ -0.1340, Y’ (R7) ≈ 2.2321

**********************************************************************************************************************

Stair Calculation - Eddie Shore


Stair Calculation starts at line 280 and ends at line 299

Stair Calculation

Store riser height in R0 (RH)
Store horizontal run in R1
Store vertical rise in R2

GSB 3 displays number of stairs (S)
R/S displays treadwidth (TW)
R/S displays stringer length (ST)

S = int(rise/RH)-1
TW = run/S
ST = S * √(RH2 + TW2)

Example:

R0 = 7 inches (riser height)
R1 = 56 inches (horizontal run)
R2 = 80 inches (vertical rise)

Results:

R3 = 10 (number of stairs)
R4 = 5.6 inches (treadwidth)
R5 ≈ 89.6437 inches (stringer)

**********************************************************************************************************************

Triangle Solution provided 2 sides and 1 angle - Gamo


Triangle Solution starts at line 300 and ends at line 318

Triangle Solution

Find the 3rd side and 2 remaining angles.

Sides Angles
a=4 A=28.9550°
b=6 B=46.5674°
c=8 C=104.4775°

a ENTERENTER c GSB 4 for b R/S for A° R/S for C°

Example:
4 ENTER 4 6 . 5 6 7 4 ENTER 8 GSB 4 = 6
R/S = 28.9550°
R/S = 104.4775°

**********************************************************************************************************************

RNEAR - Round to nearest 1/n - Eddie Shore, Dieter. Modified for hp-15c - J E Patterson.


RNEAR starts at line 319 and ends at line 328

Round to nearest 1/n
Round to nearest 1/n - discussion

The program RNEAR rounds a number x to the nearest 1/n. For example, to round x to the nearest 10th, n = 10. To round to the nearest
16th, n = 16.

x ENTER n GSB 5
x is a positive number and n is a positive integer.

Examples:
x = π
n = 10, result: 3.10 (nearest 10th)
n = 1000, result: 3.142 (nearest 1000th)
n = 16, result: 3.125 (nearest 16th)

**********************************************************************************************************************

Hyperfocal Distance - Gamo, Dieter

Hyperfocal Distance starts at line 329 and ends at line 342

Hyperfocal Distance

Hyperfocal Distance is the closest distance setting at which a lens should be focused while still keeping everything, from half the hyperfocal distance to infinity, sharp.

Formula: H = (f2 / Ac) + f

H - Hyperfocal distance in millimetres
f - Lens focal length in millimetres
A - Aperture the f-number
c - Circle of confusion in millimetres

The Circle of Confusion size that you need to use in the above formula are as follows, these camera formats are used mostly by digital SLR

- Full Frame Camera (36x24mm) = 0.03mm
- Sensor with 1.6 times crop factor of Full Frame = 0.019mm
- Sensor with 2 times crop factor of full frame = 0.015 mm

Dieter: Instead of the Circle of Confusion c, simply enter the crop factor, which is what most users will be more familiar with:

Examples:

"full frame":
3 5 ENTER 1 1 ENTER 1 GSB 6 => 3.75

APS-C:
3 5 ENTER 1 1 ENTER 1 . 5 GSB 6 => 5.60
Note for ASP-C crop factors vary from 1.3x to 1.7x, depending on the camera used. 1.5x is a safe guess.

(Micro-) Four Thirds:
3 5 ENTER 1 1 ENTER 2 GSB 6 => 7.46

Note that the precision required is not high as the focussing scales of typical old syle manual lenses are usually just numbers with no exact scale markings. My 50 mm, f 1.8, Olympus lense is only marked with the metre numerals 0.45, 0.5, 0.7, 1, 1.5, 2, 5 10 and ∞. The alternative is to use a tape measure and focussing through the viewfinder.

**********************************************************************************************************************

Program Resources

Labels

Name Description Name Description Name Description
 A Gaussian Integration  3 Stair calculation .4
 B Convert decimal to fraction  4 Triangle solution .5
 C Base Conversion  5 Round to nearest 1/n .6
 D Calculate the prime factors of N  6 Hyperfocal Distance .7
 E Numerical derivative .0 .8
 0 Modulo .1 .9
 1 Big Factorial .2
 2 Coordinate rotation .3

Storage Registers

Name Description Name Description
 0  5
 1  6
 2  7
 3 I Number of intervals
 4

Program

Line Display Key Sequence Line Display Key Sequence Line Display Key Sequence
000 115 20 × 230 34 x↔y
001 42,21,11 f LBL A 116 44,40, 0 STO + 0 231 10 ÷
002 44 1 STO 1 117 33 R⬇ 232 30
003 30 118 22 .5 GTO . 5 233 1 1
004 45 25 RCL I 119 42,21, .6 f LBL . 6 234 40 +
005 10 ÷ 120 45 0 RCL 0 235 43 13 g LOG
006 44 0 STO 0 121 43 32 g RTN 236 45 0 RCL 0
007 2 2 122 42,21,14 f LBL D 237 1 1
008 10 ÷ 123 42, 7, 0 f FIX 0 238 12
009 44,40, 1 STO + 1 124 44 2 STO 2 239 10 ÷
010 48 . 125 44 0 STO 0 240 43 13 g LOG
011 6 6 126 2 2 241 45 0 RCL 0
012 11 √x̅ 127 44 1 STO 1 242 20 ×
013 20 × 128 42,21, .8 f LBL . 8 243 40 +
014 44 3 STO 3 129 45 0 RCL 0 244 45 0 RCL 0
015 43 35 g CLx 130 45,10, 1 RCL ÷ 1 245 43 26 g π
016 44 2 STO 2 131 36 ENTER 246 20 ×
017 42,21, .0 f LBL . 0 132 42 44 f FRAC 247 2 2
018 45 1 RCL 1 133 43 20 g x=0 248 20 ×
019 45 3 RCL 3 134 22 .7 GTO . 7 249 11 √x̅
020 40 + 135 1 1 250 43 13 g LOG
021 32 .1 GSB . 1 136 44,40, 1 STO + 1 251 40 +
022 5 5 137 22 .8 GTO . 8 252 44 1 STO 1
023 20 × 138 42,21, .7 f LBL . 7 253 42 44 f FRAC
024 44,30, 2 STO 2 139 45 1 RCL 1 254 13 10ˣ
025 45 1 RCL 1 140 31 R/S 255 42 31 f PSE
026 45 3 RCL 3 141 33 R⬇ 256 45 1 RCL 1
027 30 142 33 R⬇ 257 43 44 g INT
028 32 .1 GSB . 1 143 44 0 STO 0 258 43 32 g RTN
029 5 5 144 1 1 259 42,21, 2 f LBL 2
030 20 × 145 30 260 45 3 RCL 3
031 44,30, 2 STO 2 146 43,30, 0 g TEST x≠0 261 45 4 RCL 4
032 45 1 RCL 1 147 22 .8 GTO . 8 262 42 1 f → R
033 32 .1 GSB . 1 148 45 2 RCL 2 263 44 6 STO 6
034 8 8 149 42, 7, 4 f FIX 4 264 34 x↔y
035 20 × 150 43 32 g RTN 265 44 7 STO 7
036 44,30, 2 STO 2 151 42,21,15 f LBL E 266 45 3 RCL 3
037 45 0 RCL 0 152 44 2 STO 2 267 45 5 RCL 5
038 44,40, 1 STO + 1 153 33 R⬇ 268 42 1 f → R
039 42, 5,25 f DSE I 154 44 1 STO 1 269 45 7 RCL 7
040 22 .0 GTO . 0 155 2 2 270 40 +
041 45 2 RCL 2 156 45,20, 2 RCL × 2 271 44 7 STO 7
042 20 × 157 30 272 34 x↔y
043 1 1 158 32 .9 GSB . 9 273 16 CHS
044 8 8 159 44 0 STO 0 274 45 6 RCL 6
045 10 ÷ 160 45 1 RCL 1 275 40 +
046 43 32 g RTN 161 45,30, 2 RCL 2 276 44 6 STO 6
047 42,21, .1 f LBL . 1 162 32 .9 GSB . 9 277 31 R/S
048 23 SIN 163 8 8 278 34 x↔y
049 43 36 g LSTx 164 16 CHS 279 43 32 g RTN
050 10 ÷ 165 20 × 280 42,21, 3 f LBL 3
051 43 32 g RTN 166 44,40, 0 STO + 0 281 45 2 RCL 2
052 42,21,12 f LBL B 167 45 1 RCL 1 282 45,10, 0 RCL ÷ 0
053 44 0 STO 0 168 45,40, 2 RCL + 2 283 43 44 g INT
054 44 1 STO 1 169 32 .9 GSB . 9 284 1 1
055 0 0 170 8 8 285 30
056 36 ENTER 171 20 × 286 44 3 STO 3
057 36 ENTER 172 44,40, 0 STO + 0 287 31 R/S
058 1 1 173 45 1 RCL 1 288 15 1/x
059 43 33 g R⬆ 174 2 2 289 45,20, 1 RCL × 1
060 42,21, .2 f LBL . 2 175 45,20, 2 RCL × 2 290 44 4 STO 4
061 43 44 g INT 176 40 + 291 31 R/S
062 43 33 g R⬆ 177 32 .9 GSB . 9 292 43 11 g
063 20 × 178 16 CHS 293 45 0 RCL 0
064 40 + 179 44,40, 0 STO + 0 294 43 11 g
065 44 2 STO 2 180 45 0 RCL 0 295 40 +
066 32 .4 GSB . 4 181 45,10, 2 RCL ÷ 2 296 11 √x̅
067 34 x↔y 182 1 1 297 45,20, 3 RCL × 3
068 10 ÷ 183 2 2 298 44 5 STO 5
069 43 34 g RND 184 10 ÷ 299 43 32 g RTN
070 45 0 RCL 0 185 44 0 STO 0 300 42,21, 4 f LBL 4
071 43 34 g RND 186 43 32 g RTN 301 34 x↔y
072 43,30, 5 g TEST x=y 187 42,21, .9 f LBL . 9 302 36 ENTER
073 22 .3 GTO . 3 188 36 ENTER 303 43 33 g R⬆
074 40 + 189 12 304 42 1 f → R
075 43 35 g CLx 190 20 × 305 43 33 g R⬆
076 45 2 RCL 2 191 43 32 g RTN 306 30
077 36 ENTER 192 42,21, 0 f LBL 0 307 16 CHS
078 36 ENTER 193 36 ENTER 308 43 1 g →P
079 43 33 g R⬆ 194 36 ENTER 309 31 R/S
080 45 1 RCL 1 195 30 310 43 35 g CLx
081 42 44 f FRAC 196 33 R⬇ 311 43 26 g π
082 15 1/x 197 34 x↔y 312 43 3 g →DEG
083 44 1 STO 1 198 43 36 g LSTx 313 34 x↔y
084 22 .2 GTO . 2 199 10 ÷ 314 31 R/S
085 42,21, .3 f LBL . 3 200 43 44 g INT 315 43 33 g R⬆
086 45 2 RCL 2 201 20 × 316 40 +
087 42,21, .4 f LBL . 4 202 30 317 30
088 36 ENTER 203 43 32 g RTN 318 43 32 g RTN
089 36 ENTER 204 42,21, 1 f LBL 1 319 42,21, 5 f LBL 5
090 45 0 RCL 0 205 44 0 STO 0 320 44 1 STO 1
091 20 × 206 1 1 321 20 ×
092 48 . 207 2 2 322 48 .
093 5 5 208 20 × 323 5 5
094 40 + 209 15 1/x 324 40 +
095 43 44 g INT 210 45 0 RCL 0 325 43 44 g INT
096 43 32 g RTN 211 43 11 g 326 45 1 RCL 1
097 42,21,13 f LBL C 212 2 2 327 10 ÷
098 44 0 STO 0 213 8 8 328 43 32 g RTN
099 44 3 STO 3 214 8 8 329 42,21, 6 f LBL 6
100 45 1 RCL 1 215 20 × 330 15 1/x
101 45 2 RCL 2 216 15 1/x 331 48 .
102 30 217 40 + 332 0 0
103 34 x↔y 218 45 0 RCL 0 333 3 3
104 42,21, .5 f LBL . 5 219 3 3 334 20 ×
105 45 1 RCL 1 220 14 335 20 ×
106 34 x↔y 221 5 5 336 10 ÷
107 45 2 RCL 2 222 1 1 337 20 ×
108 10 ÷ 223 8 8 338 40 +
109 43 44 g INT 224 4 4 339 26 EEX
110 43 20 g x=0 225 0 0 340 3 3
111 22 .6 GTO . 6 226 20 × 341 10 ÷
112 33 R⬇ 227 1 1 342 43 32 g RTN
113 20 × 228 3 3
114 33 R⬇ 229 9 9