Sunday, October 27, 2019

HP 12C and HP 41C/DM41L: Rounding Numbers

HP 12C and HP 41C/DM41L:  Rounding Numbers

Introduction

The following program rounds positive numbers to the desired decimal amount of places.  For example,  √3 rounded to 3 places is 1.732.  e^2 rounded to 2 places is 7.39. 

Set up your stack like this:
Y:  number
X: number of decimal places

HP 12C Program: Rounding

Step;  Code;   Key
01;  1;  1
02;  0;  0
03;  34;  x<>y
04;  21;  y^x
05;  36;  ENTER
06;  33;  R↓
07;  20;  *
08;  36;  ENTER
09;  43,24;  FRAC
10;  40;  +
11;  43, 25;  ITNG
12;  33;  R↓
13;  33;  R↓
14;  33;  R↓
15;  10;  ÷
16;  43,33,00;  GTO 00

HP 41C Program:  Rounding

01  LBL^T ROUND
02  10↑X
03  STO T
04 *
05 ENTER↑
06 FRC
07 +
08 INT
09 R↑
10 /
11 RTN
12 END

Examples:

Round √3 rounded to 3 places

Y:  3, sqrt   (√3)
X:  3

Result:  1.732

Round e^2 rounded to 2 places. is 7.39. 

Y: 2,  e^x  (e^2)
X:  2

Result:  7.39

Eddie

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

Casio fx-CG 50: Impedance Calculations

Casio fx-CG 50:  Impedance Calculations



Introduction

The program FX61IMP contains a suite of impedance calculations.  Why the unusual name?

In the late 1980s, Casio had a fx-61F calculator.  The fx-61F is a specialized programming scientific calculator, which is the only calculator, to my knowledge, to feature an Impedance mode.  The impedance mode has specialized keys to calculate impedance of resistors, capacitors, and inductors (coils).  The calculator also featured 29 specialized electrical formulas, a 30 step programming capability, base conversions, 1 variable statistics, and complex numbers.

The main menu of FX61IMP:

1.  Impedance of a Coil (Inductor)
2.  Impedance of a Capacitor
3.  Impedance of two parallel resistors (Parallel)
4.  Impedance of a Series Resistor
5.  Analysis of total Impedance
6.  Store results in X and Y
7.  View Memory Registers
8.  Clear Variables
9.  Exit

Variables used:
Z = impedance of the current calculation
S = grand total impedance
X = user register
Y = user register

Note:  In electronics, the symbol j is used in complex numbers.  The fx-61F uses j.  However, the fx-CG50 uses i in complex numbers.  The program uses i and the user is notified of this when the program starts. 

1.  Impedance of a Coil (Inductor)
Provide the self-inductance (in H, Henrys) and frequency (in 1/s), the impedance is calculated as:
Z = 2 * π * f * L * i

The result is added to S.

2.  Impedance of a Capacitor
Provide the capacitance (in F, Farads) and frequency (in 1/s), the impedance is calculated as:
Z = 1/(2 * π * f * C * i)

The result is added to S.

3.  Impedance of two parallel resistors (Parallel)
This calculates the impedance of parallel resistors:
Z = 1/(1/a + 1/b) = (a * b) / (a + b)

The result is added to S.

4.  Impedance of a Series Resistor
The impedance of the resistor is:  R (in Ω, Ohms)

Z = R

The result is added to S.

5.  Analysis of total Impedance
Takes the total impedance (S) and returns its total, magnitude, and phase angle (in degrees).  You will have an opportunity to clear S (reset S to zero).

6.  Store results in X and Y
You can store Z or S in the variables X and Y.

7.  View Memory Registers
View the contents Z, S, X, and Y.

8.  Clear Variables
Resets Z, S, X, and Y to 0.

9.  Exit
Exits the program.

The program is listed in text form, which can be copied to the fx-CG 50.

Program Text Listing:
'ProgramMode:RUN
"2019-09-09 EWS"
Deg
a+bi
ClrText
Red Locate 1,3,"NOTICE"
Blue Locate 1,5,"J is represented"
Blue Locate 1,6,"by _Imaginary_. (_Sqrt__(-)_1)"
" "Disps0->S
0->Z
0->X
0->Y
Lbl 0
ClrText
Menu "IMPEDANCE","COIL",1,"CAPACITOR",2,"PARALLEL",3,"SERIES RESISTOR",4,"ANALYSIS",5,"STORE IN X OR Y",6,"VIEW MEMORY",7,"CLEAR VARS",8,"EXIT",E
Lbl 1
"FREQ: "?->F
"INDUCTANCE: "?->L
2piLFImaginary->ZDispsS+Z->S
Goto 0
Lbl 2
"FREQ: "?->F
"CAPACITY: "?->C
(2piFCImaginary)^<-1>->ZDispsS+Z->S
Goto 0
Lbl 3
"PARALLEL IMPEDANCE"
"A_#E6D7_B"
"A: "?->A
"B: "?->B
(AB)/(A+B)->ZDispsS+Z->S
Goto 0
Lbl 4
"RESISTANCE: "?->R
R->ZDispsS+Z->S
Goto 0
Lbl 5
"TOTAL IMPEDANCE:"
SDisps"MAGNITUDE: "
Abs SDisps"PHASE ANGLE: "
Arg SDispsMenu "CLEAR TOTAL?","YES",Y,"NO",0
Lbl Y
0->S
"CLEARED!"DispsGoto 0
Lbl 6
Menu "WHAT TO STORE?","Z_->_X",M,"Z_->_Y",N,"S_->_X",O,"S_->_Y",P
Lbl M
Z->X
"DONE!"DispsGoto 0
Lbl N
Z->Y
"DONE!"DispsGoto 0
Lbl O
S->X
"DONE!"DispsMenu "CLEAR TOTAL?","YES",Y,"NO",0
Lbl Y
0->S
"CLEARED!"DispsGoto 0
Lbl P
S->Y
"DONE!"DispsMenu "CLEAR TOTAL?","YES",Y,"NO",0
Lbl Y
0->S
"CLEARED!"DispsGoto 0
Lbl 7
ClrText
"Z: "
ZDisps"S: "
SDisps"X: "
XDisps"Y: "
YDispsGoto 0
Lbl 8
0->Z
0->S
0->X
0->Y
"DONE!"DispsGoto 0
Lbl E
ClrText
Red Locate 5,4,"FX61 IMPEDANCE"

Note:  Disps:  ◢, ⊿
Imaginary:  i  [SHIFT] [ 0 ]

Program Calculator Listing:
"2019-09-09 EWS"
Deg
a+bi
ClrText
Red Locate 1,3,"NOTICE"
Blue Locate 1,5,"J is represented"
Blue Locate 1,6,"by i. (√-1)"
" "⊿
0->S
0->Z
0->X
0->Y
Lbl 0
ClrText
Menu "IMPEDANCE","COIL",1,"CAPACITOR",2,"PARALLEL",3,"SERIES RESISTOR",4,"ANALYSIS",5,"STORE IN X OR Y",6,"VIEW MEMORY",7,"CLEAR VARS",8,"EXIT",E
Lbl 1
"FREQ: "?->F
"INDUCTANCE: "?->L
2πLFi->Z⊿
S+Z->S
Goto 0
Lbl 2
"FREQ: "?->F
"CAPACITY: "?->C
(2πFCi)⁻¹->Z⊿
S+Z->S
Goto 0
Lbl 3
"PARALLEL IMPEDANCE"
"A||B"
"A: "?->A
"B: "?->B
(AB)÷(A+B)->Z⊿
S+Z->S
Goto 0
Lbl 4
"RESISTANCE: "?->R
R->Z⊿
S+Z->S
Goto 0
Lbl 5
"TOTAL IMPEDANCE:"
S⊿
"MAGNITUDE: "
Abs S⊿
"PHASE ANGLE: "
Arg S⊿
Menu "CLEAR TOTAL?","YES",Y,"NO",0
Lbl Y
0->S
"CLEARED!"⊿
Goto 0
Lbl 6
Menu "WHAT TO STORE?","Z->X",M,"Z->Y",N,"S->X",O,"S->Y",P
Lbl M
Z->X
"DONE!"⊿
Goto 0
Lbl N
Z->Y
"DONE!"⊿
Goto 0
Lbl O
S->X
"DONE!"⊿
Menu "CLEAR TOTAL?","YES",Y,"NO",0
Lbl Y
0->S
"CLEARED!"⊿
Goto 0
Lbl P
S->Y
"DONE!"⊿
Menu "CLEAR TOTAL?","YES",Y,"NO",0
Lbl Y
0->S
"CLEARED!"⊿
Goto 0
Lbl 7
ClrText
"Z: "
Z⊿
"S: "
S⊿
"X: "
X⊿
"Y: "
Y⊿
Goto 0
Lbl 8
0->Z
0->S
0->X
0->Y
"DONE!"⊿
Goto 0
Lbl E
ClrText
Red Locate 5,4,"FX61 IMPEDANCE"

The || is found in (CHAR), (MATH).

Examples:

Example 1:
Two coils in a series with inductance of 0.1 H and 0.2 H, respectively.  The frequency is 50 Hz. 

Sequence:
Option 1:  Enter 50 for frequency, 0.1 for inductance.
Option 1:  Enter 50 for frequency, 0.2 for inductance.
Option 5:  For analysis.

Total Impedance:  94.24777961i
Magnitude:  94.24777961
Phase Angle:  90°
(Clear the total)

Example 2:
A capacitor of 30 μF, a resistor of 10 Ω, and coil of 0.3 H are in a series.  Find the total impedance of the circuit if the frequency is 65 Hz.

Sequence:
Option 2:  Enter 65 for frequency, 30E-6 for capacity
Option 4:  Enter 10 for resistance
Option 1:  Enter 65 for frequency, 0.3 for inductance
Option 5:  For analysis

Total Impedance:  10 + 40.90419396i
Magnitude: 42.10882429
Phase Angle:  76.26214952°
(Clear the total)

Example 3:
Three resistors in parallel with 100 Ω, 200 Ω, and 400 Ω, respectively.  Find the total impedance.

Sequence:
Option 3:  Enter 100 for A and 200 for B.
Option 6:  Store S in X.  Clear the total.
Option 3:  Enter X for A and 400 for B.
Option 5:  For analysis

Total Impedance: 57.14285714
Magnitude: 57.14285714
Phase Angle: 0°

Eddie

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

HP 12C: Finding Two Factors of an Integer

HP 12C:  Finding Two Factors of an Integer 



Introduction

This program finds two factors of the integer N, where one of the factors is close to, but not equal to √N as possible. 

Let X and Y be positive integers where:

(I)
N = B^2 - A^2

By the difference of squares:

(II)
N = (B - A) * (B + A)

The program tests every integer higher than √N.  Let B = int(√N) + 1.   If A = N - B^2 is an integer, the search stops.  The program uses the equation (II) above and places the results on the stack as such:

Y Stack:  B + A   // the program pauses to show this result
X Stack:  B - A

Program:
(Step ##: key code: key)
01:  44, 0:  STO 0
02:  43, 21: √
03:  43, 25:  INTG
04:  1:  1
05:  40:  +
06:  44, 1: STO 1
07:  2:   2
08:  21:  y^x
09:  45, 0:  RCL 0
10:  30:  -
11:  43, 21:  √
12:  44, 2:   STO 2
13:  43, 24:  FRAC
14:  43, 35:  X=0
15:  43, 33, 20:  GTO 20
16:  1:   1
17:  44, 40, 1:  STO+1
18:  45, 1:  RCL 1
19:  43, 33, 07:  GTO 07
20:  45, 1:  RCL 1
21:  45, 2:  RCL 2
22:  40:   +
23:  43, 31:  PSE
24:  45, 1:  RCL 1
25:  45, 2:  RCL 2
26:  30:  -
27:  43, 33, 00:  GTO 00

Examples:
n = 22356 = 162 * 138

n = 667 = 29 * 23

n = 4120 = 206 * 20

n = 144 = 18 * 8
(remember, factors close to √n as possible, but not the square root)

n = 97 = 97 * 1
(prime number)

Eddie

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

HP 12C: Total Sales Tax with Rounded Amounts

HP 12C:  Total Sales Tax with Rounded Amounts




Introduction

The following program calculates the total invoice with the total sales tax.   Each time sales tax is calculated, the amount is rounded to two decimal places.

For example:

What is the total invoice for the purchase of three taxable items, if the sales tax is 9.5%. 

$19.95
$32.85
$47.50

The calculation:

19.95 + round(19.95 * .095,2)
+ 32.85 + round(32.85 * .095,2)
+ 47.50 + round(47.50 * .095,2)


= 19.95 + 1.90
+ 32.85 + 3.12
+ 47.50 + 4.51

= 109.83

Rounding to 2 Decimal Places 

The FIX 2 mode rounds results to 2 decimal places, but for the purposes the display only.  The number retains it's full decimal expansion.

When you want to use the rounded amount, we can use the following routine:

In fixed 2 mode:  [ f ] 2

...
1
EEX
2
*
ENTER   // makes a duplicate of the number
FRAC   // takes the fraction
.
5
x<>y   
x≤y   // is the fraction part less than 0.5
GTO  (A)   // go to line where (A) is

R↓  // fraction part is more than 0.5
+
GTO (B)

R↓   // (A)
R↓

ITNG  // (B), finalize the rounded number
1
EE
2
÷    // rounded number in the stack
...

Example:  425/118 = 3.60 in the display, shows 3601694915 when pressing [ f ] (PREFIX)

After this routine, we have 3.60, shows 3600000000 when pressing [ f ] (PREFIX)

Instructions:
1.  Enter the tax rate.
2.  Press [ f ] (PRGM), [R/S]
3.  Enter the item's cost, press [R/S]
4.  For subsequent items, enter the cost, then [R/S]
5.  When finished, press [RCL], 1 to recall total rounded sales tax.  Press [RCL], 2 to recall the total invoice.

I have program set to pause to show the rounded sales tax when each cost is entered. 

Program:
(Step ##: key code, key)
01:  44,0  STO 0
02:  42, 2  FIX 2
03:  35,  CLx
04:  44, 1 STO 1
05:  44, 2 STO 2
06:  31  R/S
07:  45, 0  RCL 0
08:  25   %
09:  1     1
10:  26   EE
11:  2     2
12:  20   *
13:  36   ENTER
14:  43, 24  FRAC
15:  48    .  (decimal point)
16:  5      5
17:  34   x<>y
18:  43, 34  x≤y
19:  43, 33, 23  GTO 23
20:  33   R↓
21:  40   +
22:  43, 33, 25   GTO 25
23:  33  R↓
24:  33  R↓
25:  43, 25  ITNG
26:  1    1
27:  26  EEX
28:  2     2
29:  10   ÷
30:  43, 31   PSE
31:  44, 40, 1   STO+ 1
32:  40   +
33:  44, 40, 2   STO+ 2
34:  31   R/S
35:  43, 33, 07  GTO 07

Example:
Sales Tax Rate:  9.5%
Item Costs:  $14.35, $18.99, $39.99, $23.64

Keystrokes:
9.5  [ f ] (PRGM) [R/S]
14.35 [R/S]
18.99 [R/S]
39.99 [R/S]
23.64 [R/S]

R1:  Total rounded sales tax:  9.21
R2:  Total invoice:  106.18

Eddie

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

Casio fx-991EX Classwiz: Simple Programming With Mutli-Statements

Casio fx-991EX Classwiz:  Simple Programming With Mutli-Statements 

Formula Programming

With the use of the [CALC] key and multi-statment feature on the Casio fx-991EX, we can make simple temporary formula programs for repeated calculations.   Emphasis is on the word temporary:  once we go on to another mode, or press [ ON ],  the formula disappears.

There are also no comparison operators or loops to work with. 

Given these limitations, we can still program simple formulas with the fx-991EX. 

You are going to want to be in Norm mode for this.

Note:  This feature is present on other advanced solar calculators, however we will focus on the fx-991 EX Classwiz.

Let's illustrate formula programming with some examples. 

Formula 1

Let's start with a simple example. 

B(A) = 2A² + 1
C(B) = B/(B - 1)

To assign variables in multi-step calculations, use the syntax:

var = value. 

The equals symbol can be found by pressing pressing [ALPHA] [CALC] ( = ).  This is NOT the same as the equals key on the bottom right hand corner of the keyboard. 

Each calculation is separated by a colon (:).  Type a colon by pressing [ALPHA] [ ∫ ] ( : ). 

Set up:

B=2A²+1:C=B÷(B-1)

Each variable that is not assigned will be prompted for in the order that they are typed.  In the expression above, B and C are assigned while A is not.   Pressing [CALC] will prompt the user to enter a value for A. 

Keystrokes:

[ALPHA] ( B ) [ALPHA] ( = ) 2 [ALPHA] ( A ) [ x² ] [ + ] 1 [ALPHA] ( : ) [ALPHA] ( C )  [ALPHA]  ( = )  [ALPHA] ( B ) [ ÷ [ [ ( ] [ [ALPHA] ( B ) [  -  ] 1 [ ) ] [ CALC ]

Note:  For this to work, press [ CALC ], not the EXE key. 

You will be prompted for A.  The results for B and C will be displayed. 

Examples

Example 1:  A = 3
[CALC],  enter 3, press [ = ]
B:  19,  press [ = ]
C:  19/18  [ S ←→ D ] 1.0555555556

Example 2:  A = -6
Results:  B = 73,  C = 73/12 ≈ 1.013888889

R-C Circuit:  Voltage Charge and Discharge

The charge and discharge of an R-C time circuit are described by the following equations:

Charge = Y / ( 1 - B)
Discharge = Y / B

where B = e^(-A / (C*X))

Inputs:
A = time (s)
X = resistance (kΩ)
C = capacitance (μF)
Y = voltage across the capacitor (V)

In this example, B is going to be used as the temporary variable. 

Set up:

B=e^(-A÷(Cx)):Y÷(1-B):Y÷B

[CALC]

Example

Inputs:
A = 5 s
C = 2.6 μF
x = 10 kΩ
y = 30 V

Results:
B = 0.825052967 (sub-formula, press [ = ] )
171.4804732 V  (voltage charge, press [ = ] )
36.36130188 V (voltage discharge)

Solar Energy:  % of Solar Light Reflected

The proportion of solar light reflected off the surface is calculated by:

T = 1/2 ( sin(E - F)^2 / sin(E + F)^2 + tan(E - F)^2 / tan(E + F)^2 )

where

E = the angle of incidence (θi)
F = the angle of refraction (θt)

We can use Snell's law in connection with the equation above. 

Since both  E-F and E+F repeat, we can assign temporary variables, such as:
A = E - F
B = E + F

Therefore:
T = 1/2 ( sin(A)^2 / sin(B)^2 + tan(A)^2 / tan(B)^2 )

And the set up for the fx-991EX Classwiz is:

A=E-F:B=E+F:1÷2*(sin(A)²÷sin(B)²+tan(A)²÷tan(B)²)   [CALC]

Example:

For this example, the calculator is Degrees mode. 
Inputs:
E = 35° (θi)
F = 22° (θt)

Results:
A = E-F = 13
B = E+F = 57
0.04721102683  (% of reflected light)

Source (for R-C Circuit and Solar Energy)

Rosenstein, Morton  Computing with the Scientific Calculator  Casio.  1986. ISBN: 978-1124164130


Eddie

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

HP Prime: Law of Refraction

HP Prime: Law of Refraction 

Introduction

The program DRAWREFRACT, visually demonstrates the Law of Refraction, or Snell's Law:

n1 sin θi = n2 sin θt

The program asks for n1, θi, and n2; and calculates θt.  The program draws the incident ray (in red) and the refracted ray (in blue).  The calculator is set to Degrees mode and the Function app. 

Note: you can find the angle character ∡, by pressing [SHIFT] [ × ]. 

HP Prime: Law of Refraction: DRAWREFRACT

Program:
EXPORT DRAWREFRACT(n1,θ1,n2)
BEGIN
// EWS 2018-08-20
// drawing Descates law
HAngle:=1; // Degrees
LOCAL θ2,x1,y1,x2,y2;
LOCAL str1,str2;
// window setup
STARTAPP("Function");
STARTVIEW(11,0);  // Decimal zoom
// calculation
θ2:=ASIN(n1*SIN(θ1)/n2);
x1:=RE(16∡(θ1+90));
y1:=IM(16∡(θ1+90));
x2:=RE(16∡(270+θ2));
y2:=IM(16∡(270+θ2));
// plot
RECT();
// draw axis
LINE(0,−16,0,16,0);
LINE(16,0,−16,0,0);
// draw analysis
LINE(0,0,x1,y1,#FF0000h);
LINE(0,0,x2,y2,#0000FFh);
str1:="n = "+STRING(n1)+
", θi = "+STRING(θ1);
str2:="-> n = "+STRING(n2)+
", θt = "+STRING(θ2);
TEXTOUT(str1,−15,−5,4,#FF0000h);
TEXTOUT(str2,−15,−8,4,#0000FFh);
WAIT(0);
// display home
STARTVIEW(−1);
END;

Example

n1 = 1.001
θ = 34.5°
n2= 1.205

DRAWREFRACT(1.001, 34.5, 1.205)

Result:
θt = 28.0678429359°



Eddie

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

Thursday, October 10, 2019

HP 41C/DM 41: Halloween and Thanksgiving - Calendar Calculations

HP 41C/DM 41:  Halloween and Thanksgiving - Calendar Calculations

Introduction 



We are about to enter the annual holiday season, and it's can be hard to remember when all the holidays.  Here is a way to determine what date Thanksgiving will be on this year, and all you have to know is what day of the week Halloween falls on.

Halloween is celebrated on October 31.  Halloween is celebrated on a fixed date, while Thanksgiving is celebrated on a fixed day of the week.

In the United States, Thanksgiving is on the fourth Thursday in November.  Therefore the only dates Thanksgiving in the United States is between November 22 and November 28.

In Canada, Thanksgiving is on the second Monday in October, which lands the possible dates between October 8 and October 14. 

Determine The Date of Thanksgiving Knowing What Day of the Week Halloween Is On

The first step is to give each day a numeric value:

Sunday: 0
Monday:  1
Tuesday:  2
Wednesday:  3
Thursday:  4
Friday:  5
Saturday:  6

To determine what date Thanksgiving falls on in the United States:

1.  Let H be the numeric value for the day Halloween falls on (see the above chart). 
2.  Subtract 4 from H.
3.  If the result is zero or negative, add 28; otherwise, add 21. 

Note:  The following programs could address alternative approaches given what the command set of the HP 41C/DM 41 allows us to do. 

HP 41C/DM 41 Program:  H>T

01 LBL^T  H>T
02 4
03 X<>Y
04 -
05 X>0?
06 GTO 01
07 7
08 +
09 LBL 01
10 21
11 + 
12 RTN

To determine what date Thanksgiving falls on in Canada:

1.  Let H be the numeric value for the day Halloween falls on (see the above chart). 
2.  Subtract H from 7. 
3.  Subtract 3 from the last result.
4.  If the result from Step 3 is zero or negative, add 14; otherwise, add 7.

HP 41C/DM 41 Program: H>CT

01 LBL^T H>CT
02 7
03 X<>Y
04 -
05 3
06 -
07 X>0?
08 GTO 01
09 7
10 +
11 LBL 01
12 7
13 + 
14 RTN

Now, let's go the other way.

Determine The Day of the Week Halloween Knowing the Date of Thanksgiving

The first step is to give each day a numeric value:

Sunday: 0
Monday:  1
Tuesday:  2
Wednesday:  3
Thursday:  4
Friday:  5
Saturday:  6

To determine the day of the week Halloween falls on given the date of Thanksgiving (United States):

1.  Let T be the date of Thanksgiving.
2.  Subtract 21 from T. 
3.  Subtract the result from Step 2 from 4.  If the number is negative, add 7.  See the above chart to determine the Day of the Week.

HP 41C/DM41 Program:  T>H

01  LBL^T T>H
02 21
03 - 
04 4
05 X<>Y
06 -
07 X<0 font="">
08 GTO 01
09 RTN
10 LBL 01
11 7
12 + 
13 RTN

To determine the day of the week Halloween falls on given the date of Thanksgiving (Canada):

1.  Let T be the date of Thanksgiving.
2.  Subtract T from 11.  If the result is negative, add 7.  See the above chart to determine the Day of the Week.

HP 41C/DM41 Program:  CT>H

01 LBL^T CT>H
02 11
03 X<>Y
04 -
05 X<0 font="">
06 GTO 01
07 RTN
08 LBL 01
09 7
10 +
11 RTN

Are you ready for the holiday season?  I'm not sure I am.  Let's have fun,

Eddie

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

Fun with the TI-81: Part II

Fun with the TI-81:  Part II

Please check out yesterday's blog entry for Part I.  Now let's continue.

TI-81 Decimal to Fraction:  DECTOFRAC
(148 bytes)

This program converts a number X to fraction as an approximation.  Each successful approximation is displayed until the absolute value of the error falls below 10^-12.  This program is based on a program written for the Radio Shack TRS-80 (see source). 

Variables:
X = Number
H = numerator
I = denominator
Y = error
Used: A, B, C, D, E, F, G, J

Program:
Disp "X="
Input X
IPart X → A
1 → B
X - A → C
0 → D
1 → E
1 → F
0 → G
Lbl 2
A * F + D → H
A * G + E → I
H / I - X → Y
ClrHome
Disp H
Disp "/"
Disp I 
Disp "ERR="
Disp Y
Pause
If abs Y<1e-12 font="">
Stop
C → J
B - A * C → C
J → B
F → D
H → F
G → E 
I → G
Goto 2

Example:
X = 4.7995
4 / 1,  ERR = -.7995
5 / 1,  ERR = .2005
13 / 4, ERR = -.0495
24 / 5,  ERR = 5E-4
1915 / 399, ERR = -1.253133E-6
9599 / 2000, ERR = 0

4.7995 = 9599/2000

Source:

Craig, John Clark  119 Practical Programs for the TRS-80 Pocket Computer  Tabs Books Inc.:  Blue Ridge, PA.  1982 ISBN 0-8306-0061-1 (Paperback)

TI-81 Simple Logistic Regression:  LOGISFIT 
(71 bytes)

The program LOGISFIT fits the statistical data to the equation:

y = 1 / (a + b*e^x)

This program uses the linear regression fit with the following translations:

x' = e^(-x), y' = 1/y

This fit will is good for all data except when y = 0.

Instructions: 
1.  Enter the data through the Stat Edit menu. 
2.  Run LOGISFIT.  The data will be altered. 

Program:
1 → I
Lbl 1
e^( -{x}(I) ) → {x}(I)
{y}(I)⁻¹ → {y}(I)
IS>( I, Dim{x} )
Goto 1
LinReg
Disp "Y=1/(a+be^(X))"
Disp "a"
Disp a
Disp "b"
Disp b

Example:
x1 = 0.5
y1 = 0.384
x2 = 1
y2 = 0.422
x3 = 1.5
y3 = 0.45
x4 = 2
y4 = .468
x5 = 2.5
y5 = .48

Results:
a = 2.001859259
b = .9942654005

Equation:
y = 1 / (2.001859259 + .9942654005*e^x)

Source:

Shore, Edward.  "HP Prime and TI-84 Plus CE: Simple Logistic Regression"  Eddie's Math and Calculator Blog. 2017.  http://edspi31415.blogspot.com/2017/04/hp-prime-and-ti-84-plus-ce-simple.html
Retrieved August 17, 2019

TI -81 Confidence Intervals: INTERVAL
(184 bytes)

The program INTERVAL calculates a confidence interval given the sample's mean (M), variance (V), and number of data points (N).  A Z scored is selected when the user selects one of three confidence levels: 

99%  (0.5% on each side of the curve, Z = 2.575829586)
95%  (2.5% on each side of the curve, Z = 1.959963986)
90%.  (5% on each side of the curve, Z = 1.644853627)

The interval lies between ( M - Z * V/√N,  M + Z * V/√N )

Notes:
1.  Z is used as an control variable and the Z score.
2.  The percent symbol is built of three characters, the degree symbol (°), the forward slash by pressing the [ ÷ ] key (/), the decimal point (.).

Program:
0 → Z
Disp "MEAN="
Input M
Disp "VAR="
Input V
Disp "N="
Input N
Lbl 0
ClrHome
Disp "1. 99°/."
Disp "2. 95°/."
Disp "3. 90°/."
Input P
If P=1
2.575829586 → Z
If P=2
1.959963986 → Z
If P=3
1.644853627 → Z
If Z=0
Goto 0
M + Z * V / √N → U
M - Z * V / √N → V
Disp "INTERVAL"
Disp U
Disp V

Example:
Input:  n = 100, M = 156.39, V = 10.94, 99% confidence interval
Results: 
162.2079576
156.5720424

Source:
Kelly, Kathy A., Robert E. Whitsitt II, M. Deal LaMont, Dr. Ralph A. Olivia, et all.  Scientific Calculator Sourcebook   Texas Instruments Inc.  1981.  (no ISBN number is given)

TI-81 Fresnel Polarization:  MICROPOL
(120 bytes)

Given a microwave transferring from one medium to another with the initial angle with respect to the plane surface that separates the mediums, the following are calculated:

1.  Angle of refraction, θt
2.  Fresnel Horizontal Polarization, R_H
3.  Fresnel Vertical Polarization, R_V

The Law of Refraction:
n1 sin θi = n2 sin θt

Fresnel Horizontal Polarization:
R_H = sin(θ_i - θ_t) / sin(θ_i + θ_t)

Fresnel Vertical Polarization:
R_V = tan(θ_i - θ_t) / tan(θ_i + θ_t)

Variables:
N = n_1  (index of refraction of medium 1)
M = n_2  (index of refraction of medium 2)
θ = θ_i  (angle of incidence)
Z = θ_t (angle of refraction)
H = R_H (Fresnel horizontal polarization)
V = R_V (Fresnel vertical polarization)

Note:  Angles are in degrees

Program:
Deg
Disp "N1="
Input N
Disp "θ="
Input θ
Disp "N2="
Input M
sin⁻¹ (Nsin θ / M) → Z
sin(θ-Z) / sin(θ+Z) → H 
tan (θ-Z) / tan (θ+Z) → V
Disp "REFRACT θ=" 
Disp Z
Disp "H-POLAR="
Disp H
Disp "V-POLAR="
Disp V

Example:
Inputs:  N1 = 1.001, θ = 40°, N2 = 1.333
Results:
REFRACT θ = 28.86146514°
H-POLAR = .2071186671
V-POLAR = .0761259908

Source:
Barue, Geraud  Microwave Engineering:  Land & Space Communications  John Wiley & Sons: Hoboken, NJ 2008.  ISBN 978-0-470-08996-5

TI-81 Hyperbolic Circles: Circumference and Area:  HYPCIRCL
(61 bytes)

The program HYPCIRCL calculates the circumference and area of a circle in hyperbolic space.  Note that this not the same as (normal, regular, everyday) circles in Euclidean space. 

Circumference of a hyperbolic circle: C = 2 π sinh(R)

Area of a hyperbolic circle:  A = 4 π sinh(R/2)^2

Program:
Disp "HYP CIRCLE"
Disp "R="
Input R
2π sinh R → C
4 π (sinh(R/2))² → A
Disp "C="
Disp C
Disp "A="
Disp A

Example:
Input: R = 3
Results: 
C = 62.94416455
A = 56.97380062

Source:
Series, Caroline  "Hyperbolic Geometry MA 448"  2010. Edited Jan. 4, 2013

Eddie

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

Fun with the TI-81: Part I

Fun with the TI-81:  Part I

Before there there was the TI-82, TI-83 and its family, and the TI-84 Plus and its family, there was the Texas Instrument's original calculator from the 1990, the TI-81!

Translating TI-81 to TI-84 Plus (and Back) 

Most of the commands can be copied directly.  Some caveats to keep in mind:

Disp

The TI-81's Disp (Display command) can only display either a variable's value or a string.  The command can only display one item per line.

The TI-84 Plus' Disp command can list any combination of strings and variable values, separated by a comma.  Each argument will be placed on one line.

Input

The TI-81's Input command can ask for one variable.  There is no prompt string option.  A prompt string will require an extra Disp command.  Also, there is no colon character.

Disp "VAR="
Input A

The TI-84 Plus' Input command can have an optional prompt string.

Input "VAR=", A

Lists 

The TI-81 has two lists that are used for statistical calculations, {x} and {y}.  To recall an element of either {x} or {y}, press [ 2nd ] [ 0 ] or [ 2nd ] [ 1 ], respectively.  The dimensions of the stat lists can be found by pressing [VARS], and selecting Dim{x} under the DIM menu.  Stat lists can't be resized by storing a value to it.

All of the lists for the TI-84 Plus start with a lower case bold "L".  Lists 1-6 can be pressed by [ 2nd ] [ 1 ] through [ 6 ].  There are many lists commands and functions for the TI-84 Plus.

Linear Regression Options

Running linear regression is the LinReg command on the TI-81.  The equation will always be a + bx.

Running linear regression for the TI-84 Plus will need you to designate the x-list and y-list.  There are also various options: a + bx, ax + b, or Med-Med

The If Command and Loops

The TI-81 only has a singular If command, no Then or Else.  The syntax is:

If condition
do if condition is true
skip to here if condition is false

Loops will require the extensive use of Lbl (label), Goto, DS<(, and IS>(.   Lbl and Goto are self-explanatory. 

DS<(var, target).   The value of var is decreased by 1.  The next command is skipped when value < target.

IS>(var, target).  The value of var is increased by 1.  The next command is skipped when value > target. 

In addition to If (which can still do the two-line structure), Lbl, Goto, DS<(, and IS>(, the TI-84 Plus has Then, Else, For, While, and Repeat.

The STO> Button

The TI-81 turns on the ALPHA keyboard when pressing [STO>].

The TI-84 Plus doesn't.

On to the programming...

TI-81 Decimal to Binary Conversion:  BINTODEC
(75 bytes)

Input the binary integer at the prompt.  Use only 1s and 0s. 

Variables:
B = binary representation
D = decimal representation
N, M:  used

Program:
Disp "BIN>DEC"
Input B
0 → D
0 → N
B → M
Lbl 0
2^N * 10 * FPart(M/10) + D → D
IPart(M/10) → M
IS>(N, IPart(log B) + 1)
Goto 0
Disp D

Example:
Input:  B:  1001010
Result:  D:  74

TI-81 Binary to Decimal Conversion:  DECTOBIN
(99 bytes)

Input the decimal integer at the prompt.  The integer needs to be in between 1 and 1024.  Only positive integers are allowed.

Variables:
B = binary representation
D = decimal representation
N, M:  used

Program:
Disp "DEC>BIN"
Disp "1≤D≤1024"
Input D
0 → B
D → M
IPart( log D / log 2 ) → N
Lbl 2
If 2^N ≤ M
B + 1 → B
If 2^N ≤ M
M - 2^N → M
If N ≠ 0 
10 * B → B
DS<(N, 0)
Goto 2
Disp B

Example:
Input:  D:  516
Result:  B:  1000000100

TI-81 Roots of a Quadratic Equation:  QUADEQN
(121 bytes)

This program solves the equation A*X^2 + B*X + C = 0, which allows for real or complex roots.

Variables:
A, B, C:  coefficients
X, Y:  roots

If the discriminant is zero or positive, the roots are real, and are stored in X and Y.

If the discriminant is negative, we have complex roots in the form of X ± Yi, X is the real part, Y is the imaginary part.

Program:
Disp "AX²+BX+C=0"
Input A
Input B
Input C
-B / (2A) → X
(B² - 4AC) / (4A²) → Y
If Y<0 font="">
Goto 0
√Y → Y
X + Y → Y
2X - Y → X
Disp "ROOTS"
Goto 2
Lbl 0
√(abs Y) → Y
Disp "X+YI, X-YI"
Lbl 2
Disp X
Disp Y

Examples:

x^2 + 4x + 5 = 0,  Roots:  2 ± i
Input:  A: 1, B: 4, C: 5
Results:  "X+YI, X-YI", X: -2, Y: 1

x^2 + 5x + 4 = 0,  Roots:  -4, -1
Input:  A: 1, B: 5, C: 1
Results: "ROOTS", X: -4, Y: -1

Tomorrow will be Part 2. Until then,

Eddie

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

Thursday, October 3, 2019

HP 42S/DM42: Error Function, Bernoulli Numbers, Chebyshev Polynomials

HP 42S/DM42:  Error Function, Bernoulli Numbers, Chebyshev Polynomials

Error Function

The program ERF calculates the error function:

erf(x) = 2 / √π * ∫ e^-(t^2) dt from t = 0 to t = x

The calculation uses the series:

erf(x) = 2 * e^(-(x^2)) / √π * Σ( 2^n * x^(2n+1) / (1 * 3 * ... * (2n+1)) from n=0 to ∞

The error function can be used to calculate the cumulative normal distributive function from 0 to x by:

ncdf(x) = 1/2 + 1/2 * erf(x/√2)

HP 42S/DM42 Program: Error Function:  ERF

00 { 46-Byte Prgm }
01▸LBL "ERF"
02 STO 01
03 ENTER
04 ×
05 2
06 ×
07 STO 02
08 1
09 STO 03
10 RCL 01
11▸LBL 01
12 RCL 02
13 RCL 03
14 2
15 +
16 STO 03
17 ÷
18 RCL 01
19 ×
20 STO 01
21 +
22 X≠Y?
23 GTO 01
24 2
25 ×
26 PI
27 SQRT
28 RCL 02
29 2
30 ÷
31 E↑X
32 ×
33 ÷
34 RTN
35 END

Examples

erf(1.34) ≈ 0.9419
erf(2.43) ≈ 0.9994

Source:

Hewlett Packard  HP-65 Math Pac 2.   1974.

Bernoulli Numbers (Approximation)

The program BERN calculates Bernoulli numbers for positive integers n > 2.   The calculator is set to Radian mode.

The formula used:

B_n = (-cos(n * π/2))^((n+2)/2) * 2 * n! * Σ(2 * j * π)^(-n) from j=1 to ∞

HP 42S/DM42 Program: Bernoulli Numbers:  BERN

00 { 70-Byte Prgm }
01▸LBL "BERN"
02 RAD
03 STO 00
04 CLX
05 STO 02
06 1
07 +
08 STO 01
09▸LBL 00
10 2
11 PI
12 ×
13 RCL× 01
14 RCL 00
15 +/-
16 Y↑X
17 STO+ 02
18 1
19 STO+ 01
20 R↓
21 ABS
22 1ᴇ-10
23 X < Y ? 
24 GTO 00
25 RCL 02
26 RCL 00
27 N!
28 ×
29 2
30 ×
31 RCL 00
32 PI
33 ×
34 2
35 ÷
36 COS
37 +/-
38 2
39 RCL+ 00
40 2
41 ÷
42 Y↑X
43 ×
44 RTN
45 END


Examples

B_2 ≈ 0.1667
B_3 returns 1.1184E-85  (0)
B_4 returns -0.0333
B_6 returns 0.0238

Source:

Keith Oldhma, Jan Myland, and Jerome Spanier An Atlas of Functions 2nd Ed.  Springer: New York.  ISBN: 978-0-387-48806-6

Chebyshev Polynomials

The program CHEBY calculates the value of a first-order Chebyshev polynomial using the recurring formula where:

T_n(x) = 2 * x * T_n(x) - T_(n-1)(x)

where T_0(x) = 1,  T_1(x) = x

HP 42S/DM42 Program:  Chebyshev Polynomials: CHEBY

00 { 51-Byte Prgm }
01▸LBL "CHEBY"
02 STO 02
03 2
04 ×
05 STO 03
06 R↓
07 STO 00
08 X=0?
09 GTO 00
10 1
11 STO 01
12 STO- 00
13 X=Y?
14 GTO 01
15▸LBL 02
16 RCL 03
17 RCL× 02
18 RCL- 01
19 RCL 02
20 STO 01
21 R↓
22 STO 02
23 DSE 00
24 GTO 02
25 RTN
26▸LBL 00
27 1
28 RTN
29▸LBL 01
30 RCL 02
31 RTN
32 .END.


Instructions

Input n,  [ENTER], input x, XEQ CHEBY

Examples
T_3(0.4):  3, ENTER, 0.4, XEQ CHEBY
Result:  -0.9440

T_4(1.5):  4, ENTER, 1.5, XEQ CHEBY
Result:  23.5000

Source

Hewlett Packard  HP-65 Math Pac 2.   1974.



Happy programming,

Eddie

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


Spotlight: Akron Brass FireCalc Pocket Computer

Spotlight: Akron Brass FireCalc Pocket Computer Welcome to a special Monday Edition of Eddie’s Math and Calculator blog. Thi...