Saturday, October 31, 2020

Breaking Down the Factorial

Breaking Down the Factorial


Factorial: It's Not Just For Integers


Let n be a positive number, where n > 0.   n! can be rewritten as:


n! 

= n * (n - 1)!

= n * (n - 1) * (n - 2)!

= n * (n - 1) * (n - 2) * (n - 3)!

...

= n * (n - 1) * (n - 2) * (n - 3) * ... * k


where 0 ≤ k ≤ 1.   Note that 0! = 1.   Keep the loop multiplying n, n - 1, n - 2, n - 3, etc. until you a multiplying a number between 0! and 1! to the total.


For certain k:


0.25! ≈ 0.9064024771

0.50! = ≈ 0.8862269255

0.75! ≈ 0.9190625268

1! = 1


Examples


3! = 3 * 2 * 1! = 3 * 2 * 1 = 6

3.25! = 3.25 * 2.25 * 1.25 * 0.25! = 9.140625 * 0.25! ≈ 8.285085142

3.5! = 3.5 * 2.5 * 1.5 * 0.5! = 13.125 * √π ÷ 2 ≈ 11.6317284

3.75! = 3.75 * 2.75 * 1.75 * 0.75! = 18.046875 * 0.75! ≈ 16.58620654


4! = 4 * 3 * 2 * 1! = 4 * 3 * 2 * 1 = 24

4.25! = 4.25 * 3.25 * 2.25 * 1.25 * 0.25! = 38.847652625 * 0.25! ≈ 35.21161185

4.5! = 4.5 * 3.5 * 2.5 * 1.5 * 0.5! = 59.0625 * √π ÷ 2 ≈ 52.3427778

4.75! = 4.75 * 3.75 * 2.75 * 1.75 * 0.75! = 85.72265625 * 0.75! ≈ 78.78448106


Factorial Values of 0 to 1


Below is a chart are the values for 0 to 1, along with several approximation polynomials.  The value and polynomials have been determined using LibreOffice's Calc application.  








Happy Halloween, 

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. 


Sunday, October 25, 2020

Swiss Micros DM41X: Custom Menus

 Swiss Micros DM41X: Custom Menus




Customize It


With the new Swiss Micros DM41X, custom menus comes to the HP 41C engine.   The custom menu can hold up to 16 commands or user program shortcuts.   Best yet, the customized menu can be saved and transferred among fellow DM 41X users.   The custom menu is very easy to use and set up.


To access the custom menu, just press the [ CST ] key.   To use one of the commands, just press the corresponding key related to the assigned letter, no prior alpha key is required.  For example, to access the command in the A slot, press [ CST ] [ Σ+ ].  


The custom menu has six other commands that are always present:


1.  Help:  The DM41X's help facility which additional commands that come with the 41X, information about the ISG/DSE loops, date, time, and alarms, and additional topics like Angel's references.


2.  ROM Map:  A map where all the modules are loaded into the virtual ROM facility of the DM41X.


3.  Load a RAW file


4.  Save a RAW file


5.  USB Disk:  Put the DM41X in USB mode, allowing to transfer files between the calculator and the computer


6.  Flags:  A map listing the state of all the DM41X's flags.  0 means the flag is off, 1 means the flag is on.


To customize the custom menu, press [gold shift] [ CST ] (CONF).


Pick any of the slots A through P.  While in this mode, you can customize three additional key sequences:


[ gold shift ] [ blue alpha ]


[ gold shift ]  [ ↑ ] 


[ gold shift ]  [ ↓ ]


When prompted, just type the command, label, or program name.  Alpha mode has been turned on automatically.  Finish and accept by pressing the [ R/S ] key.   Pressing the [ ON ] cancels the customization.   The custom menu does not affect the programming memory.


One more thing, the name cannot have a space.   For example:  ARCL ST X is not allowed.   ARCL is.  


That's all there is to it.  Have fun,


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. 


Saturday, October 24, 2020

HP 42S/DM42/Free42: Drawing Lines and Circles

 HP 42S/DM42/Free42:  Drawing Lines and Circles



Introduction

The HP 42S, Swiss Micros DM42, and Free42 has several graphics commands that allows for drawing and plotting functions.   The following programs draw simple geometric objects on the calculator's screen:

HLINE:  horizontal line

VLINE:  vertical line

DLINE:  a line between two points

DCIRC:  draw a circle given a center point and radius


The graphics screen of the 42S is 131 x 16.  The x axis goes from 1 to 131 to the right, while the y axis goes from 1 to 16 down.  


To plot points along the line, use the equation:

y = slope * x + (y1 - x1 * slope)

where slope = (y1 - y0) / (x1 - x0)


For the circle, the pixels to be plotted are:

x' = x + r * sin θ

y' = x + r * cos θ

for θ from 0° to 360°  (0 to 2π in radians)


Since a full circle is plotted, we don't have to worry about accounting for the fact that the y axis is inverted.  


Commands used:


CLLCD:  clear the screen


PRLCD:  print the screen.  Depending on whether the printer is on or off and what machine is being used, the screen would printed to the optional infrared printer or saved as a print file.  Turning print off (by the PROFF setting) will just display the screen.  


PIXEL:  Takes the arguments from the y-stack and x-stack and draws a pixel.   There are several flags that can affect how the command operates, that is beyond the scope of this blog entry.  Non-integer numbers can be used as pixels.


HP 42S/DM42/Free42 Program:  HLINE


     00 { 58-Byte Prgm }

          01 LBL "HLINE"

           02 "X START?"

             03 PROMPT  

             04 STO 01  

             05 "X END?"

             06 PROMPT  

             07 STO 02  

             08 "Y?"    

             09 PROMPT  

             10 STO 03  

             11 RCL 02  

             12 1ᴇ3     

             13 ÷       

             14 RCL+ 01 

             15 STO 00  

             16 CLLCD   

             17 LBL 01  

             18 RCL 03  

             19 RCL 00  

             20 IP      

             21 PIXEL   

             22 ISG 00  

             23 GTO 01  

             24 PRLCD   

             25 END 


HP 42S/DM42/Free42 Program:  VLINE


    00 { 58-Byte Prgm }

          01 LBL "VLINE"

             02 "X?"    

             03 PROMPT  

             04 STO 03  

           05 "Y START?"

             06 PROMPT  

             07 STO 01  

             08 "Y END?"

             09 PROMPT  

             10 STO 02  

             11 RCL 02  

             12 1ᴇ3     

             13 ÷       

             14 RCL+ 01 

             15 STO 00  

             16 CLLCD   

             17 LBL 01  

             18 RCL 00  

             19 IP      

             20 RCL 03  

             21 PIXEL   

             22 ISG 00  

             23 GTO 01  

             24 PRLCD   

             25 END  


HP 42S/DM42/Free42 Program:  DLINE


The x coordinates are entered first.  The point (x0, y0) is the to left of the point (x1, y1) and x0 < x1 is required.  Attempt to draw vertical lines where x0 = x1 using DLINE will result in an error.


 00 { 89-Byte Prgm }

          01 LBL "DLINE"

            02 "X0 < X1"

             03 AVIEW   

             04 STOP    

             05 "X0?"   

             06 PROMPT  

             07 STO 01  

             08 "X1?"   

             09 PROMPT  

             10 STO 03  

             11 1ᴇ3     

             12 ÷       

             13 RCL+ 01 

             14 STO 00  

             15 "Y0?"   

             16 PROMPT  

             17 STO 02  

             18 "Y1?"   

             19 PROMPT  

             20 STO 04  

             21 X<>Y    

             22 -       

             23 RCL 03  

             24 RCL- 01 

             25 ÷       

             26 STO 05  

             27 RCL× 03 

             28 +/-     

             29 RCL+ 04 

             30 STO 06  

             31 CLLCD   

             32 LBL 01  

             33 RCL 00  

             34 IP      

             35 RCL× 05 

             36 RCL+ 06 

             37 RCL 00  

             38 IP      

             39 PIXEL   

             40 ISG 00  

             41 GTO 01  

             42 PRLCD   

             43 END     


HP 42S/DM42/Free42 Program:  DCIRC


 00 { 70-Byte Prgm }

          01 LBL "DCIRC"

             02 "X CTR?"

             03 PROMPT  

             04 STO 01  

             05 "Y CTR?"

             06 PROMPT  

             07 STO 02  

            08 "RADIUS?"

             09 PROMPT  

             10 STO 03  

             11 DEG     

             12 0.36005 

             13 STO 00  

             14 CLLCD   

             15 LBL 01  

             16 RCL 00  

             17 IP      

             18 RCL 03  

             19 →REC    

             20 RCL+ 01 

             21 X<>Y    

             22 RCL+ 02 

             23 X<>Y    

             24 PIXEL   

             25 ISG 00  

             26 GTO 01  

             27 PRLCD   

             28 .END.   


These programs and routines can be used stand-alone or as subroutines.  


You can download the four programs here:  

https://drive.google.com/file/d/1FJqVTkGMAtLa-0eMBHQ1LEfdKGt55VNM/view?usp=sharing


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. 


Sunday, October 18, 2020

HP 42S/DM42: Height of a Fire, Time to Clear a Corridor

 HP 42S/DM42:  Height of a Fire, Time to Clear a Corridor


HP 42S/DM42/Free42 Program:  FIREHGT


The program FHGT approximates the height of a fire in three scenarios:


* A relatively large fire

* A fire with a base area of approximately 0.5 meter

* A fire set in a corner


The general equation is:


H = factor * Q^0.4


H = height of a fire in meters, including the tip

factor = constant depending on the scenario the fire is set in

Q = energy release rate in kilowatts


00  {119-Byte Prgm}

01 LBL "FIREHGT"

02 "ENERGY? (kW)"

03 PROMPT

04 STO 01

05 LBL 00

06 "TYPE?"

07 AVIEW

08 "LARGE"

09 KEY 1 GTO 01

10 "0.5 M"

11 KEY 2 GTO 02

12 "CORNER"

13 KEY 3 GTO 03

14 MENU

15 LBL 10

16 STOP 

17 GTO 10

18 LBL 01

19 0.23

20 GTO 04

21 LBL 02

22 0.21 

23 GTO 04

24 LBL 03

25 0.075

26 GTO 04

27 LBL 04

28 CLMENU

29 EXITALL

30 RCL 01

31 0.4

32 Y↑X

33 ×

34 "HEIGHT=" 

35 ARCL ST X

36 AVIEW

37 END


Example:


Q = 2650 kW


large fire:  H = 5.38302238231 m

0.5 m fire:  H = 4.9149334795 m

corner fire:  H = 1.7553338554 m


HP 42S/DM42/Free42 Program:  SMOKE


The program SMOKE estimates:


*  The front velocity of the smoke, or how quickly the smoke fills a corridor

*  The time it takes for front velocity to fill the corridor.


Equations used:


V ≈ 0.5 * √(g * (1 - Ta/T) * H)

tf = L / Vf


g = acceleration of gravity, for Earth, g = 9.80665 m/s

Ta = ambient temperature

T = gas temperature  (Ta ≤ T)

H = height of the corridor in meters

L = length of the corridor in meters 


Note 1 - Ta/T = (Da - Dc) / Da

Da = density of the corridor of the ambient air

Dc = density of the fire fluid


00 {99-Byte Prgm}

01 LBL "SMOKE"

02 1

03 "AMB. TEMP?"

04 PROMPT

05 "GAS TEMP?"

06 PROMPT

07 ÷

08 -

09 9.80665

10 ×

11 "HEIGHT? (M)"

12 PROMPT

13 ×

14 SQRT

15 2

16 ÷

17 ENTER

18 "VEL= "

19 ARCL ST X

20 AVIEW 

21 STOP 

22 R↓

23 1/X

24 "LENGTH? (M)"

25 PROMPT

26 ×

27 "TIME="

28 ARCL ST X

29 AVIEW

30 END


Example:


Amb. Temp:  78 °F = 25.555555556 °C

Gas Temp:  103 °F = 39.44444444 °C

Height:  3.048 m

Length:  3.6576 m


Results:


Velocity:  1.622103844 m/s

Time:  2.254849474 s


Source:


Lawson, J.R. and Quintiere, J.G..   "Slide Rule Estimates of Fire Growth". Fire Technology, Vol. 21., No. 4, November 1985, pg. 267



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. 


Saturday, October 17, 2020

Review: Catiga CS-121

Review:  Catiga CS-121








Just the Facts:


Model:  CS-121 (could be other model numbers)

Company: Catiga

Type: Graphing

Battery:  Case contains 2 CS-2032 slots, but can run on 1

Logic: Algebraic

Memory Registers: 9 

Colors:  Many colors including Black, Red, Blue.  I purchased a blue CS-121.  


Case and Keyboard


The cover case and calculator casing for the CS-121 is very light.  When sliding the calculator into the case, you really have to listen for the snap to lock the calculator in place.  The keys are very fast and responsive, you will have no problems typing in expressions quickly.  


Screen


Like most graphing calculators, the CS-121 has a large screen.  However, the CS-121 does not use the screen like most graphing calculators.   The CS-121 operates as a large Casio fx-6300g instead.   Graphs take up part of the left side of the screen and you can see only the X or the Y (not both) coordinates during tracing.   The expression line is reduced to the bottom line of the screen.  


This is my biggest gripe of the CS-121.   This screen scheme may have worked on the fx-6300g and its relatives fx-6200g and HP 9g because they have small screens to work with, but the CS-121 should have full screen graphs and allowed the use of the entire screens for expressions in Home mode. 


Features of the CS-121


Left,  Catiga CS-121;  Right, Casio fx-6300g


The CS-121 isn't an entire clone of the fx-6300g because it does have some nice advanced features.  


Graphing:  Functions (up to 2 functions), Parametric (1 parametric pair)

Calculus:  Numeric Integrals of f(x)

Solver:  Solve for any variable

Complex Number Mode:  Arithmetic, Cube, Cube Root, Square, Square Root, Absolute Value, Argument (angle).   The [ENG] acts as the i key.  Switch between showing the real and complex results by pressing [ SHIFT ] [ = ].  All complex numbers operate in rectangular format (a + bi).  

Regressions:  Linear, Logarithm, Exponential, Power, Inverse, Quadratic.   Get the correlation ( r ) by pressing [SHIFT] [ ( ].  

Base-N:  The CS-121 adds boolean logic functions ([x^3] key):  And, Or, Nxor, Xor, Not, Neg

Drawing Tools:  Plot points, lines including lines between two points, horizontal, vertical, and tangent.   It is a little frustrating that the CS-121 does not use the entire screen for graphs because it would really enhance the use of the drawing tools.  


Memory


Let's talk about the memory.  It is very unusual for a graphing calculator to only have nine memory slots (A, B, C, D, E, F, X, Y, M with M+ and M-).  It's because the CS-121 does not have programming.  Yes, you can store an equation in the form var=f(vars) with the [SHIFT] [ Calc ] (PROG) key sequence and calculate using the stored equation by using [ Calc ].  


It is very rare that a graphing calculator does not have programming.  The rare Casio fx-6200g was a direct relative to the fx-6300g and it did not have programming.  


The Learn (LRN) Key


The [LRN] key allows users to shift graphs or change the size of the graphs.  Handy when learning about functions.  


Verdict


I like the keyboard and I like how responsive the calculator operates.  The CS-121 operates on not much battery (ultimately 1 CS-2032 battery).  As said before, my major gripe is the mismanaged use of the screen.   



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, October 15, 2020

HPCC 2020 Virtual Conference and Document Website

 HPCC 2020 Virtual Conference and Document Website 


HPCC 2020 Virtual Conference


The HPCC 2020 Virtual Conference took place on October 10, 2020.   The HPCC is the Handheld and Portable Computer Club is a long running calculator and computer site based out of the United Kingdom.  Their meetings are held virtually on the 2nd and 4th Saturday of every month.  I have recently joined the HPCC and glad to be a part of the club. 

You can find more information on the meetings here:  http://www.hpcc.org, under the Home tab.  Membership rates are between £17 to £23 depending where you live.


The conference has the following speakers and topics:


Eric Rechlin:  USB Drive Update

Jake Schwartz:  Updates to the PPC Archive

Bob Prosperi:  Swiss Micros DM41X - A little late; a lot better

Eric Hazen:  HP-25 Re-implementation on Z80 with VFD display

Michael Park:  MP-29 - a tactile touchscreen calculator

Mark Power:  Prime G2

Sylvain Côté:  Clonix & NoV modules for the HP-41

Edward Shore:  CAS and Calculators

Gene Wright and Włodek Mier-Jędrzejowicz: HP's Worst Calculators

Godwin Stewart:  Presentation on DMConnect 

Will Marchant:  DM16 in a satellite launch campaign


Conference web page:  http://www.hpcc.org/conferences/index.html


Each talk has slides for download and the corresponding YouTube video.  Special thanks to Eric Rechlin. 


HP Documentation Website


Eric Rechlin of hpcalc.org has put together a new website where you can download manuals for Hewlett Packard calculators, past and present.  


Link:  https://literature.hpcalc.org


Coming soon:  the USB that contains information calculator conferences including manuals through 2020 will be available his commerce site,  https://commerce.hpcalc.org.


Eddie  (Edward Shore)


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. 


Sunday, October 11, 2020

Casio Classpad: Theorem of Sós

Casio Classpad:  Theorem of Sós


Introduction: The Theorem of Sós

A set of triple rational numbers (a, b, λ) is considered to be a H-triple if

c = √(a^2 - 2 λ a b + b^2) is also a rational number.  (I)


Heron Triple

Should the set of rational numbers (a, b, λ) can be further test to see if to is also a Heron triple.  That criteria (see source) requires for some numbers λ' and A (area):

λ' = √(1 - λ^2) is a positive rational number, and

A = λ' * abs(a * b) / 2 is a natural number  (positive integer)


This implies for all cases for Heron Triples that abs(λ) < 1, or -1 < λ < 1.

If the H-triple passes, then it becomes a Heron triple and the sides (a, b, c) (see (I) above) are the lengths of a Heron triangle.  

It is possible that an H-triple is not a Heron triple.  

Today's blog focuses on H-triples.  


Generating H-Triples

Given relatively prime integers m and n (where gcd(m,n) = 1) and μ, an H-triple can be generated by the following equations:


(II)

a = μ * (m^2 - n^2)

b = μ * (2*m * (n + λ*m))

c = μ * (m^2 + 2*λ*m*n + n^2)

For a > 0, this requires that m > n.  In the program htrigen, I assume that μ = 1.  In the program, u = λ

Casio Classpad Program:  htrigen

(fx-CP400 and fx-CG500)


'2020-09-15 EWS

'H Triple

Local a,b,c,m,n,u

Input m, "m > n", "m?"

Input n, "m > n", "n?"

Input u, "λ? (rational)"

If gcd(m,n)≠1

Then

Print "m and n are not"

Print "relatively prime."

Stop

IfEnd

(m^2 - n^2) ⇒ a

(2 × m × (n + u × m)) ⇒ b

(m^2 + 2 × u × m × n + n^2) ⇒ c

Print "H-Triple:", ColorMagenta

Print "{a,b,λ}="

Print {a,b,u}, ColorBlue

Print "c="

Print c


Example:

m = 7, n = 3, λ = 2/3


Result:

a = 40, b = 322/3, c = 86


Testing the Theorem of Sós


The program htrist tests the criteria for the triple (a, b, λ). 


Testing numbers in a program to see that they are rational is not as easy as it appears. Thankfully, the functions numerator and denominator can be used on the Classpad.  The numerator function converts the number into an exact fraction and extracts its numerator.  Similarly, the denominator function converts the number into an exact fraction and extracts its denominator.  


For an irrational number such as √2, the Classpad determines the exact fraction to be 

√2/1.


Casio Classpad Program:  htrist

(fx-CP400 and fx-CG500)


'2020-09-15 EWS

'H Triple test

Local a,b,c,n,d,u

Input a

Input b

Input u, "λ? (rational)"

√(a^2 - 2 × u × a × b + b^2) ⇒ c

numerator(c) ⇒ n

denominator(c) ⇒ d

ClrText

Print {n, d}

If frac(n) = 0 and frac(d) = 0

Then

Print "H Triple", ColorGreen

Print {a, b, u}

Print "c ="

Print c

Else 

Print "No Solution", ColorRed

IfEnd


Example:

a = 85, b = 374, λ = 1


Results: 

c = 289,  n = 289, d = 1


Source:


Halbeisen, Lorezn and Hungrebühler, Nobert.  "Heron triangles and their elliptic curves" Journal of Number Theory 213 (2020) 232-253.  https://doi.org/10.1016/j.jnt.2019.12.005 


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. 


Saturday, October 10, 2020

Sines and Cosines: Adding and Subtracting Angles

 Sines and Cosines:   Adding and Subtracting Angles





Note:   


π/2 radians = 90°,   π radians = 180°


Sine


sin(x + π/2) = sin(x) cos(π/2) + cos(x) sin(π/2) = cos(x)


sin(x - π/2) = sin(x) cos(π/2) - cos(x) sin(π/2) = -cos(x)


sin(π/2 - x)  = sin(π/2) cos(x) - cos(π/2) sin(x) = cos(x)


sin(x + π) = sin(x) cos(π) + cos(x) sin(π) = -sin(x)


sin(x - π) = sin(x) cos(π) - cos(x) sin(π) = -sin(x)


sin(π - x)  = sin(π) cos(x) - cos(π) sin(x) = sin(x)


Cosine


cos(x + π/2) = cos(x) cos(π/2) - sin(x) sin(π/2) = -sin(x)


cos(x - π/2) = cos(x) cos(π/2) + sin(x) sin(π/2) = sin(x)


cos(π/2 - x) = cos(π/2) cos(x) + sin(π/2) sin(x) = sin(x)


cos(x + π) = cos(x) cos(π) - sin(x) sin(π) = -cos(x)


cos(x - π) = cos(x) cos(π) + sin(x) sin(π) = -cos(x)


cos(π - x) = cos(π) cos(x) + sin(π) sin(x) = -cos(x)


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. 


Sunday, October 4, 2020

TI-84 Plus CE: Lorenz Curves and the Gini Coefficient

TI-84 Plus CE:  Lorenz Curves and the Gini Coefficient

Introduction - Graphing Income Inequality

Developed by Max O. Lornez, the Lorenz curve displays the graphs of income distribution and income inequality.  Each point of represents a cumulative percentage of an income level.   An example of a Lorenz curve:

(25%, 9%):   The first 25% of a population earns 9% of the population's total income

(50%, 21%):  Half of the population earns only 21% of the total income.

(75%, 44%):  The bottom 75% of the population earns 44% of the total income.

(100%, 100%):  This represents the total population.  

The Lornez curve is compared against a straight line which connects points (0%, 0%) to (100%, 100%).    The ratio between the top area and the whole curve is called a Gini coefficient.  If the Gini coefficient is 0, then there is no income inequality.  On the other hand, the closer that the Gini coefficient is to 1, there is more income inequality.  The diagram below is a Lorenz curve.



Calculating the Gini Coefficient


Let:

A = the area above the Lorenz  curve and below the straight line

B = the area above the x axis and below the Lorenz curve

W = the total area = A + B = 1/2 * max(x value) * max(y value)  

Note: that the total area is the area of a right triangle


The Gini coefficient is defined as:

G = A / (A + B) = (W - B) / B


TI-84 Plus CE Program: LORENZ

430 bytes


"2020-09-13 EWS"

Menu("LORENZ CURVE", "EQUAL PERCENTILE", 1, "DATA", 2)

Lbl 1

Input "DATA?", L4

dim(L4) → N

cumSum(L4) → L6

seq(100J/N, J, 1, N) → L3

L3 → L5

Goto 3

Lbl 2

Disp "ASCENDING ORDER: Y"

Input "X DATA?", L3

Input "Y DATA?", L4

cumSum(L3) / sum(L3) * 100 → L5

sumSum(L3 * L4) / sum(L3 * L4) * 100 → L6

Goto 3

Lbl 3

"BELOW"

augment( {0}, L5 ) → L5

augment( {0}, L6 ) → L6

sum( seq(.5 * (L5(J) - L5(J-1)) * (L6(J) + L6(J-1)) /2 , J, 2, dim(L6) ) ) → B

"WHOLE"

.5 * max(L5) * max(L6) → W

(W - B) / W → G

Disp "GINI INDEX:", G

Pause

Func

PlotsOff

FnOff

FnOn 1

PlotsOn 1

10 → Xscl : 10 → Yscl

Plot1( xyLine, L5, L6, □, RED)

"max(L6)*X/100" → Y1

ZoomStat


There are two options:

1. Equal Percentile:  Enter the percentage of each bin.  The percentile of each class is divided equally. Example:  for ten data points, the percentiles are split in 10% increments.

(10%, y1%)
(20%, y2%)
(30%, y3%)
(40%, y4%)
(50%, y5%)
(60%, y6%)
(70%, y7%)
(80%, y8%)
(90%, y9%)
(100%, y10%)

2.  Data:  Enter x and y data.   For y data, make sure that list has all of its elements in ascending order.

The graph displays in values of percents.  X Axis: 0 to 100 (representing 0% to 100%).  Y Axis: 0 to 100 (representing 0% to 100%).

Examples

Example 1:  Equal Percentile  

The total health spending for high average per capita in 10% percentiles in 2002.  (see source for background information)

Percentile Percent of Health Spending
10% 0%
20% 0.1%
30% 0.6%
40% 1.2%
50% 2%
60% 3.4%
70% 5.4%
80% 9.1%
90% 16.5%
100% 61.7%


Enter Option 1: Data.   

Gini Index: 0.8633

List = { 0, .1, .6, 1.2, 2, 3.4, 5.4, 9.1, 16.5, 61.7 }




Example 2:  Data

Hourly employees of a company and their wages:

Number of Employees Hourly Wage
156 $15.00
195 $30.00
53 $50.00
49 $70.00

X Data:  {156, 195, 53, 49}
Y Data:  {15, 30, 50, 70}

Gini Index:  0.6379627898



Source:

Reindhardt, Uwe E.   "The Construct of Lorenz Curves and of The Gini-Coeficient to Decpict Degrees in Inequality in Health Care"  Princeton University, WWS 597  (Political Economy of Health Systems) 
Retrieved August 26, 2020 


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. 





Saturday, October 3, 2020

TI-84 Plus CE and HP 41C: Method of Successive Substitutions

 TI-84 Plus CE and HP 41C:  Method of Successive Substitutions


Repeating the Calculation Again and Again


With an aid of a scientific calculator, we can solve certain problems of the form:


f(x) = x.


Examples include: 


tan cos sin x = x  


e^-x = x


atan √x = x


sin cos x = x 


(acos x) ^ (1/3) = x


In any case with trigonometric functions, the angle mode will need to be in radians.  You will also need a good guess to get to a solution and to know that at some real number x, f(x) and x intersect.


Take the equation ln(3*x) = x with initial guess x0 = 1.512


Depending on the operating of the scientific calculator the keystrokes would be:


AOS:

1.512 [ = ]

Loop:  [ × ] 3 [ = ] [ ln ]


RPN:

1.512 [ENTER]

Loop:  3 [ × ] [ ln ]


ALG:  

1.512 [ENTER/=]

Loop:  ln( 3 * Ans) [ ENTER/= ]


Repeat the loop as many times as you like and hope you start seeing the answers converge.   After repeating the loop over and over and over again, at six decimal answers, the readout will be about 1.512135.


An approximate answer to ln(3x) = x, x ≈ 1.512134552


 If your calculator has a solve function, you can check the answer, but this method can be useful if your calculator does not have a solve function.


The program SUCCESS illustrates this method.


TI-84 Plus CE Program (TI-83 Family) Program:  SUCCESS

285 bytes


"2020-09-08 EWS"

Disp "SUCCESIVE SUBSTITUTION", "F(X)=X"

Disp "USE QUOTES FOR F(X)"

Input "F(X)? ", Y1

Input "GUESS? ", G

Input "PRECISION? ", P

0 → I

1 → T

Repeat T<10^-P

Y1 → Z

abs(Z - X) → T

Z → X

I + 1 → I

If I > 200

Then

Disp "ITERATIONS EXCEEDED", "NO SOLUTION FOUND"

Stop

End

End

ClrHome

Disp "SOLUTION=",  round(X,P), "ITERATIONS=", I, "ABS DIFF", T


HP 41C/DM41 Program: SUCCESS

This program calls on the subroutine, FX.   FX is where you enter f(x).  End FX with the RTN command.


01 LBL^T SUCCESS

02 ^T F<X>=X

03 AVIEW

04 PSE

05 ^T GUESS?

06 PROMPT

07 STO 00

08 ^T PRECISION?

09 PROMPT

10 STO 02

11 0

12 STO 03

13 1

14 STO 04

15 LBL 01

16 RCL 00

17 XEQ ^FX

18 STO 01

19 RCL 00

20 -

21 ABS

22 STO 04

23 RCL 01

24 STO 00

25 1

26 ST+ 03

27 200

28 RCL 03

29 X>Y?

30 GTO 02

31 RCL 02

32 CHS

33 10↑X

34 RCL 04

35 X>Y?

36 GTO 01

37 ^T SOL=

38 ARCL 01

39 AVIEW

40 STOP

41 ^T ITER=

42 ARCL 03

43 AVIEW

44 STOP

45 ^T DIFF=

46 ARCL 04

47 AVIEW

48 STOP

49 GTO 04

50 LBL 02

51 ^T NO SOL FOUND

52 AVIEW

53 STOP 

54 LBL 04

55 END


Examples for FX:


f(x) = sin cos x.   


Program:

LBL ^FX

RAD

COS 

SIN 

RTN


f(x) = e^-x


Program:

LBL ^FX

CHS

E↑X

RTN


Be aware, some equations cannot be solved in this manner, such as x = π / sin x and x = ln(1 / x^4).

Cheung, Y.L. "Using Scientific Calculators to Demonstrate the Method of Successive Substitutions"  The Mathematics Teacher.  National Council of Teachers of Mathematics.  January 1986, Vol. 79 No. 1 pp. 15-17  http://www.jstor.com/stable/27964746 



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.