Showing posts with label modulus. Show all posts
Showing posts with label modulus. Show all posts

Saturday, September 6, 2025

HP 71B Programs: September 2025

HP 71B Programs: September 2025


One of my favorite calculators/pocket calculators of all time is the HP 71B.



ADDMOD: (a + b) mod n = a mod n + b mod n


10 DESTROY A, B, N

20 DISP “(A+B) MOD N” @ WAIT .5

30 INPUT “A? “; A

40 INPUT “B? “; B

50 INPUT “C? “; C

60 S = MOD(A, N) + MOD(B, N)

70 S = MOD(S, N)

80 DISP “SUM = “; S


MULTMOD: (a * b) mod n = a mod n * b mod n


10 DESTROY A, B, N

20 DISP “(A*B) MOD N” @ WAIT .5

30 INPUT “A? “; A

40 INPUT “B? “; B

50 INPUT “N? “; N

60 P = MOD(A, N) * MOD(B, N)

70 P = MOD(P, N)

80 DISP “PRODUCT = “; P


Examples:

A

630

48

15

B

320

99

47

N

700

15

7

SUM:

250

12

6

PRODUCT:

0

12

5



GABLE: Area of a Gable Roof


10 DESTROY P, S, L

20 DEGREES

30 INPUT “PITCH (IN.)? “; P

40 INPUT “SPAN (FT.)? “; S

50 INPUT “LENGTH (FT.)? “; L

60 A = 2 * S * L / COS(ATAN(P/12))

70 DISP “AREA = “; A; “ FT^2”


Input: Pitch (P)

6”

3”

4”

Input: Span (S)

110” (110/12 ft)

5’ 8” (5 + 8/12 ft)

15 ft

Input: Length (L)

100” (100/12 ft)

10’

10 ft

Output: Area (A)

170.81074828 ft^2

116.821326059 ft^2

316.227766017 ft^2



INTENSE: Light Intensity of a Spherical or a Cylindrical Light Source


intensity = power / surface area

intensity (W/m^2), power (W), surface area (m^2)

Surface area: sphere = 4 * π * r^2, cylinder = 2 * π * (r * h + r^2)


10 DESTROY P, K$, R, H

20 DISP “INTENSITY OF LIGHT!” @ WAIT .5

30 INPUT “POWER (W)? “; P


40 DISP “1. SPHERE 2. CYLINDER”

50 DELAY 0,0

60 K$ = KEY$

70 IF K$ = “1” OR K$ = “S” THEN GOTO 100

80 IF K$ = “2” OR K$ = “C” THEN GOTO 200

90 GOTO 40


100 INPUT “RADIUS (M)? “; R

110 A = 4 * PI * R^2

120 GOTO 300


200 INPUT “RADIUS (M)? “; R

210 INPUT “HEIGHT (M)? “; H

220 A = 2 * PI * (R * H + R^2)

230 GOTO 300


300 I = P / A

310 DISP I; “W/M^2”


Examples:


Sphere: r = 4 m, Power = 60 W: Intensity = .298415518297 W/M^2


Cylinder: r = 1.25 m, h = 0.75 m, Power = 70 W; Intensity = 4.45633840656 W/M^2



SIMPLE: Simple Interest – Banker’s Rule


interest = amount * rate% / 100 * #days / 360

final = principal + interest (final, maturity value)


10 DESTROY P, R, I, M

20 DISP “SIMPLE INTEREST” @ WAIT .5

30 INPUT “AMT? “; P

40 INPUT “RATE%? “; R

50 INPUT “# DAYS? “; D

60 I = P * R * D / 360 / 100

70 M = P + I

80 IMAGE K, M10D.2D

90 DISP USING 80; “INT.=”, I @ PAUSE

100 DISP USING 80; “FINAL=”, M


Notes:


* When the HP 71B is in pause, press [ f ] [ + ] to continue (CONT).

* To stop execution, press [ ON ] (ATTN).

* IMAGE K, M10D.2D: display “prompt string”, number rounded to 2 decimal places. The number is right-justified, make the prompt string 7 characters or less to fit both the string and number on the screen.


Examples


Input: Amount

1500

2000

2800

Input: Rate %

4.00%

8.00%

6.65%

Input: # Days

180

90

60

Output: Interest

30

40

31.03

Output: Final

1530

2040

2831.03



AIRSOUND: Speed of Sound in Air


S = 331.5 + .606 * T

S = speed of sound in air, m/s

T = temperature in °C


10 DESTROY K$, S, T

20 DISP “SPEED OF SOUND IN AIR” @ WAIT .5

30 DISP “SOLVE FOR…” @ WAIT .5

40 DISP “1. SPEED 2. TEMP”

60 K$ = KEY$

70 IF K$=”1” OR K$=”S” THEN GOTO 100

80 IF K$=”2” OR K$=”T” THEN GOTO 200

90 GOTO 40


100 INPUT “TEMP (°C)? “; T

110 S = 331.5 + .606 * T

120 DISP “S=”; S; “ M/S”

130 END


200 INPUT “SPEED (M/S)? “; S

210 T = (S- 331.5) / .606

220 DISP “T=”; T ; “°C”

230 END



Examples:


Input: T = 74 °F = (32 + 1/3) °C

Output: S = 345.64 m/s

Input: S = 350 m/s

Output: T = 30.5280528053 °C

Input: T = -8.5 °C

Output: S = 326.349 m/s

Input: S = 382 m/s

Output: T = 83.3333333333 °C



Eddie


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

Sunday, February 14, 2021

HP Prime and Numworks: Luhn Algorithm

 HP Prime and Numworks: Luhn Algorithm


The Luhn Algorithm:   Is Your Credit Card Number Valid?


The Luhn algorithm, created by IBM scientist Hans Peter Luhn in 1954, also known as the modulus 10 algorithm, is a checksum algorithm used to check the validity certain numbers used in financial transactions, such as identification numbers and credit card numbers. The algorithm is in public domain and serves as a basic check.  


The general steps of the Luhn Algorithm:


1.  Starting at the rightmost digit, double every other digit (2nd digit from the rightmost digit, 4th digit from right, 6th digit from right, and so on)


2.  If the digit that is doubled is at least 10, add the digits together.  


Replace 10 with 1.

Replace 12 with 3.

Replace 14 with 5.

Replace 16 with 7.

Replace 18 with 9.


3.  Take the sum of all the digits.


4.  If the sum is a multiple of 10 (sum modulo 10 is equal to zero), the number is considered valid.


Example:  4366357


For illustration purposes, let's separate each of the digits:


4  3  6  6  3  5  7


There are 7 digits.  


2nd digit from the most right:  5.  Double it to 10.  1 + 0 = 1


4  3  6  6  3  1  7


4th digit from the most right:  6.  Double it to 12.  1 + 2 = 3


4  3  6  3  3  1  7


6th digit from the most right:  3.  Double it to 6.  


6  6  3  3  1  7


Now add the digits:  4 + 6 + 6 + 3 + 3 + 1 + 7 = 30


10 divides into 30 evenly, or 30 mod 10 = 0.   The integer 4366357 is valid according to the Luhn algorithm.  


HP Prime Program:  LUNH


EXPORT LUHN()

BEGIN

// Luhn Algorithm - HP Prime

// strings are used to accommodate

// string: type 2

LOCAL s,l,k,c,t,n;


INPUT({{s,[[2]]}},

"Luhn Algorithm",

{"N?"},{"Integer"});

l:=DIM(s);

k:=l;


// total

t:=0;


// loop

WHILE k>0 DO

n:=EXPR(MID(s,k,1));

IF FP((l-k)/2)==0.5 THEN

IF n≠0 THEN

n:=(2*n-1) MOD 9+1;

END;

END;

t:=t+n;

k:=k-1;

END;


// final results

IF t MOD 10==0 THEN

RETURN "VALID";

ELSE

RETURN "NOT VALID";

END;


END;


Numworks Python Script:  luhn.py


from math import *

# Luhn Algorithm

# 2021-01-10 EWS

# Numworks Python


# strings are used

s=str(input('Integer? '))

l=len(s)

k=l


# total

t=0


# loop

while k>0:

  n=float(s[k-1])

  f=(l-k)/2

  if f-int(f)==0.5:

    if n!=0:

      n=fmod(2*n-1,9)+1

  t=t+n

  k=k-1


# final results

if fmod(t,10)==0:

  print("VALID")

else:

  print("NOT VALID")



Examples


38348 returns NOT VALID


14956 returns NOT VALID


4382 returns VALID



Source


"Luhn algorithm" GeeksforGeeks. Noida, Uttar Pradesh.  https://www.geeksforgeeks.org/luhn-algorithm/  Retrieved January 1, 2021.


"Luhn algorithm".  Wikipedia.  Last Updated December 23, 2020.  https://en.wikipedia.org/wiki/Luhn_algorithm  Retrieved January 1, 2021.  



Eddie


All original content copyright, © 2011-2021.  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, December 13, 2020

Numworks and DM42: Lucas-Lehmer Primality Test

 Numworks and DM42: Lucas-Lehmer Primality Test


Introduction


The Lucas-Lehmer Primality tests whether integers of the form 2^p - 1 are prime by repeating the loop p-2 times:


s_i+1 = s_i^2 - 2


with the initial value s_0 = 4.


At the end of the loop, if s = 0 mod (2^p - 1), then integer 2^p - 1 is a prime number.


Caution:  this test fails when p = 2.  The user will be asked to input an integer greater than 2.  


Numworks Python Script:  llt.py


from math import *

# Lucas-Lehmer Test

# 2020-12-06 EWS

p=float(input("p (>2)? "))

s=4

m=2**p-1

for i in range(p-2):

  # repeat p-2 times

  s=(s*s-2)%m

print("Mersenne Number:")

print(m)

if s==0:

  print("Prime")

else:

  print("Not Prime")


HP 42S/DM42 Program LLT


00 {66-Byte Prgm}

01 LBL "LLT"

02 "P (>2)?"

03  PROMPT

04  STO 01

05  ENTER

06  2

07  X<>Y

08  Y↑X

09  1

10  -

11 STO 04

12 R↓

13 2

14 -

15 STO 02

16 4

17 STO 03

18 LBL 00

19 RCL 03

20 X↑2

21 2

22 -

23 RCL 04

24 MOD

25 STO 03

26 DSE 02

27 GTO 00

28 RCL 04

29 "M= "

30 ARCL ST X

31 AVIEW

32 STOP

33 RCL 03

34 X=0?

35 "PRIME"

36 X=0?

37 AVIEW

38 END


Registers


R01: p

R02: p - 2

R03: s

R04:  m = 2^p - 1


Examples


p = 3

m = 7

Prime


p = 4 

m = 15

Not Prime


p = 5 

m = 31

Not Prime


p = 15

m = 32767

Not Prime


p = 20

m = 1048575

Not Prime


Source:


Cook, John D.  "Searching for Mersenne Primes" John D. Cook Consulting  November 28, 2018.  Retrieved December 5, 2020.  https://www.johndcook.com/blog/2018/11/28/searching-for-mersenne-primes/


"Lucas-Lehmer primality test"  Wikipedia.   Last edited June 29, 2020.  Retrieved December 5, 2020.

https://en.wikipedia.org/wiki/Lucas–Lehmer_primality_test


Eddie


Friday, April 17, 2020

Fun with Radio Shack EC-4019 and Casio fx-3800P

Fun with Radio Shack EC-4019 and Casio fx-3800P

First blog entry of the 10th year of this blog (4/11/2020 - 4/11/2021).  I can't expression enough gratitude for your support and comments - Eddie

Sums

n
∑ x  = (n^2 + n) / 2
x = 1

Program (9 steps):

ENT
Kin 1
x^2 
+
Kout 1
=
÷ 



Execution:  [ # ] n [ RUN ]

where [ # ] represents program keys [ I ], [ II ], [ III ], and [ IV ] in RUN mode ( [ MODE ] [ . ] )

Example:  n = 48, Result:  1176

n
∑ x^2 = n * ((n/3 + 1/2) * n + 1/6 )
x=1

Program (16 steps):

ENT
Kin 1
*
(
Kout 1
x^2
÷ 
3
+
Kout 1
÷

+
6
1/x
=

Execution:  [ # ] n [ RUN ]

Example:  n = 48, Result:  38024

Horner's Rule:  Cubic Polynomials

Calculate p(x) by Horner's Rule where:

p(x) = a*x^3 + b*x^2 + c*x + d = x * ( x * ( a*x + b ) + c ) + d

Program (16 steps):

Kout 5
+
Kout 1
*
(
Kout 4

Kout 1

(
Kout 2
*
Kout 1

Kout 3
=

Execution:  x [ Kin ] 1, a [ Kin ] 2, b [ Kin ] 3, c [ Kin ] 4, d [ Kin ] 5.   Press [ # ]

Example:  x = K1 = 50, a = K2 = 1, b = K3 = 4, c = K4 = 5, d = K5 = -200
Result:  135,050

Head Winds And Cross Winds

Head Winds:
HW = K * cos(D - HDG - V)

Cross Winds:
RCW = K * sin(D - HDG - V)

where:
K = wind velocity (mi/hr)  (K1)
D = wind direction with 0° due North, clockwise (degrees)  (K2)
HDG = airplane direction with 0° due North, clockwise (degrees)  (K3)
V = compass adjustment   (K4)

Mode 4: Degrees

Program (13 steps):

Mode
4        //  Degree mode
Kout 1
P → R 
(
Kout 2 
-
Kout 3
-
Kout 4

HLT   // HW
X ←→ Y  // RCW

Execution:
K [ Kin ] 1,  D [ Kin ] 2,  HDG [ Kin ] 3,  V [ Kin ] 4.  Press [ # ].

Example:
K = 25 mi/hr = K1
D = 240° = K2
HDG = 280°  = K3
V = 0  = K4

Results:
HW:  19.15111108 mi/hr
RCW:  -16.09699024 mi/hr

Source:  HP 65 Aviation Pac-1 Hewlett Packard.  1974

Rate of Climb

Rate of Climb (ft/min):
ROC = TAS * ALT ÷ √( DIST^2 + ALT^2 )

where:
TAS = true airplane speed (ft/min)   (K1)
ALT = vertical distance (ft)   (K2)
DIST = horizontal distance (ft)   (K3)

Conversion factors:
1 knot = 101.269 ft/min
1 nautical mile = 6072.12 ft

Program (13 steps):

Kout 1
*
Kout 2
÷
(
Kout 2
x^2

Kout 3
x^2
)

=

Execution:
TAS [ Kin ] 1,  ALT [ Kin ] 2,  DIST [ Kin ] 3.  Press [ # ].

Example:
TAS = 4,300 ft/min = K1
ALT = 3,000 ft = K2
DIST = 81,425 ft = K3

Result:  ROC: 158.3205808 ft/min

Source:  HP 65 Aviation Pac-1 Hewlett Packard.  1974

Modulus

For positive integers N, M:
N mod M = ( N / M - int(N / M) ) * M

Results lie in the interval [ -int( M / 2 ), int( M / 2 ) ]

Program (16 steps):

MODE
7
0     // Fix 0 mode 
Kout 2
1/x
*
Kout 1

Kin 3

Kout 3
RND   // round displayed number to settings
=
*
Kout 2
=

Execution:
N [ Kin ] 1,  M  [ Kin ] 2.  Press [ # ].

Examples:

48 mod 17 = -3  (equivalent to 48 mod 17 = 14)

721 mod 21 = 7


Eddie

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

Friday, March 13, 2020

Casio fx-9860g and fx-CG 50: Psuedorandom Numbers

Casio fx-9860g and fx-CG 50:  Psuedorandom Numbers

Introduction:  Generating Random Integers

The program PSUEDORN generates random integers by using the recurring relationship:

R_n+1 = (R_n * A + C) mod M

where R_0 = S, the seed
A = multiplier
M = modulus
C = increment

Outputs:

List 5:  list of integers generated.  If the list cycles, then the numbers return and we don't have a good random sample.

List 6:  percentile list of 10 elements, which each element represents a 10 percentile.  The best parameters will have elements of List 6 of around 0.1 uniformly.

List 6 =
{ 0% - 10% tile, 10% - 20% tile, 20% - 30% tile, 30% - 40% tile, 40% - 50% tile,
50% - 60% tile, 60% - 70% tile, 70% - 80% tile, 80% - 90% tile, 90% - 100% tile}
(percentage of the population)

List 6 is a demonstration of the bucket test.

Casio fx-9860GII and fx-CG 50 Program PSUEDORN

"2020-02-24 EWS"
"PSUEDORANDOM INTEGERS"
"MOD(R*A+C,M)→R"
"SEED"?→S
"MULTIPLIER"?→A
"MODULUS"?→M
"INCREMENT"?→C
"SAMPLE SIZE"?→T
1 → Dim List 5
10 → Dim List 6
MOD(SA+C,M) → R
Intg(10R ÷ M)+1 → B
List 6[B] + 1 → List 6[B]
For 2 → I To T
MOD(RA+C,M) → R
Augment(List 5, {R}) → List 5
Intg(10R ÷ M) + 1 → B
List 6[B] + 1 → List 6[B]
Next
"ANALYSIS:"
"MEAN:"
Mean(List 5) ◢
List 6 ÷ Dim List 6 → List 6
"BUCKET TEST:" ◢
List 6 ◢
"RANDOM NUMBERS (List 5)" ◢
List 5

Download the fx-9860gII and fx-9750gII version: 
https://drive.google.com/open?id=1PBTzvYtwZ5wLdIJqZ-oT6obgm3HnUcCp

Download the fx-CG 50 and fx-CG 10/20 version:
https://drive.google.com/open?id=1CqHPxYMdUeJjRxV4i3lKcOtWR-X0kAGu

Example

Generate a list of psuedorandom integers from 0 to 8192 with seed 111 of sample size 25. 

r_n+1 = (3 * r_n + 4) mod (2^13 + 1)
Seed: 111

Multiplier: 3
Modulus:  2^13 + 1
Increment:  4
Sample Size:  25

Bucket Test (List 6):  { 0.2, 0.4, 0.2, 0.4, 0.4, 0, 0.2, 0.3, 0.1, 0.3 }

List (List 5):
{ 0, 1015, 3049, 958, 2878, 445, 1339, 4021, 3874, 3433, 2110, 6334, 2620, 7864, 7210, 5248, 7555, 6283, 2467, 7405, 5833, 1117, 3355, 1876, 5632 }

Eddie

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

TI 84 Plus CE and HP Prime: Simplified Modulo Expressions

TI 84 Plus CE and HP Prime: Simplified Modulo Expressions

I hope you are having a great, at least sane Thanksgiving. It's Turkey Day (or the vegan equivalent of turkey day) in the United States.  Disclosure: I'm not vegan. 



Introduction

Let A, B, and M be positive integers where:

A ≡ B mod M

Let A = a * c   (A = a when c = 1)
B = b * c  (B = b when c = 1)
M = m

A "cancellation" theorem states that if:

a * c ≡ b * c mod m and gcd(c,m) = 1, then

a ≡ b mod c

Also, if a * c ≡ b * c mod m with gcd(c,m) = d, then

a ≡ b mod (m/d)

The program SIMPMOD uses the second theorem to find equivalent congruence for A ≡ B mod M.   The user inputs B and M, A and equivalent congruence will be calculated.

TI-84 Plus CE Program: SIMPMOD

Firmware version 5.3 or greater is required because of the toString command.  For earlier versions, you will have edit the last few lines. 

"2019-10-27 EWS"
"84+ CE 5.3"
ClrHome
Disp "A =  B MOD M"
Disp "A>0, B>0, M>0"
Input "B? ",B
Input "M? ",M
remainder(B,M)→A
Disp "A= ",A
iPart(√(B))→S
{1,B}→L_1
For(K,2,S)
B/K→T
If fPart(T)=0
augment(L_1,{K,T})→L_1
End
dim(L_1)→D
For(K,1,D)
L_1(K)→C
If fPart(A/C)=0
Then
A/C→R
B/C→S
M/gcm(M,C)→T
toString(R)+" = "+toString(S)+" MOD "+toString(T)→Str1
Disp Str1
End
End 
Disp "DONE"

L_1 is the L1 list variable, [2nd] [ 1 ]

HP Prime Program: SIMPMOD

CHAR(8801) or CHAR(#2261h) is the congruence symbol, ≡

EXPORT SIMPMOD()
BEGIN
// 2019-10-27 EWS
// A ≡ B MOD M
LOCAL B,M;
LOCAL A,R,S,T,K,l1,l2,D;
INPUT({B,M},
"A "+CHAR(8801)+" B MOD M",
{"B?","M?"});
A:=B MOD M;
PRINT();
l1:=CAS.idivis(B);
l2:=SIZE(l1);
D:=l2(1);

FOR K FROM 1 TO D DO
C:=l1(K);
IF FP(A/C)==0 THEN
R:=A/C;
S:=B/C;
T:=M/CAS.gcd(M,C);
PRINT(R+" "+CHAR(8801)+" "+
S+" MOD "+T);
END;
END;
PRINT("DONE");
END;

Examples

Example 1

20 ≡ 500 MOD 30

Inputs:  B = 500, M = 30

20 ≡ 500 MOD 30
10 ≡ 250 MOD 15
5 ≡ 125 MOD 15
4 ≡ 100 MOD 6
2 ≡ 50 MOD 3
1 ≡ 25 MOD 3

Example 2

4 ≡ 364 MOD 60

Input: B = 364, M = 60

4 ≡ 364 MOD 60
2 ≡ 182 MOD 30
1 ≡ 91 MOD 15

Example 3

28 ≡ 3528 MOD 100

Input:  B = 3528, M = 100

28 ≡ 3528 MOD 100
14 ≡ 1764 MOD 50
7 ≡ 882 MOD 25
4 ≡ 504 MOD 100
2 ≡ 252 MOD 50
1 ≡ 126 MOD 25

Source:

Dudley, Underwood.  Elementary Number Theory  2nd Edition.  Dover Publications, Inc:  Mineola, NY 1978  ISBN 978-0-486-46931-7  (2008 reprint)

Happy Thanksgiving!

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, November 22, 2018

TI-84 Plus and HP Prime: Chinese Remainder Theorem

TI-84 Plus and HP Prime:  Chinese Remainder Theorem

Introduction

The Chinese Remainder Theorem deals with solving the following congruences:

x ≡ r₀ mod m₀
x ≡ r₁ mod m₁
x ≡ r₂ mod m₂
...

where m₀, m₁, m₂, etc are all relatively prime.  Two integers are relatively prime when both integers have a GCD (greatest common divisor) is 1. 

We are going to focus on the two congruent system:

(I)
x ≡ r mod s
x ≡ t mod u

where the solution is x mod s*u.

HP Prime Function CAS.inchinrem

To solve the Chinese Remainder Theorem, use the function inchinrem. 

Syntax (reference (I) above):

Home/Programming Mode Syntax:  CAS.inchinrem([r, s], [t, u]). 
CAS Mode Syntax:  inchinrem([r, s], [t, u])

The answer returned is x mod s*u in vector form [x, s*u]. 

Where to find inchinrem:  [Toolbox], (CAS), 5.  Integer, 7. Division, 3.  Chinese Remainder


TI-84 Plus Program CTR2

"2018-11-18 EWS"
Disp "CHINESE REMAINDER","X=R MOD S","X=T MOD U"
Prompt R,S,T,U
If gcd(S,U)≠1
Then 
Disp "NO SOLUTION"
Stop
T-R→W
U*fPart(abs(W)/U)→W
If T-R<0 font="">
U-W→W
0→Y
0→N
Repeat W=N
1+Y→Y
U*fPart(S*Y/U)→N
End
S*Y+R→X
S*U→M
Disp "SOLUTION:",X,"MOD",M


Examples

Example 1:

x ≡ 3 mod 19
x ≡ 8 mod 11

Solution:  [41, 209],  41 mod 209

Example 2:

x ≡ 4 mod 14
x ≡ 7 mod 17

Solution:  [228, 238],  228 mod 238

Source:

Silverman, Joseph H.  A Friendly Introduction to Number Theory Prentice Hall, Inc: Upper Saddle River, New Jersey  2001.  ISBN 0-13-030954-0


Happy Thanksgiving!

Eddie

All original content copyright, © 2011-2018.  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.  Please contact the author if you have questions.

Sunday, July 2, 2017

Fun with the Casio fx-3650p

Links to previous fx-3650p programs:

5/11/2014:


Contents:
1. Circular Sectors
2. Stopping Sight Distance
3. Resistors in Parallel
4. Net Present Value
5. Rod Pendulum
6. Vectors: Dot and Cross Products


10/27/2015:


Contents for this blog:
1.  Combination with Replacement
2.  Great Circle (Distance in km) 
3.  Orbital Speed and Period 
4.  Eccentricity and Area of an Ellipse
5.  Super Factorial
6.  Escape Velocity 
7.  Finance: Payment of a Monthly Mortgage
8.  Wind Chill Factor
9.  Speed of Sound in Dry Air 

-------

Contents for this blog entry (7/2/2017)

1.  Modulus Function
2.  Normal CDF
3.  Sum:  Σ (AX + B)^C,  from X = 0 to X = Y
4.  Sun Altitude and Azimuth Based on the Vernal Equinox
5.  Trapezoid: Midsegment, Height, and Area
6.  Solar Irradiance
7.  General a list of X Random Integers from 0 to Y

Modulus Function

Calculates A mod B for A > 0 and B > 0.   Since the fx-3650p has no integer or fraction part functions, a loop of repeated subtractions are needed.

Program (25 steps):
? → A : ? → B : Lbl 1 : A – B → A : A ≥ B Goto 1 : A

Examples:
Input:  A = 77, B = 9.  Result: 5
Input:  A = 92.38, B = 2.38.  Result:  1.94 

Normal Distribution CDF

This calculates the area of a normal distribution curve between points A and B, given that mean = 0 and deviation = 1.  Radians mode is set.  The result is stored in C.

Program (34 steps):
? → A : ? → B : Rad : ∫ ( e (-X² ÷ 2 ), A, B → C : C ÷ √ (2 π → C

Note e is the exponential function (e^x).

Examples:
Input:  A = 0, B = 2.  Result:  0.47725066
Input:  A = -1, B = 1.  Result:  0.682709924


Sum:  Σ (AX + B)^C,  from X = 0 to X = Y

Program (51 steps):
? → A : ? → B : ? → C : ? → Y : 0 → X : 0 → M : Lbl 1 : (AX + B)^C M+ : 1 + X → X : Y ≥ X Goto 1: M

Examples:
Input:  A = 2. B = 6, C = 2, Y = 4.  Result:  540
Input:  A = -3, B = 1, C = 3, Y =6.  Result:  -9632

Sun Altitude and Azimuth Based on the Vernal Equinox


Input:
Y =  days after the vernal equinox, usually March 21
A = latitude on Earth (north-south, -90° to 90°)
X = the time before solar noon, local time

For example, for 10 AM (10:00), enter 2.  For 3 PM (15:00), enter -3.  Hence:  12 – time.

Output:
D = approximate declination of the sun (-23.45° to 23.45°)
B = sun’s altitude
C = sun’s azimuth (from ground wise north)

Program (69 steps):
? → Y : ? → A : ? → X : Deg : 23.45 sin(.9856Y → D   sin¯¹ (cos A cos D cos (15X) + sin A sin D → B cos¯¹ ( ( sin B sin A – sin D) ÷ (cos A cos B → C

Examples:

Input:  Y = 90 days, A = 25°, X = -3  (3 PM)
Results: 
D = 23.44400127° = 23°26’38.4”
B = 48.81756385° = 48°49’3.23”
C = 99.85903298° = 99°51’32.52”

Input:  Y = 68 days, A = 46°, X = 4 (8 AM)
Results:
D = 21.58916369° = 21°35’20.99”
B = 35.989914° = 35°59’23.69”
C = 84.40834691° = 84°24’30.05”

Source: Sun Altitude, Azimuth, Solar Pond Absorption, HP 67/97 Energy Conservation December 1978, Author: HP

Trapezoid: Midsegment, Height, and Area


Input:
A = length of top side
B = length of bottom side
C = length of left side
D = length of right side

Output:
X = Midsegment length
Y = Height
M = Area

Program (92 steps):
? → A : ? → B : ? → C : ? → D : .5(A + B → X (-A + B + C + D)(A – B + C + D)(A – B + C – D)(A – B- C- + D) → Y : √Y ÷ ( 2 √( (B – A)² ) → Y (A + B)Y ÷ 2 → M

Example:
Input:  A = 18, B = 16, C = 12, D = 11
Results:  X = 17, Y = 9.921567417, M = 168.6666461

Source:  “Trapezoid”  Wikipedia.  Edited July 7, 2014.  Retrieved July 8, 2014

Solar Irradiance



The program calculates:



1. The solar angle of incidence given the angular elevation and azimuth (from south going “counterclockwise”:  east-north-west) of both the sun and panel.
2. The irradiance given by the solar panel. 


Input:
X = elevation of the sun
A = azimuth of the sun
Y = elevation of the solar panel
Z = azimuth of the solar panel
M = the sun’s power or irradiance.  Often this is treated as a constant, which is approximately 1367 W/m^2 for extraterrestrial solar power, or approximately 1000 W/m^2 when we are dealing with the Earth’s surface (taking scattering of light into account)

Output:
C = incidence angle
D = solar irradiance

Program (46 steps):
? → X : ? → A : ? → Y : ? → B : ? → M : Deg : cos¯¹ ( cos Y sin X + sin Y cos X cos (A – B → C M cos Y → D

Example:
Input:

Sun:
X = 55°24’21”
A = 175°15’44”

Panel:
Y = 40°
B = 90°

Sun’s Irradiance:
M = 1000 W/m

Results:
C = 48.6431686°
D = 766.0444431 W/m

Sources (you might have to copy and past these links)  

Baldocchi, Dennis “Lecture 7, Solar Radiation, Part 3, Earth-Sun Geometry”  Biometeorogy, ESPM 129  University of California, Berkeley.


Retrieved February 17, 2015. 

Mortimer, David  “Lambert’s Cosine Law”  30 January 2014.  The Solar Bucket.


Retrieved March 18, 2015

University of Oregon Solar Radiation Monitoring Laboratory  “Solar Radiation Basics”  University of Oregon.  http://solardat.uoregon.edu/SolarRadiationBasics.html   Retrieved February 10, 2015

General a list of X Random Integers from 0 to Y

This program generates a list of random integers (X) from 0 to upper limit Y.  This program uses the Fix 0 mode and makes use of the Rnd (round the number in the display) command.  Note the integers as they appear.  The program finishes by setting the calculator back in Norm 1 mode.

Program (33 steps):
? → Y : ? → X : 1 → M : Fix 0 : Lbl 1 : Ran# Y : Rnd 1 M+ : X ≥ M Goto 1 : Norm 1

Example:
Generate 5 random integers from 0 to 10.  (Y = 10, X  = 5)
Result:  6, 7, 6, 6, 10 (your results will vary)

Comments

As with the other fx-3650p I and others have posted, they can easily be adapted to the fx-50fH, fx-5800p, fx-6300g, fx-CG50, and (almost) any other Casio programming calculator. 

Recently I learned that Casio updated the fx-3650P and the fx-50F(H) with the fx-3650P II and fx-50F(H) II respectively.  The only difference I was able to spot is that the fx-3650P II now has 390 programming steps instead of 360. http://www.casio-intl.com/asia/en/calc/school/programmable/

And yes, I still wish Casio sold these models in stores in the United States.  Currently, for us U.S. residents, they can only be purchased online. 

Now if Casio made a solar version of the fx-6300g, with more memory.

Eddie


This blog is property of Edward Shore, 2017.

RPN HP 12C: Fibonacci and Lucas Sequences

  RPN HP 12C: Fibonacci and Lucas Sequences Golden Ratio, Formulas, and Sequences Let φ be the Golden Ratio: φ = (1 + √5) ÷ 2...