Sunday, December 4, 2022

Casio fx-CG 50: Fresnel's Equations - Polarized Light

Casio fx-CG 50:  Fresnel's Equations - Polarized Light



Introduction:  Reflection and Transmission


The object of Fresnel's Equations is to calculate the reflection and transmissions of a light wave when it hits a change of medium.   Where the change of medium occurs is known as of a plane of incidence.  The equations calculate components:  p-polarized light for light parallel to the plane of incidence, and s-polarized light for perpendicular to the plane of incidence.  


The program presented also calculates Brewster's Angle, the angle required for light to hit the plane of incidence to have no reflection.  


Simplified, the equations are:


Angle of Transmission per Snell's Law:


Θt = arcsin(n1 × sin Θi ÷ n2)


Reflection Coefficients:


r ∥ = tan(Θi - Θt) ÷ tan(Θi + Θt) 


r ⟂ = -sin(Θi - Θt) ÷ sin(Θi + Θt) 


Transmission Coefficients:


t ∥ = (2 × sin Θt × cos Θi) ÷ (sin(Θi + Θt) × cos(Θi - Θt))


t ⟂ = (2 × sin Θt × cos Θi) ÷ sin(Θi + Θt)


Brewster's Angle:


Θb = arctan(Θt ÷ Θi)



Casio fx-CG 50 Program:  POLARIZE

(284 bytes)


Text file:


'ProgramMode:RUN

"2022-10-19 EWS"

Deg

"REFRACT INDEX 1"?->M

"_Theta_I"?->P

"REFRACT INDEX 2"?->N

"_Theta_T"

sin^-1 (M*sin P/N)->QDisps

"REFLECTION:"

"R_#E6D7_:"

tan (P-Q)/tan (P+Q)->RDisps

"R_#E6D5_:"

(-)sin (P-Q)/sin (P+Q)->TDisps

"TRANSMISSION:"

"T_#E6D7_:"

(2*sin Q*cos P)/(sin (P+Q)*cos (P-Q))->SDisps

"T_#E6D5_:"

(2*sin Q*cos P)/sin (P+Q)->UDisps

"BREWSTERS ANGLE:"

tan^-1 (N/M)->B


Program Code:


"2022-10-19 EWS"

Deg

"REFRACT INDEX 1"?→M

"ΘI"?→P

"REFRACT INDEX 2"?→N

"ΘT"

sin^-1 (M*sin P/N)→Q ◢

"REFLECTION:"

"R∥:"

tan (P-Q)/tan (P+Q)→R ◢

"R⟂:"

-sin (P-Q)/sin (P+Q)→T ◢

"TRANSMISSION:"

"T∥:"

(2*sin Q*cos P)/(sin (P+Q)*cos (P-Q))→S ◢

"T⟂:"

(2*sin Q*cos P)/sin (P+Q)→U ◢

"BREWSTERS ANGLE:"

tan^-1 (N/M)→B


The symbols ∥ and ⟂ are from the CHAR menu.  


Examples


All angles are in degrees.  


Example 1:


Inputs:

n1 = 1.00293 

ΘI = 20

n2 = 1.52 (glass)


Results:

ΘT = 13.04242914

R∥ = 0.1876099408

R⟂ = -0.2221588123

T∥ = 0.7836116039

T⟂ = 0.7778411877

Brewster's Angle = 56.58227879


Example 2:


Inputs:

n1 = 1.000293 (air)

ΘI = 34

n2 = 1.333 (water)


Results:

ΘT = 24.81075448

R∥ = 0.09793113211

R⟂ = -0.1866780705

T∥ = 0.8238955934

T⟂ = 0.8133219295

Brewster's Angle = 53.11516797



Sources


"Brewster's Angle".  Wikipedia.  https://en.wikipedia.org/wiki/Brewster%27s_angle  Retrieved October 18, 2022


"Fresnel's Equations: Reflection and Transmission"  HyperPhysics. http://hyperphysics.phy-astr.gsu.edu/hbase/phyopt/freseq.html  Retrieved October 16, 2022



Until next time,


Eddie


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

HP 15C and TI-84 Plus CE: Weibull Distribution Parameter Calculation

HP 15C and TI-84 Plus CE:  Weibull Distribution Parameter Calculation



Introduction


The Weibull probability density distribution function is:


f(x) = (b / Θ) * (x / Θ)^(b-1) * exp(-(x / Θ)^b)


with the lower tail cumulative distribution of (-∞ to x):


Area = 1 - exp(-(x / Θ)^b)


The area function tells us what is the probability a device lasts no more than x time units.  


Area = 1 - Survival


The survival function is the probability a device lasts more than x time units.


Survival = exp(-(x / Θ)^b)


Generally, the higher Θ is, the flatter the Weibull Distribution curve.  


In today's blog, we are estimating the parameters b and Θ given the number of data points, N, and data points (time periods to failure) x_i.   For the HP 15C program, which is modeled after the HP 55 program (see source below).   



The Process


Each x_i is sorted in ascending order.  Then transform the following data:


x' = ln x


α = (K - 0.3) ÷ (N + 0.4),  K = 1, 2, 3, ... , N


y' = ln( ln( 1 ÷ (1 - α)))


Enter each point (x', y'), and perform a linear regression analysis.


Then:  


b = slope


Θ = e^-(intercept ÷ slope)


 


HP 15C Program:  Weibull Distribution - Parameter Determination


Line #;  Key;  Code


001;  LBL A; 42, 21, 11

002;  1;  1

003;  STO 0;  44, 0

004;  CLΣ;  43, 32

005;  R/S;  31

006;  STO 1;  44, 1

007;  LBL 9;  42, 21, 9

008;  R/S;   31

009;  LN;  43, 12

010;  RCL 0;  45, 0

011;  . ;  48

012;  3 ;  3

013;  - ;  30

014; RCL 1;  45, 1

015; .  ;  48

016; 4 ;  4

017; +  ; 40

018; ÷ ; 10

019; 1 ;  1

020;  STO+ 0;  44, 40, 0

021;  x<>y  ; 34

022;  - ; 30

023;  1/x ;  15

024;  LN ; 43, 12

025;  LN ; 43, 12

026;  x<>y ; 34

027;  Σ+ ; 49

028;  GTO 9; 22, 9

029;  LBL B; 42, 21, 12

030;  L.R.;  42, 49

031;  x<>y ; 34

032;  R/S ; 31

033;  ÷ ; 10

034;  CHS;  16

035;  e^x;  12

036;  RTN;  43, 32


1.  Execute label A.   

2.  Enter N, the number of data points, then press the R/S key.

3.  Enter each x_i in ascending order, press R/S key in between each keys.  

4.  Execute label B.   The b parameter is displayed.  

5.  Press R/S.  The Θ parameter is displayed.



TI-84 Plus CE Program: WBFIT  


Weibull Distribution - Parameter Determination


"EWS 2022-10-09"

ClrHome

Disp "WEIBULL DIST.","FIT CALCULATION"

Input "DATA LIST: ",L1

SortA(L1)

dim(L1)→N

ln(L1)→L1

N→dim(L2)

For(K,1,N)

(K-0.3)/(N+0.4)→A

ln(ln(1/(1-A)))→L2(K)

End

LinReg(a+bx) L1,L2

b→B

e^(­(a/b))→θ

ClrHome

Disp "1-e^(­(X/B)^θ)"

Disp "B:",B,"θ:",θ


The x_i data are sorted in the WBIT program.  



Examples


Example 1:

Hours to failure:

{ 11000, 11056, 11379, 11821, 11956, 12403, 12526, 13000, 13380, 13663 }

N = 10


b ≈ 14.01123

Θ ≈ 12649.59071


Example 2:

Days to failure:

{ 1760, 1799, 1882, 1931, 1996, 2004, 2150 }

N = 7


b ≈ 15.22473

Θ ≈ 1993.22461


Sources:


HP55 Statistics Programs  Hewlett Packard Company.  Cupertino, CA.  1975


Ma, Dan.  "The Weibull distribution"  Topics in Actuarial Modeling.  September 28, 2016.   https://actuarialmodelingtopics.wordpress.com/2016/09/28/the-weibull-distribution/  Last Retrieved September 20, 2022.  



Eddie


All original content copyright, © 2011-2022.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Saturday, November 26, 2022

HP Prime CAS: Curvature

HP Prime CAS:  Curvature



Introduction


The following CAS functions calculates the curvature of:


functions, y(x)

polar functions, r(t)  (t: Θ)

parametric functions, x(t), y(t)


Let Δα be the angle of rotation angle and Δs is the slight change of distance. Then the radius of curvature is:


K = abs(Δα ÷ Δs) as Δs → 0


And the radius of curvature is the reciprocal of K.  


For circles, the radius of curvature is constant.  Wankel engines and rotary engines have their pistons traveling in a circle.


Calculating the curvature depends on the form of the function.  


Function:  y(x)


K = abs( y''(x) ) ÷ (1 + (y'(x))^2) ^(3/2)


Polar:  r(t)  (t replaces Θ)


K = abs( r(t)^2 + 2 * (r'(t))^2 - r(t) * r''(t) ) ÷ ( r(t)^2 + r'(t)^2 )^(3/2)


Parametric:  x(t), y(t) 


K = abs( x'(t) * y''(t) - y'(t) * x''(t) ) ÷ ( x'(t)^2 + y'(t)^2 )^(3/2)


Radius of Curvature:


r = 1 ÷ K



For the CAS functions, they take the form:


#cas

name(arguments):=

BEGIN

...

END;

#end


Clicking on the CAS checkbox will not put the #cas and #end delimiters.  And these programs will work in CAS mode only.



HP Prime CAS Program: crvfunc


#cas

crvfunc(y,x):=

BEGIN

// curvature

// function

// radius = 1/curvature

LOCAL a,b;

a:=diff(y,x,2);

b:=diff(y,x,1);

RETURN ABS(a)/(1+b^2)^(3/2);

END;

#end






HP Prime CAS Program: crvpol


#cas

crvpol(r,t):=

BEGIN

// curvature

// polar (t: θ)

// radius = 1/curvature

LOCAL a,b,n,d;

a:=diff(r,t,2);

b:=diff(r,t,1);

n:=simplify(r^2+2*b^2-r*a);

d:=r^2+b^2;

RETURN ABS(n)/(d)^(3/2);

END;

#end






HP Prime CAS Program: crvpar


#cas

crvpar(y,x,t):=

BEGIN

// curvature

// parametric

// radius = 1/curvature

LOCAL y1,y2,x1,x2,n,d;

y2:=diff(y,t,2);

y1:=diff(y,t,1);

x2:=diff(x,t,2);

x1:=diff(x,t,1);

n:=simplify(x1*y2-y1*x2);

d:=simplify(x1^2+y1^2); 

RETURN ABS(n)/(d)^(3/2);

END;

#end





Until next time and have a great day, 


Eddie 


Source:


Svirin, Alex Ph.D.      "Curvature and Radius of Curvature" Math24  https://math24.net/curvature-radius.html   2022.  Last Updated September 12, 2022.  


Gratitude to Arno K. and rombio for helping me with derivatives and CAS programs.  

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

HP 32SII: Some Algorithms For RPN Calculators

HP 32SII:  Some Algorithms For RPN Calculators



Four programs ported to the HP 32SII calculator from algorithms designated for the 1973 HP 45 calculator.  



HP 32SII: Euclid Algorithm - Greatest Common Divisor (GCD)


The HP 45 algorithm is found on page 228 in the Algorithms For RPN Calculators book. (see source below)


This algorithm takes up three labels.


E01 LBL E

E02 INPUT M

E03 ENTER

E04 ENTER

E05 ENTER

E06 INPUT N

E07 x<>y


K01 LBL 1

K02 ÷

K03 FP

K04 ×

K05 1

K06 x>y?

K07 GTO L

K08 R↓

K09 ENTER

K10 ENTER

K11 R↓

K12 R↓

K13 GTO K


L01 LBL L

L02 R↓

L03 R↓

L04 RTN


Sizes and Checksums:

E:  10.5 bytes, 9D4D

K:  19.5 bytes, F8AD

L:  6.0 bytes, C304

Total:  36.0 bytes


Instructions:

Press [ XEQ ] E, enter M and N.   


Examples:


Input:  M = 36, N = 28.  Result:  4

Input:  M = 48, N = 126. Result: 6

Input:  M = 115, N = 300.  Result: 5


HP 32SII:  GCD Using One Label - John Kenney 


The program was provided by Ross Barnes, and the algorithm is from the book ENTER by J. Daniel Dodlin and Keith Jarrett (ISBN 0-9615174-2-1, pg. 84).  This is smart, one label program.


Enter both numbers in the stack before running the program.


G01 LBL G

G02 ENTER

G03 ENTER

G04 -

G05 R↓

G06 x<>y

G07 LASTx

G08 /

G09 LASTx

G10 RDN

G11 IP

G12 x

G13 -

G14 x≠0?

G15 GTO G

G16 +

G17 RTN


Size and Checksum:  25.5 bytes, 4E39


Posted with permission.  


HP 32SII:  Tetens Equation


The HP 45 algorithm is found on page 290 in the Algorithms For RPN Calculators book.    The original algorithm took the temperature in Celsius. 


Find the saturation of water vapor (e_m) in mmHg (millimeters of Mercury) given the temperature in °F.


Determined Formulas:

T (in °C) = (T°F - 32) * 5/9

α = T/(236.87 + T)

e_m = 4.579 * 10^(7.49 * α)


T01 LBL T

T02 INPUT T

T03 →°C

T04 ENTER

T05 ENTER

T06 236.87

T07 +

T08 ÷

T09 7.49

T10 ×

T11 10^x

T12 4.579

T13 ×

T14 RTN


Size and Checksum:

45.0 bytes, 404A


Examples:

T = 68 °F, Result: 17.53658 mmHg

T = 99 °F, Result:  47.63501 mmHg




HP 32SII:  Dew Point Given Relative Humidity and Air Temperature


The HP 45 algorithm is found on page 290 in the Algorithms For RPN Calculators book.    The original algorithm took the temperature in Celsius. 


Relativity humidity (F) is to be entered as a decimal.  For instance, instead of 20%, enter 0.20.


Determined Formulas:

T (in °C) = (T°F - 32) * 5/9

A = T/(T + 236.87)

B = 1/(log F/7.49 + A)

TD = 236.87/(B - 1)

TD = TD * 9/5 + 32


D01 LBL D

D02 INPUT T

D03 →°C

D04 ENTER

D05 ENTER

D06 236.87

D07 STO A

D08 +

D09 ÷

D10 INPUT F

D11 LOG

D12 7.49

D13 ÷

D14 +

D15 1/x

D16 1

D17 -

D18 RCL÷ A

D19 1/x

D20 →°F

D21 RTN


Size and Checksum:

47.5 bytes, 8677


Examples:

T = 80, F = 0.64, Result:  66.725

T = 95, F = 0.32, Result:  60.50684



HP 32SII:  Effective Temperature Due to Wind Velocity



The HP 45 algorithm is found on page 291 in the Algorithms For RPN Calculators book.    The original algorithm took the temperature in Fahrenheit. 


Wind velocity is in miles per hour (mph).  


Determined Formulas:

A = 0.634*(0.634 - log V)

ΔT = A*(T - 90)

Effective T = T - ΔT


E01 LBL E

E02 0.634

E03 ENTER

E04 ENTER

E05 INPUT V

E06 LOG

E07 -

E08 ×

E09 INPUT T

E10 ENTER

E11 90

E12 -

E13 ×

E14 RCL T

E15 x<>y

E16 -

E17 RTN


Size and Checksum:

33.5 bytes, 54F7


Examples:

V = 20 mph, T = 15 °F,  Result: -16.71728

V = 15 mph, T = 86 °F,  Result: 84.62526


Source:


Ball, John A.  Algorithms For RPN Calculators  John Wiley & Sons:  New York, NY.  1978. ISBN 0-471-03070-8

For the second GCD program:

Dodin, J. Daniel and Keith Jarrett. ENTER: Reverse Polish Notation Made Easy   Synthetix:  Berkeley, CA   ISBN 0-9612174-2-1  1984.


Special thanks and gratitude to Ross Barnes.  



All original content copyright, © 2011-2022.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Saturday, November 19, 2022

Casio fx-9750GIII: Integrals with Infinite Limits

Casio fx-9750GIII:  Integrals with Infinite Limits





A Substitution to Get to Infinity... 


It is quite a challenge to calculate numerical integrals with infinite limits such as 


∫( f(x) dx, a, ∞)


∫( f(x) dx, -∞, a)


∫( f(x) dx, -∞, ∞)



A trick is to substitute x = tan Θ.  Then:


Θ = arctan x


dx = sec^2 Θ dΘ = cos^-2 Θ dΘ



Note that


lim t→∞ arctan t = π/2


lim t→-∞ arctan t = -π/2  


In this blog, assume that radian angle mode is used in all calculations.


Let's go over some examples and see how it works.  I used a Casio fx-9750GIII, however, this technique should work with all calculators with numerical integral calculations.  Furthermore, changing the integral will allow for Simpson's Rule or Trapezoid Rule approximation.


For the upper limit, I approximate π/2.


A = 1.5708  (π/2 to 4 places)

B = 1.570796  (π/2 to 6 places)

C = 1.57079633 (π/2 to 8 places)



Example 1:  


∫( e^(-x^2) dx, 0, ∞)  


transforms to


∫( e^(-tan^2 Θ)/cos^2 Θ dΘ, 0, ≈π/2)


Calculations (fx-9750GIII):


Upper Limit: A (see above),  Result:  0.8862269255


Upper Limit: B,  Result:  0.8862269255


Upper Limit: C,  Result:  0.8862269255




Example 2:  


∫(x^0.5 * e^(-x) dx, 0, ∞)


transforms to


∫((tan Θ)^0.5 * e^(-tan Θ))/cos^2 Θ dΘ, 0, π/2)


Calculations:


Upper limits A, B, C:  0.862269255


Coincidently, ∫( e^(-x^2) dx, 0, ∞)  = ∫(x^0.5 * e^(-x) dx, 0, ∞) = Γ(1.5) = √(π)/2




Example 3:


∫( e^x*(x^2 + 1) dx, -∞, 0)


transforms to


∫( e^(tan Θ) * (tan^2 Θ + 1)/cos^2 Θ dΘ, -π/2, 0)

=  ∫( e^(tan Θ) * 1/cos^2 Θ * 1/cos^2 Θ dΘ, -π/2, 0)

∫( e^(tan Θ)/cos^4 Θ dΘ, -π/2, 0)


For upper limits A, B, C, the answer returned is 3, which is the exact answer.  


For integrals like this all is needed is a four digit approximation of π/2 = 1.5708.



Let's keep going:


Example 4:


∫( (x^2 + 1)/(x^4 - 1) dx, 0, ∞) 


transforms to


∫( 1/cos^Θ * (tan^2 Θ + 1)/(tan^4 Θ - 1) dΘ, 0, π/2)

= ∫( 1/(sin^4 Θ - cos^4 Θ) dΘ, 0, π/2)


On the fx-9750GIII get MA Error.  



Example 5:


∫( 1/√(x^2 + 3*x + 1) dx, 0, ∞)


transforms to 


∫( 1/(cos^2 Θ * √(tan^2 Θ + 3 * tan Θ + 1)) dΘ, 0, π/2)


like example 4, I get the MA Error.



Observation:  the transformation works best if the integral involves some form of either of the following:


f(x) * e^(g(x))


or 


f(x) * e^(-g(x))



Gamma


The Gamma Function is an excellent candidate for this transformation.  


Γ(t) = ∫( x^(t-1) * e^-x dx, 0, ∞)


transforms to


∫( tan^(t-1) Θ * e^(-tan Θ)/cos^2 Θ dΘ, 0, π/2)



Source


Mier-Jedrzejuwicz, W.A.C. Ph.D.    Tips And Programs for the HP 32S   Synthetix Publication.  Berkeley, CA.  September 1988.  ISBN 0-937637-05-X


Download the book here:  https://literature.hpcalc.org/items/1756




Happy calculating,


Eddie


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

HP 15C: Weibull Distribution Calculations

HP 15C:  Weibull Distribution Calculations


Introduction


The Weibull probability density distribution function is:


f(x) = (b / Θ) * (x / Θ)^(b-1) * exp(-(x / Θ)^b)


with the lower tail cumulative distribution of (-∞ to x):


Area = 1 - exp(-(x / Θ)^b)


The area function tells us what is the probability a device lasts no more than x time units.  


Area = 1 - Survival


The survival function is the probability a device lasts more than x time units.


Survival = exp(-(x / Θ)^b)


Generally, the higher Θ is, the flatter the Weibull Distribution curve.  


What follows are four calculations regarding the Weibull Distribution.  In the following programs, store the following values first prior to running the programs:


R0 = x

R1 = b

R2 = Θ


Use whatever labels you like.  


HP 15C Program:  Lower Tail Probability - Weibull Distribution


CDF = 1 - exp(-(x/Θ)^b)


Keys:


LBL B

1

RCL 0

RCL÷ 2

RCL 1

y^x

CHS

e^x

-

RTN


Key Codes:


42, 21,12

1

45, 0

45, 10, 2

45, 1

14

16

12

30

43, 32


Example:  

b = 1.96, Θ = 420

x = 300, result:  0.4038

x = 400, result:  0.5970

x = 500, result:  0.7552


HP 15C Program:  Failure Rate - Weibull Distribution


FR = b/Θ * (x/Θ)^(b-1) 


Keys:


LBL C

RCL 1

RCL÷ 2

RCL 0

RCL÷ 2

RCL 1

1

-

y^x

*

RTN


Key Codes:


42, 21, 13

45, 0

45, 10, 2

45, 0

45, 10, 2

45, 1

1

30

14

20

43, 32


Example:  

b = 1.96, Θ = 420

x = 300, result:  0.0034

x = 400, result:  0.0045

x = 500, result:  0.0055


HP 15C Program:  Mean of a Weibull Distribution


µ = (1/b)! * Θ


Keys:


LBL D

RCL 1

1/x

x!

RCL× 2

RTN


Key Codes:


42, 21, 14

45, 1

15

42, 0

45, 20, 2

43, 32


Example:  

b = 1.96, Θ = 420

Result:  373.3720


HP 15C Program:  Standard Deviation of a Weibull Distribution


σ = Θ * √((2/b)! - (1/b)!^2)


Keys:


LBL E

2

RCL 1

÷

x!

RCL 1

1/x

x!

x^2

-

RCL× 2

RTN


Key Codes:


42, 21, 15

2

45, 1

10

42, 0

45, 1

15

42, 0

43, 11

30

11

45, 20, 2

43, 32


Example:

b = 1.96, Θ = 420

Result:  198.2208


Sources:


HP55 Statistics Programs  Hewlett Packard Company.  Cupertino, CA.  1975


Ma, Dan.  "The Weibull distribution"  Topics in Actuarial Modeling.  September 28, 2016.   https://actuarialmodelingtopics.wordpress.com/2016/09/28/the-weibull-distribution/  Last Retrieved September 20, 2022.  



Eddie


All original content copyright, © 2011-2022.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Saturday, November 12, 2022

HP Prime: Reversing an Integer's Digits

HP Prime:  Reversing an Integer's Digits


(Inspired by the HHC 2022 programming contest)


What Should I Add To Reverse the Digits?


Let A, B, C, D, and E be individual digits (0-9) of an integer.   AB would represent a two digit integer with the value of 10 * A + B.  ABC would represent a three digit integer with the value of 100 * A + 10 * B + C.


Reversing a Two Digit Integer


AB + # = BA

10 * A + B + # = 10 * B + A

# = 9 * (B - A)


Example:  Let AB = 76.

A = 7, B = 6

# = 9 * (6 - 7) = -9

76 - 9 = 67


Reversing a Three Digit Integer


ABC + # = CBA

100 * A + 10* B + C + # = 100 * C + 10 * B + A

# = 99 * (C - A)


Example:  ABC = 469

# = 99 * (9 - 4) = 495

469 + 495 = 964


Reversing a Four Digit Integer


ABCD + # = DCBA

1000 * A + 100 * B + 10 * C + D + # = 1000 * D + 100 * C + 10 * B + A

# = 999 * (D - A) + 90 * (C - B)


Example:  ABCD = 7219

# = 999 * (9 - 7) + 90 * (1 - 2) = 1908

7219 + 1908 = 9127


Reversing a Five Digit Integer


ABCDE + # = EDBCA

10000 * A + 1000 * B + 100 * C + 10 * D + E + # =

10000 * E + 1000 * D + 100 * C + 10 * B + A 

# = 9999 * (E - A) + 990 * (D - B)


Example: ABCDE = 52693

# = 9999 * (3 - 5) + 990 * (9 - 2) = -13068

52693 - 13068 = 39625


Having the Calculator Do It


The program REVINT reverses the digits of an integer, up to 11 digits.   The program does not allow numbers that have non-zero fractional parts or integers more than 11 digits.  Instead of solving for # (see above), the program splits the integers into a list in reverse order, and uses list processing to get the final answer. 


HP Prime Program:  REVINT


Caution:  Integers that end or begin with zero may not return accurate results.   My suggestion is not use 0s with this program.  See examples below for more details.  


EXPORT REVINT(N)

BEGIN

// 2022-09-18 EWS

// reverse the integer N

// up to 12 digits

LOCAL D,P,A,I,M,L;

L:={};

P:=XPON(N);


// check size 

  IF P>11 THEN

  RETURN "TOO BIG";

  KILL;

  END;

 

// check type

  IF FP(N) THEN

  RETURN "NOT AN INTEGER";

  KILL;

  END;

   

D:=N;


// loop

  FOR I FROM P DOWNTO 0 DO

  A:=D/ALOG(I);

  L:=CONCAT({IP(A)},L);

  D:=D-IP(A)*ALOG(I); 

  END;

  

// rebuild 

M:=ΣLIST(MAKELIST(ALOG(X),X,P,0,−1)*L);

RETURN M; 

END;


Examples:


REVINT(4321) returns 1234


REVINT(56765) returns 56765   (56765 is a palindrome, reversing the digits results in the same number)


REVINT(42910) returns 1924 (01924 - be aware about integers ending or beginning with 0)


REVINT(67.28) returns "NOT AN INTEGER" (error)



Eddie


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


Casio fx-CG 50: Fresnel's Equations - Polarized Light

Casio fx-CG 50:  Fresnel's Equations - Polarized Light Introduction:  Reflection and Transmission The object of Fresnel's Equations ...