Sunday, November 15, 2020

HP 41C and DM41: Operations by Test, Messages, Block Storage

 HP 41C and DM41: Operations by Test, Messages, Block Storage  


The programs are inspired from a great calculator resource, "Calculator Tips & Routines Especially For The HP-41C/41CV", edited by John Dearing (see source below).   


Operations by Test


One of the tips presented is the selection of one of two opposite arithmetic operations based on a comparison between X and Y values.  This tip was provided by Bill Kolb (tip 2-7).  They are:


X?Y

CHS  (subtract if test is true)

+   (add if test is false)


X?Y

1/X  (divide if the test is true)

*  (multiply if the test is false)


X?Y

1/X   (take the root if the test is true)

Y↑X  (take the power if the test is false)


The following programs uses the test X<Y:


TESTAS:  X<Y  (subtract, y - x),  X≥Y (adding, y + x)


(^T represent the beginning of an alpha string)


01 LBL^T TESTAS

02 X<Y?

03 CHS

04 + 

05 END


Example:  

45, 13, XEQ TESTAS returns 32  (45 - 13)

13, 45, XEQ TESTAS returns 58  (13 + 45)


TESTMD:  X<Y  (divide, y/x),  X≥Y (mulitply, y * x)


01 LBL^T TESTMD

02 X<Y?

03 1/X

04 * 

05 END


Example:  

45, 13, XEQ TESTMD returns 3.4615  ( ≈ 45 / 13)

13, 45, XEQ TESTMD returns 585  (13 * 45)


TESTPR:  X<Y  (root, y^1/x),  X≥Y (power, y^x)


01 LBL^T TESTPR

02 X<Y?

03 1/X

04 Y↑X 

05 END


Example:  

49, 3, XEQ TESTPR returns 3.6593  ( ≈ 49 ^ 1/3)

3, 49, XEQ TESTPR returns 2.3930E23  (≈ 3 ^ 49)


Messages


With the use of AVIEW during a loop, you can display a loop up to 12 characters while the loop is running.   A CLD (clear display) is added after the loop's completion to clear the alpha display and show the stack. (tip 2-25)


The program TESTSUM adds a message while the 41C is summing numbers from 1 to X.   While this is not the most efficient way to tackle the problem, this illustrates the use of messages.  


01 LBL^T TESTSUM

02 STO 01

03 0

04 STO 02

05 LBL 01   // loop begins

06 RCL 01

07 ST+ 02

08 ^T ADDING...  // message

09 AVIEW   // display the message

10 DSE 01

11 GTO 01

12 CLD  // clear display

13 RCL 02

14 END


Example:

50, XEQ TESTSUM  

Display: ADDING..., then 1275


Block Storage


You can use indirect storage and the stack to store a constant in a block of consecutive storage registers.  A sample loop:


LBL %%

STO IND Y

ISG Y

GTO %%


Where %% is a label, and the loop variable is B.EEE  (B:  beginning register, E:  ending register) stored in this case, Stack Y.  (tip 10-1)


The program LOADBLK, prompts the user enter the value, beginning register number, and ending register number.


01 LBL^LOADBLK

02 ^T VALUE

03 PROMPT

04 STO Z     // keystrokes:  [ STO ]  [ . ]  ( Y )

05 ^T R%% BGN?

06 PROMPT

07 ^T R%% END?

08 PROMPT

09 1E3

10 /

11 +

12 STO Y  

13 RDN   // R↓

14 X<>Y

15 LBL 01

16 STO IND Y   // keystrokes:  [ STO ] [ shift ] [ . ] ( Y )

17 ^T STORING...    // message

18 AVIEW

19 ISG Y    // keystrokes:  [ shift ] ( ISG ) [ . ] ( Y )

20 GTO 01

21 ^T DONE

22 AVIEW

23 PSE

24 CLD

25 END


Try this:

Store π in R00 to R03 and e^1 in R04 to R07.

 

Results:  (Fix 4)

R00:  3.1416

R01:  3.1416

R02:  3.1416

R03:  3.1416

R04:  2.7183

R05:  2.7183

R06:  2.7183

R07:  2.7183


Source:


Dearing, John.  "Calculator Tips & Routines Especially for the HP-41C/41CV"  Corvallis Software, Inc.   Corvallis, OR.  1981 


Link on HP41.org (account needed):  http://www.hp41.org/LibView.cfm?Command=View&ItemID=320



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, November 14, 2020

HP Prime: The Percent Function

 HP Prime:  The Percent Function


The Percent Function



The HP Prime has three percent functions.   They are not easily found (through the catalog or in program edit mode, Cmds-More menu).  The functions are:


%

%CHANGE

%TOTAL


% Function


%(x, y)  returns x * y /100.  This returns either x% of y or y% of x.  Due to the communicative multiplication property, you can use the arguments in either order.  


%CHANGE


This the percent change function where the arguments are %CHANGE(old, new).  Formula:  %CHANGE(x, y) = (y - x) / x * 100%


%TOTAL


This calculates the % total given a part and a whole.  Syntax:  %TOTAL(whole, part).  Formula:  %TOTAL(x, y) = y / x * 100%


The program POPTOWN uses the percent functions.  It is a simple game where you invite a certain population to live in a town, and the birth (growth) and death rates are determined by random.


HP Prime Prime Program:  POPTOWN


RESULTS(y,n,g,d,p)

BEGIN

// subroutine

PRINT();

PRINT("Year: "+STRING(y));

PRINT("Population: "+STRING(n));

IF y>0 THEN

PRINT("Growth: "+STRING(g)+"%");

PRINT("Death: "+STRING(d)+"%");

PRINT("Δ%: "+%CHANGE(p,n));

END;

WAIT(0);

END;


// main program

EXPORT POPTOWN()

BEGIN

MSGBOX("You start with 10 

residents, inviting up to 50 

new residents each year.  Can 

growth beat death?");

// 2020-10-24 EWS

// Growth and Death

LOCAL n,y,w,g,d,c,p;

LOCAL v; // number of invites

n:=10;

RESULTS(y,n,g,d,p);

// The game

FOR y FROM 1 TO 5 DO

INPUT({{c,{0,10,20,30,40,50}}},

"Year "+STRING(y),"Invite:");

// all invites move in at the

// beginning of each turn

p:=n;

w:=10*(c-1)+n;

v:=10*(c-1)+v;

g:=RANDINT(5,20);

d:=RANDINT(1,25);

n:=w+IP(%(w,g))-IP(%(w,d));

// empty town scenario

IF n≤0 THEN

MSGBOX("No one survived.");

n:=0; 

END;

RESULTS(y,n,g,d,p);

END;

// End the game results

PRINT("Final Results");

PRINT("Population Change: "+

STRING(n-10));

PRINT("Invited: "+STRING(v));

PRINT("Percent Invite: "+

STRING(ROUND(%TOTAL(n,v),2))

+"%");

END;



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, November 7, 2020

HP Prime: Approximate of a Quartic Root

 HP Prime: Approximate of a Quartic Root


Introduction


In the article "Square Root & Cube Root Algorithms" (see source below), teacher and educator Dave  Elgin wrote an article on how his Advanced Higher Applied Mathematics class developed algorithms to estimate the square root and cubic roots of numbers.  The algorithms are first based off of Netwon's Method, then uses selected initial guesses and solving for linear systems.


Elgin's Derivation 


Square Root


Suppose x^2 = k.   To set up for Newton's Method, let f(x) = x^2 - k, with df/dx = 2x.  Then


x_n+1 = x_n - (x_n^2 - k) / (2 * x_n) = 1/2 * (x_n + k / x_n^2)


(The article uses N for the number to find the root of, but to eliminate confusion, I use k.  Completely a choice of labels.)


The class used a pattern to determine guesses for the square root of k:


k / (x_n),  (k^2) / (x_n^3),  (k^3) / (x_n^5), and so on.   


Let g(x) be an iterative function where x_n+1 = g(x_n) and for a second-order approximation:


g(x) = a1 * x + a2 * k / x + a3 * k^2 / x^3


Two derivatives of g(x) are taken:


g'(x) = a1 - a2 * k / x^2 - 3 * a3 * k^2 / x^4, with g'(x_n) = 0


g''(x) = 2 * a2 * k / x^3 + 12 * a3 * k^2 / x^5 with g''(x_n) = 0


This requires the following system of equations to be solved for a1, a2, and a3 (after substituting x = √k):


1 = a1 + a2 + a3

0 = a1 - a2 - 3 * a3

0 = 2 * a2 + 12 * a3


leading to the solutions a1 = 3/8, a2 = 3/4, and a3 = -1/8


Hence the second-order recursive function for the square root is (after simplifying):


g(x) = 3/8 * x + (3 * k) / (4 * x) -  k^2 / (8 * x^3)


which translates to 


x_n+1 = 3/8 * x_n + (3 * k) / (4 * x_n) -  k^2 / (8 * x_n^3)


Cube Root


They repeat the same process for the cubic root, which I will briefly outline here:


x^3 = k,   f(x) = x^3 - k,  f'(x) = 3x^2


x_n+1 = x_n - (x^3 - k) / (3x^2) = 1/3 * (2 * x_n - k / (x_n^2))


With guess of k / (x_n^2) and k^2 / (x_n^5) used, the iterative function is set up as:


g(x) = a1 * x + a2 * k / x^2 + a3 * k^2 / x^5


and


g'(x) = a1 - 2 * a2 * k / x^3 - 5 * a3 * k^2 / x^6


g''(x) = 6 * a2 * k / x^4 + 30 * a3 * k^2 / x^7


and with g(x_n) = x_n+1, g'(x_n) = 0, g''(x_n) = 0 and substituting x = k^1/3, the system becomes:


1 = a1 + a2 + a3

0 = a1 - 2 * a2 - 5 * a3

0 = 6 * a2 + 30 * a3


with the solutions a1 = 5/9, a2 = 5/9, and a3 = -1/9, giving the second-order recursive function:


g(x) = 5/9 * x + (5 * k) / (9 * x^2) - k^2 / (9 * x^5)


The article shows the derivation of a third-order recursive function for both square and cube root. 


Deriving a Second-Order Algorithm for Quartic Roots


Let's use a similar approach used in Elgin's article to develop an algorithm to calculate the fourth (quartic) root:  


k^1/4 = x


Let f(x) = x^4 - k,  then f'(x) = 4*x^3, and


x_n+1 = x_n - (x_n^4 - k) / (4 * x_n^3) = 3/4 * x_n - k / (4 * x_n^3)


Use guesses x_n, k / (x_n^3), k^2 / (x_n^7), we set up the equations:


g(x) = a1 * x + a2 * k / x^3 + a3 * k^2 / x^7


g'(x) = a1 - 3 * a2 * k / x^4 - 7 * a3 * k^2 / x^8


g''(x) = 12 * a2 * k / x^5 + 56 * a3 * k^2 / x^9



Setting g(x) = x^1/4, g'(x) = 0, g''(x) = 0, and setting g(k^1/4), we get the system:


1 = a1 + a2 + a3

0 = a1 - 3 * a2 - 7 * a3

0 = 12 * a2 + 56 * a3


The solutions to above system:  a1 = 21/32, a2 = 7/16, a3 = -3/32, which gives the second order recursive  equation:


g(x) = 21/32 * x + (7 * k) / (32 * x^3) - (3 * k) / (32 * x^7)

 

The program FTHROOT use the recursive equation to approximate the quartic root. 



HP Prime Program:  FTHROOT


EXPORT FTHROOT(k)

BEGIN

// EWS 2020-10-21

// Approx 4th Root

LOCAL r,r0,r1,ri;

r:=k^0.25;

r0:=0; 

r1:=√k;

ri:=0;

WHILE ABS(r0-r1)>1ᴇ−10 DO

ri:=ri+1;

r0:=r1;

r1:=(21*r0)/32+(7*k)/(16*r0^3)-(3*k^2)/(32*r0^7);

END;

PRINT();

PRINT("4√"+PRINT(k));

PRINT("Root = "+STRING(r));

PRINT("------");

PRINT("Approximation: "+

STRING(r1));

PRINT("Iterations: "+STRING(ri));


END;


The choice of a good first guess is necessary with any iterative root finding process. The program FTHROOT chooses the square root of k for an initial guess.   The goal is to seek a positive root.


Examples


Each example is followed by a set of screen shots, which include setting up Sequences and their graphs on the HP Prime.  


Example 1


k = 176.4

Result:  3.64438831256 (algorithm took 7 iterations with initial guess √176.4)



Example 2

k = 5525
Result:  8.62150472576 (algorithm took 9 iterations with initial guess √5525)




Source

Elgin, Dave.  "Square Root & Cube Root Algorithms"  The Mathematical Association.  Mathematics in School, Jan. 2006, Vol. 35, No. 1 pp. 30-31.  https://www.jstor.org/stable/30215863

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, November 1, 2020

Book Review: Calculus for Middle Schoolers by Serena Swegle

 Book Review: Calculus for Middle Schoolers by Serena Swegle


Just The Facts


Calculus for Middle Schoolers


Author:  Serena Swegle


Publisher:  Sunhut Publishing


Cost:  $26.50 for Paperback, $9.99 for Kindle (as of 10/23/2020)


Link:  https://www.amazon.com/Calculus-Middle-Schoolers-Serena-Swegle/dp/057871275X/ref=sr_1_3?dchild=1&keywords=Calculus+for+Middle+Schoolers&qid=1603471676&sr=8-3


Topics Covered


The number e (2.718281828...)


The common logarithm  (base 10)


The natural logarithm (base e)


Trig Functions (sine, cosine, tangent)


Sums 


Limits


Derivative - the derivative of a polynomial


Integral - the integral of a polynomial


The Derivative and Integral of e^x


An Introduction to Calculus 


The target audience is middle school students.  However, book serves as a great introduction to calculus for high school and college students who are taking calculus for the first time.  The book gives a simple, concrete introduction to various subjects, in an easy-to-read narrative.  Calculus is a complex subject, and this book allows readers, who may be intimidated about the subject, to develop a understanding.   


I would recommend this book to be read prior to the student's first calculus class.   The book can be read in one or two days, but I feel it was meant to read as one chapter a time per day or week.   


Verdict


Swegle's book is well written, in a concise language.  The chapter covers one concept at the time, which serves as a great introduction to a rich subject.   The examples are simple and apply closely to the text.   I wish Swegle put a summary of all the topics covered at the end of the book as a wrap up.  Otherwise, I recommend this book for educators and parents.   For those who have the Kindle app, $9.99 is a good price point.  Recommended.


Thank you, Serena for recommending this book for me to review.  


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 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. 


Classic RPN Stack Operations

  Classic RPN Stack Operations Starting Stack: T:  d Z:  c Y:  b X:  a OVER :   Copies b to the Z and X stacks, while leaving ...