Maths1 - CurveP - Prime Factorization - Little Gauss formula - TVM - Quadratic Equation Solver - Convert to Fraction - Solve a System of Linear Equations - Nth-degree Polynomial Fitting

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.

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

CurveP - J E Patterson - jepspectro.com - version 20180409

CurveP starts at line 1 and finishes at line 148.

The program fits data that may be linear at low x,y amplitudes but y falls off at higher x values.
This is a common issue in many physical systems. x1, y1 should preferably be on the linear part of the curve.
CurveP is not a regression. It assumes that the data is reasonably precise. Linear and power curves can be fitted, as well.

The equation used is y = scale*xorder + slope*x*e-factor*x. See Curve Fitting at jepspectro.com.


Originally chart recorders were used to obtain data which occupied the y axis, leaving interpreted results naturally plotted on the x axis, when graphed on the same paper.
Here we are using y as the equation output axis.

x is first normalised, the equation solved and un-normalised to get y.
The equation parameters, scale, order, slope and factor are found by entering some standard data.

y1 ENTER, y2 ENTER, y3 GSB A
x1 ENTER, x2 ENTER, x3 R/S

Do not press ENTER after y3 or x3.
y3>y2>y1 and x3>x2>x1.
After normalisation y3 = x3 = 10 so x3 is not saved. y3 is used instead in the program.

The curve runs through the origin and three points (x1,y1) (x2,y2) (x3,y3).
The order of the upper part of the curve is displayed.
x input to GSB B to get y.
If there is a blank value, enter it and subtract the answers.

Enter f USER to avoid the GSB or f key during data input.

Test [x,y] data sets [2,2; 4,5; 5,8] [1,1; 2,4; 3,9] [1,1; 2,2; 3,3] [20,3.69; 30,8.64; 47,22.16]
Enter y data then GSB A and x data then R/S. eg. y1 ENTER y2 ENTER y3 GSB A, x1 ENTER x2 ENTER x3 R/S.
The last data set relates an element's atomic number to its X-ray fluorescence k line energy in keV
See Moseley's Law.

In this update I have improved the starting values for the iteration. Order is limited to 10

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

Prime Factorization - Eddie Shore

Prime Factorization starts at line 149 and finishes at line 177.

N GSB C 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:1 5 0 GSB C.
Factors, displayed with R/S, are 2, 3, 5, 5 (when the display reads 150.0000 the factorization ends)

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

Little Gauss formula for the HP-15C - J E Patterson - version 20170723

Little Gauss formula starts at line 178 and finishes at line 184.

The sum of integers up to n are calculated.

I adapted a 9 step subroutine by Torsten Manz to produce a new 7 step program.
The 9 step subroutine used the original formula found by Carl Friedrich Gauss:

n n(n + 1)
k = ——————————
k=1 2

This version uses the rearranged sum (n2 + n)/2.

1. Enter the number n to compute the sum of integers from 1 to n.
2. Press GSB D to run.

Example:
n = 100, (n2 + n)/2 = 5050.
n= 1000, (n2 + n)/2 = 500500.

Note that the sum is the mid-point (average) x n.
For the even number sum 1 to 10, the mid-point (average) is 5.5. The sum is 5.5 x 10 = 55.
Looking at your open hands there are usually 10 fingers - assume they represent the integers 1 to 10.
Starting to count at one thumb and ending with 10 at the other thumb, the mid-point (average) is between the little fingers, i.e at 5.5.
For the odd number sum 1 to 9, the mid-point (average) is 5. The sum is 5 x 9 = 45.
For 1 to 100 you can just average 1 and 100 or 50 and 51 = 50.5. The sum is 50.5 x 100 = 5050.
For 1 to 99 the average is 50. The sum is 50 x 99 = 4950.

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

TVM - Accurate TVM usage instructions - Jeff Kearns

TVM starts at line 185 and finishes at line 224.

1. Store 4 of the following 5 variables, using appropriate cash flow conventions as follows:
N STO 1 --- Number of compounding periods
I STO 2 --- Interest rate (periodic) expressed as a %
B STO 3 --- Initial Balance or Present Value
P STO 4 --- Periodic Payment
F STO 5 --- Future Value
and store the appropriate value (1 for Annuity Due or 0 for Regular Annuity) as
B/E STO 6 --- Begin/End Mode. The default is 0 for regular annuity or End Mode.

2. Store the register number containing the floating variable to the indirect storage register f I.

3. f SOLVE E

Example from the HP-15C Advanced Functions Handbook-

"Many Pennies (alternatively known as A Penny for Your Thoughts):

A corporation retains Susan as a scientific and engineering consultant.
Her fee is one penny per second for her thoughts, paid every second of every day for a year.
Rather than distract her with the sounds of pennies dropping, the corporation proposes to deposit them for her into a bank account.
Interest accrues at the rate of 11.25 percent per annum compounded every second.
At year's end these pennies will accumulate to a sum

total = (payment) X ((1+i/n)^n-1)/(i/n)

where payment = $0.01 = one penny per second,
i = 0.1125 = 11.25 percent per annum interest rate,
n = 60 X 60 X 24 X 365 = number of seconds in a year.

Using her HP-15C, Susan reckons that the total will be $376,877.67.
But at year's end the bank account is found to hold $333,783.35 .
Is Susan entitled to the $43,094.32 difference?"

31,536,000 STO 1
(11.25/31,536,000) STO 2
0 STO 3
-0.01 STO 4
5 STO I
f SOLVE E

The HP-15C now gives the correct result: $333,783.35.

Thanks to Thomas Klemm for debugging the routine.
The code has been edited to reflect Thomas' suggested changes.

Jeff Kearns

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

Quadratic Equation Solver program - Torsten Manz

Quadratic Equation Solver starts at line 225 and finishes at line 318.

This program finds the roots of a quadratic equation of the form ax2 + bx + c = 0.
Push a, b, and c into the Z, Y, and X registers of the stack respectively, then press GSB 1.
The discriminant b2 - 4ac is displayed briefly.
If it is positive there are two real roots.
If is zero there is one real root.
If it is negative there are two complex roots.
The roots of the equation will appear in the X and Y registers.
Use X<>Y to view the second root.
If the "C" indicator appears then the roots are complex.
f (i) can be used to temporarily view the imaginary parts.
Press g CF 8 to clear this flag before running the routine again.

Example: a = 1, b = 2, c = 3.
1 ENTER 2 ENTER 3 GSB 1
Roots are in x and y.
x= -1 - √2i
pressf (i) to view the imaginary part.
x<>y
y = -1 + √2i
pressf (i) to view the imaginary part.

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

Convert to Fraction - Guido Socher

Convert to Fraction starts at line 319 and finishes at line 342.

Let's say you would like to know what 0.15625 as a fraction is.
You type: 0.15625.
GSB 2
The display shows "running" and then you see first 5, and then a second later, 32
The fraction is therefore 5/32 (numerator = 5 and denominator = 32).
32 remains in X (display) after the program finishes and 5 remains in Y.

Guido's RPN calculators

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

Solve a System of Linear Equations - J E Patterson - version 20170723

Solve a System of Linear Equations starts at line 343 and finishes at line 377.

N GSB 3 where N is the number of equations (8 or less).

A N N is displayed.
Matrix [A] has a dimension of NxN.

Enter the coefficients of xi where i has values from 1 to N
Press R/S after each is entered.

B N 1 is displayed.
Matrix [B] has a dimension of Nx1.

Enter the constants.
Press R/S after each is entered.

C N 1 is displayed.
Matrix [C] has a dimension of Nx1.

Values for xi are read out in turn by pressing R/S.

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

Nth-degree Polynomial Fitting - Valentín Albillo

Nth-degree Polynomial Fitting starts at line 378 and finishes at line 420.

N GSB 4 to start the program where N<8
1.0000 is displayed, this is a prompt to enter x value for the first data point.
At xn+1 the prompt returns to 1.0000 so enter the first y data point.
At yn+1 R/S returns a0
Repeat R/S to get all the polynomial coefficients up to an.

GSB 5 can be used to enter new y data.
An extended memory DM15c calculator should be used as space is a little tight on a standard hp15c

For a more complete explanation go here

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

Program Resources

Labels

Name Description Name Description Name Description
 A CurveP - Enter y inputs  4 Nth degree Polynomial Fitting .2 Prime factor Loop
 B CurveP - Enter x inputs  5 Enter new yi values for same xi .3 Prime factor Loop
 C CurveP - Enter x to get y  6 Nth-degree Polynomial Fitting Loop .4 Convert to fraction - loop and test
 D Little Gauss formula  7 Nth-degree Polynomial Fitting Loop .5 Linear equations - coefficients of xi storage loop
 E TVM Solve  8 Matrix [B] xi coefficients readout Loop .6 Linear Equations - constant storage loop
 1 Quadratic equation solver  9 Dummy label to skip when matrix is full .7 Linear equations - result display
 2 Convert to Fraction .0 CurveP - loop .8 Quadratic equation - subroutine
 3 Solve a System of Linear Equations .1 RCL.5 1/x STO.5 .9 Quadratic equation - subroutine

Storage Registers

Name Description Name Description Name Description
 0 Fraction, decimal input value, row index for matrix elements  7 xscale, Ps .4 scale
 1 y1, N, Result ,GI, column index for matrix elements  8 yscale, Pt .5 temp1
 2 y2, I,loop rows  9 slope, Pw .6 temp2
 3 y3, .0 absolute decimal number for fraction .7 temp3
 4 order, PMT, Pd .1 x1 .8 xinput
 5 factor, FV, .2 x2 (i) Register of TVM value required
 6 count, B/E 1/0 .3 order first guess I Loop columns

Flags

Number Description
8 Indicates, by showing "C" in the display, that the roots are complex numbers

Program

Line Display Key Sequence Line Display Key Sequence Line Display Key Sequence
000 141 45 3 RCL 3 282 20 ×
001 42,21,11 f LBL A 142 10 ÷ 283 44 1 STO 1
002 44 8 STO 8 143 43 32 g RTN 284 42 30 f Re↔Im
003 33 R⬇ 144 42,21, .1 f LBL . 1 285 44 .1 STO . 1
004 44 2 STO 2 145 45 .5 RCL . 5 286 42 30 f Re↔Im
005 33 R⬇ 146 15 1/x 287 45 3 RCL 3
006 44 1 STO 1 147 44 .5 STO . 5 288 45 .3 RCL . 3
007 45 8 RCL 8 148 43 32 g RTN 289 42 25 f I
008 1 1 149 42,21,13 f LBL C 290 20 ×
009 0 0 150 42, 7, 0 f FIX 0 291 2 2
010 44 3 STO 3 151 44 2 STO 2 292 20 ×
011 10 ÷ 152 44 0 STO 0 293 30
012 44,10, 2 STO ÷ 2 153 2 2 294 42 31 f PSE
013 44,10, 1 STO ÷ 1 154 44 1 STO 1 295 42 30 f Re↔Im
014 31 R/S 155 42,21, .3 f LBL . 3 296 42 31 f PSE
015 44 7 STO 7 156 45 0 RCL 0 297 42 30 f Re↔Im
016 33 R⬇ 157 45,10, 1 RCL ÷ 1 298 11 √x̅
017 44 .2 STO . 2 158 36 ENTER 299 44 0 STO 0
018 33 R⬇ 159 42 44 f FRAC 300 42 30 f Re↔Im
019 44 .1 STO . 1 160 43 20 g x=0 301 44 .0 STO . 0
020 45 7 RCL 7 161 22 .2 GTO . 2 302 45,40, .2 RCL + . 2
021 45 3 RCL 3 162 1 1 303 42 30 f Re↔Im
022 10 ÷ 163 44,40, 1 STO + 1 304 45,40, 2 RCL + 2
023 44,10, .2 STO ÷ . 2 164 22 .3 GTO . 3 305 45 1 RCL 1
024 44,10, .1 STO ÷ . 1 165 42,21, .2 f LBL . 2 306 45 .1 RCL . 1
025 45 3 RCL 3 166 45 1 RCL 1 307 42 25 f I
026 45 2 RCL 2 167 31 R/S 308 10 ÷
027 10 ÷ 168 33 R⬇ 309 45 2 RCL 2
028 43 12 g LN 169 33 R⬇ 310 45,30, 0 RCL 0
029 45 3 RCL 3 170 44 0 STO 0 311 45 .2 RCL . 2
030 45 .2 RCL . 2 171 1 1 312 45,30, .0 RCL . 0
031 10 ÷ 172 30 313 42 25 f I
032 43 12 g LN 173 43,30, 0 g TEST x≠0 314 45 1 RCL 1
033 10 ÷ 174 22 .3 GTO . 3 315 45 .1 RCL . 1
034 44 4 STO 4 175 45 2 RCL 2 316 42 25 f I
035 44 .3 STO . 3 176 42, 7, 4 f FIX 4 317 10 ÷
036 1 1 177 43 32 g RTN 318 43 32 g RTN
037 44 5 STO 5 178 42,21,14 f LBL D 319 42,21, 2 f LBL 2
038 0 0 179 43 11 g 320 43 16 g ABS
039 44 6 STO 6 180 43 36 g LSTx 321 44 0 STO 0
040 45 1 RCL 1 181 40 + 322 1 1
041 45,10, .1 RCL ÷ . 1 182 2 2 323 44 1 STO 1
042 44 9 STO 9 183 10 ÷ 324 42,21, .4 f LBL . 4
043 42,21, .0 f LBL . 0 184 43 32 g RTN 325 33 R⬇
044 1 1 185 42,21,15 f LBL E 326 15 1/x
045 44,40, 6 STO + 6 186 44 24 STO (i) 327 44,20, 1 STO × 1
046 45 3 RCL 3 187 45 2 RCL 2 328 36 ENTER
047 45 4 RCL 4 188 26 EEX 329 43 44 g INT
048 43,30, 7 g TEST x>y 189 2 2 330 30
049 45 .3 RCL . 3 190 10 ÷ 331 4 4
050 44 4 STO 4 191 36 ENTER 332 16 CHS
051 45 3 RCL 3 192 36 ENTER 333 13 10ˣ
052 45 5 RCL 5 193 1 1 334 43 10 g x≤y
053 45,20, 3 RCL × 3 194 40 + 335 22 .4 GTO . 4
054 16 CHS 195 43 12 g LN 336 45 0 RCL 0
055 12 196 34 x↔y 337 45 1 RCL 1
056 45,20, 3 RCL × 3 197 43 36 g LSTx 338 43 44 g INT
057 45,20, 9 RCL × 9 198 1 1 339 20 ×
058 30 199 43,30, 6 g TEST x≠y 340 42 31 f PSE
059 45 3 RCL 3 200 30 341 43 36 g LSTx
060 45 4 RCL 4 201 10 ÷ 342 43 32 g RTN
061 43,30, 2 g TEST x<0 202 20 × 343 42,21, 3 f LBL 3
062 45 .3 RCL . 3 203 45,20, 1 RCL × 1 344 43, 5, 8 g CF 8
063 44 4 STO 4 204 36 ENTER 345 42,16, 0 f MATRIX 0
064 14 205 12 346 36 ENTER
065 10 ÷ 206 45,20, 3 RCL × 3 347 42,23,11 f DIM A
066 44 .4 STO . 4 207 34 x↔y 348 42,16, 1 f MATRIX 1
067 45,10, 1 RCL ÷ 1 208 2 2 349 45,16,11 RCL MATRIX A
068 45 .1 RCL . 1 209 10 ÷ 350 42 31 f PSE
069 45 4 RCL 4 210 42,22,23 f HYP SIN 351 42,21, .5 f LBL . 5
070 14 211 43 36 g LSTx 352 31 R/S
071 20 × 212 12 353 u 44 11 USER STO A
072 44 .5 STO . 5 213 20 × 354 22 .5 GTO . 5
073 1 1 214 2 2 355 45,23,11 RCL DIM A
074 43,30, 8 g TEST x<y 215 20 × 356 42,16, 1 f MATRIX 1
075 32 .1 GSB . 1 216 45,20, 4 RCL × 4 357 1 1
076 1 1 217 26 EEX 358 42,23,12 f DIM B
077 45 .5 RCL . 5 218 2 2 359 45,16,12 RCL MATRIX B
078 30 219 45,10, 2 RCL ÷ 2 360 42 31 f PSE
079 43 12 g LN 220 45,40, 6 RCL + 6 361 42,21, .6 f LBL . 6
080 16 CHS 221 20 × 362 31 R/S
081 45,10, .1 RCL ÷ . 1 222 40 + 363 u 44 12 USER STO B
082 44 5 STO 5 223 45,40, 5 RCL + 5 364 22 .6 GTO . 6
083 45,20, .2 RCL × . 2 224 43 32 g RTN 365 3 3
084 16 CHS 225 42,21, 1 f LBL 1 366 45,16,12 RCL MATRIX B
085 12 226 43, 6, 8 g F? 8 367 42 31 f PSE
086 45,20, .2 RCL × . 2 227 22 .9 GTO . 9 368 45,16,11 RCL MATRIX A
087 45,20, 9 RCL × 9 228 44 3 STO 3 369 42,26,13 f RESULT C
088 45 .4 RCL . 4 229 33 R⬇ 370 10 ÷
089 45 .2 RCL . 2 230 16 CHS 371 42,16, 1 f MATRIX 1
090 45 4 RCL 4 231 44 2 STO 2 372 42,21, .7 f LBL . 7
091 14 232 43 11 g 373 31 R/S
092 20 × 233 34 x↔y 374 u 45 13 USER RCL C
093 40 + 234 2 2 375 22 .7 GTO . 7
094 44 .6 STO . 6 235 20 × 376 42,16, 0 f MATRIX 0
095 45 2 RCL 2 236 44 1 STO 1 377 43 32 g RTN
096 45,10, 3 RCL ÷ 3 237 45,20, 3 RCL × 3 378 42,21, 4 f LBL 4
097 3 3 238 2 2 379 42,16, 0 f MATRIX 0
098 0 0 239 20 × 380 1 1
099 20 × 240 30 381 40 +
100 45,10, 6 RCL ÷ 6 241 42 31 f PSE 382 44 2 STO 2
101 11 √x̅ 242 43,30, 2 g TEST x<0 383 36 ENTER
102 45,20, .6 RCL × . 6 243 22 .8 GTO . 8 384 42,23,11 f DIM A
103 45 .6 RCL . 6 244 11 √x̅ 385 1 1
104 45,30, 2 RCL 2 245 44 0 STO 0 386 42,23,12 f DIM B
105 10 ÷ 246 45,40, 2 RCL + 2 387 42,16, 1 f MATRIX 1
106 15 1/x 247 45,10, 1 RCL ÷ 1 388 42,21, 6 f LBL 6
107 1 1 248 45 2 RCL 2 389 45,23,12 RCL DIM B
108 40 + 249 45,30, 0 RCL 0 390 30
109 44 .7 STO . 7 250 45,10, 1 RCL ÷ 1 391 44 25 STO I
110 45,20, 4 RCL × 4 251 43 32 g RTN 392 45 0 RCL 0
111 44 4 STO 4 252 42,21, .8 f LBL . 8 393 31 R/S
112 45 .7 RCL . 7 253 43, 4, 8 g SF 8 394 36 ENTER
113 1 1 254 11 √x̅ 395 36 ENTER
114 30 255 42 30 f Re↔Im 396 36 ENTER
115 43 16 g ABS 256 45,10, 1 RCL ÷ 1 397 1 1
116 1 1 257 44 .0 STO . 0 398 u 44 11 USER STO A
117 26 EEX 258 45 2 RCL 2 399 42,21, 7 f LBL 7
118 16 CHS 259 45,10, 1 RCL ÷ 1 400 20 ×
119 6 6 260 42 25 f I 401 u 44 11 USER STO A
120 43,30, 8 g TEST x<y 261 42 30 f Re↔Im 402 42,21, 9 f LBL 9
121 22 .0 GTO . 0 262 45 2 RCL 2 403 42, 5,25 f DSE I
122 45 4 RCL 4 263 45,10, 1 RCL ÷ 1 404 22 7 GTO 7
123 43 32 g RTN 264 45 .0 RCL . 0 405 42, 5, 2 f DSE 2
124 42,21,12 f LBL B 265 16 CHS 406 22 6 GTO 6
125 44 .8 STO . 8 266 42 25 f I 407 42,21, 5 f LBL 5
126 45,10, 7 RCL ÷ 7 267 43 32 g RTN 408 45 0 RCL 0
127 45 3 RCL 3 268 42,21, .9 f LBL . 9 409 31 R/S
128 20 × 269 44 3 STO 3 410 u 44 12 USER STO B
129 44 .8 STO . 8 270 42 30 f Re↔Im 411 22 5 GTO 5
130 45 4 RCL 4 271 44 .3 STO . 3 412 45,16,12 RCL MATRIX B
131 14 272 33 R⬇ 413 45,16,11 RCL MATRIX A
132 45,20, .4 RCL × . 4 273 16 CHS 414 42,26,12 f RESULT B
133 45 5 RCL 5 274 44 2 STO 2 415 10 ÷
134 45,20, .8 RCL × . 8 275 42 30 f Re↔Im 416 u 45 12 USER RCL B
135 16 CHS 276 16 CHS 417 42,21, 8 f LBL 8
136 12 277 44 .2 STO . 2 418 31 R/S
137 45,20, .8 RCL × . 8 278 42 30 f Re↔Im 419 u 45 12 USER RCL B
138 45,20, 9 RCL × 9 279 11 √x̅ 420 22 8 GTO 8
139 40 + 280 34 x↔y
140 45,20, 8 RCL × 8 281 2 2