Sunday, December 20, 2020

Review: Swiss Micros DM41X

 Review: Swiss Micros DM41X






General Information


Company:  SwissMicros, https://www.swissmicros.com

Type:  Programmable Scientific

Memory:  319 registers (at default) - calculator; 32 MB external flash

Battery:  CR 2032

Date:  September 2020 - current

Cost:  229 CHF, about $257.34 according to currency converter on December 12, 2020 (https://www.xe.com/currencyconverter/convert/?Amount=229&From=CHF&To=USD)

Current Software Version:  2.1 (November 13, 2020)

Case Included?  Yes


The DM41X is a long waited calculator, and joins the DM 41L and DM41 family.  The family runs HP-41CX firmware, including a clock, time, and date functions.    On February 23, 2018, I reviewed the DM 41L which you can see here:


http://edspi31415.blogspot.com/2018/02/review-swissmicros-dm41l.html


I am going to address the features that are specific to the DM41X, which is added to all the great features of the DM41 and DM41L.  


A Return to the Original Layout





The DM41X's keyboard is in a portrait design, like the original Hewlett Packard HP-41C family (HP-41C, HP-41CV, HP-41CX)


Instead of the row of ON, USER, PRGM, and ALPHA keys on the top row, the DM41X adds a column of keys to the right of the main keyboard:


ON/CLK:  ON/OFF button, the shifted CLK displays the current time


USR/SETUP:  The user keyboard.  SETUP shows the DM41X's system menu where stve states and RAW progams can be saved, USB communication can be activated, modules can be saved and loaded, system settings can be changed, and accessing the About screen.


Blue Key:  This is the ALPHA key


Backspace Key


Up Arrow: for program scrolling and debugging


Down Arrow: for program scrolling and debugging


PRG/SIZE:  The PRGM button.  The shifted function allows the user set the number of registers to be set for numerical constants.


R/S/VIEW:  Run/Stop Key, View prompts for a view of a register's value without affecting the stack.


The Big Screen


The DM41X has three screen settings that is set by the DSP key:


1.  All four stacks, T, Z, Y, and X are displayed.  This is my preferred display. 


2.  The X stack and the Alpha Register are displayed.  On the top of the screen:  alarms, the number of storage registers designated for numerical constants, free memory, the current program loaded and it's pointer location.  


3.  Two stacks, Y and X are displayed. On the top of the screen:  alarms, the number of storage registers designated for numerical constants, free memory, the current program loaded and it's pointer location.  


Connectivity


The DM41X's connectivity interface is in line with the DM42's connectivity interface.  Simply plug the DM41X with a USB-Micro B port, then on the calculator press [shift], [USR] (SETUP), 1 for File, 5 for Activate USB Disk.  The DM41X now acts as a USB storage device like a smart phone.  


You can take screenshots by pressing and holding [SHIFT] and [DSP].  Screen shots are saved as .bmp files under the disk's SCREEN folder.


Black and white images of 400 x 240 pixels, 1 bit depth, .bmp format, can be saved to the disk's OFFIMG folder.  Every picture in the folder will be shown on a rotated basis every time the calculator is turned off.  


Custom Menu


Pressing the CST key will give you access to a custom menu 16 available slots for commands and programs.  CST also gives access to Help, ROM Map, and USB Disk activation.  To learn about how to set up the custom menu, click here:  https://edspi31415.blogspot.com/2020/10/swiss-micros-dm41x-custom-menus.html.


Programming


The DM41X operates like the HP-41CX in its programming language except the DM41X has a lot more room for ROM modules.


Verdict


Like the DM41L, the DM41X is a winner.  The keys feel good, I love seeing all four stack levels on the screen, and I am fan of the custom menu built into the DM41X.  This is definitely worth a purchase.


If the price tag of DM41X is too high, consider the DM41 or DM41L.  They may not have a four line display or a custom menu, but the high-quality calculator software and firmware is still present.  Currently only the DM41L is in stock from Swiss Micros, at CHF 129.  


- - - - - -


Announcement


This is the last post for 2020.  I want to wish everyone Merry Christmas, Happy Holidays, and Happy New Year.  2020 has been a brutal year in every respect.  May 2021 be free from disease, war, economic, social, and spiritual struggle; and be full of joy, health, and happiness.  Thank you to my blog's followers and readers; I appreciate all of you!  Take care, and the next schedule blog will be on January 2, 2021.  


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, December 19, 2020

Sum of Increasing Series

 Sum of Increasing Series


The Sum From 1 to N - Increasing by 1


It is well known that sum from 1 to N, which each term increasing by 1 is:


1 + 2 + 3 + 4 + ... + N = ∑ x from x = 1 to N = (N + 1) * N / 2


The derivation is fairly easy.  Let S be the sum:


S = 1 + 2 + 3 + ... + N-1 + N


Add S to both sides:


2 * S = 1 + 2 + 3 + ... + N-1 + N + 1 + 2 + 3 ... + N-1 + N


Thanks to the commutative property of addition, we can arrange terms, and with a clever and creative way of arranging terms:


2 * S = ( 1 + N ) + ( 2 + N - 1 ) + ( 3 + N - 2 ) + ... + ( N - 1 + 2 ) + ( N + 1 )


Note that:


2 * S = 

1   +    2   +   3   + ... +  N-1  + N +

N  +  N-1 + N-2  + ..  +   2   +  1


Written this way, there are N "pairs".  Hence:


2 * S = ( 1 + N ) + ( N + 1 ) + ( N +1 ) + ... + ( N + 1 ) + ( N + 1 )


2 * S = ( N + 1 ) * N


Solving for S:


S =  ( N + 1 ) * N / 2


The Sum From 1 to N - Increasing by 2


Now lets consider the sum:


1 + 3 + 5 + 7 + ...


Fun fact: Adding odd numbers in this fashion will always total perfect squares.


1 + 3 = 4 = 2^2

1 + 3 + 5 = 9 = 3^2

1 + 3 + 5 + 7  = 16 = 4^2

1 + 3 + 5 + 7 + 9  = 25 = 5^2

... and so on


Let's define S as the sum:


S = 1 + 3 + 5 + ... + N-4 + N-2 + N


Note that

1 = 2 * 0 + 1

3 = 2 * 1 + 1

5 = 2 * 2 + 1

and so on...


For integer q,

N = 2 * q + 1


Then:


S = 1 + 3 + 5 + ... + ( 2*(q-2) + 1 ) + ( 2*(q-1) + 1) + ( 2*q + 1 )


Using the same strategy as last time:


2 * S = 1 + 3 + 5 + ... + ( 2*(q-2) + 1 ) + ( 2*(q-1) + 1) + ( 2*q + 1 ) 

           + 1 + 3 + 5 + ... + ( 2*(q-2) + 1 ) + ( 2*(q-1) + 1) + ( 2*q + 1 )


2 * S =

     1         +          3            +         5            + ... + (2*(q-2) + 1) + (2*(q-1) + 1) +   (2*q + 1) +

(2*q + 1) + (2*(q-1) + 1)  + (2*(q-2) + 1) +  ... +             5        +            3        +     1


Combine each pair as such:


2  * S = (2*q + 2) + (2*q + 2) + (2*q + 2) + ... + (2*q + 2) + (2*q + 2) + (2*q + 2)


Since q starts at q = 0, there are q+1 "pairs".  


2 * S = (q + 1) * (2*q + 2)


S = (q + 1) * (2*q + 2) / 2


To show that the sum is a perfect square:


S = (q + 1) * (2*q + 2) / 2


= (2*q^2 + 2*q  + 2*q + 2) / 2


= (2*q^2 + 4*q + 2) / 2


= (q^2 + 2*q + 1)


= (q + 1)^2


Example:


Calculate 7^2 (albeit the "longer" way):


7 = q+1;  q = 6:


S = (6 + 1) * (2*6 + 2) / 2 = 7 * 14 / 2 = 7 * 7 = 49


The Sum From 1 to N - Increasing by 3


Now add the series:


S = 1 + 4 + 7 + 10 + ... + N - 3 + N


where each term increases by 3.  Letting q be a positive integer and noting that


1 = 3*0 + 1

4 = 3*1 + 1

7 = 3*2 + 1

10 = 3*3 + 1

and so on...


Then:


S = (3*0 + 1) + (3*1 + 1) + (3*2 + 1) + .... + (3(q-1) + 1) + (3q + 1)


2* S 

= (3*0 + 1) + (3*1 + 1) + (3*2 + 1) + ... + (3(q-1) + 1) + (3q + 1) 

+ (3*0 + 1) + (3*1 + 1) + (3*2 + 1) + ... + (3(q-1) + 1) + (3q + 1)


2 * S 

= (3*0 + 1) + (3*1 + 1)     + (3*2 + 1)     + ... + (3(q-1) + 1) + (3q + 1) 

+ (3*q + 1) + (3(q-1) + 1) +(3(q-2) + 1) + ...  +  (3*1 + 1)    + (3*0 + 1)


There are q+1 pairs.


2 * S 

= (3*q + 2)  + (3*q + 2) + (3*q + 2) + ... + (3*q + 2) + (3*q + 2)


2 *S = (q + 1) * (3*q + 2)


S = (q + 1) * (3*q + 2) / 2


Example:


q = 5  (terms from 0 to 5)


S = (5 + 1) * (3*5 + 2) / 2 = 6 * 17 / 2 = 51


1 + 4 + 7 + 10 + 13 + 16 = 51 


The Sum From A for q terms, increasing by D


Let A ≥ 0, D > 0 and q be a positive integer, and A is a starting term, let the sum S be:


S = A + (A + D) + (A + 2*D) + (A + 3*D) + ... + (A + (q-2)*D) + (A + (q-1)*D) + (A + q*D)


Since we start at q = 0, there are q+1 terms.


2*S =

A + (A + D) + (A + 2*D) + (A + 3*D) + ... + (A + (q-2)*D) + (A + (q-1)*D) + (A + q*D) +

A + (A + D) + (A + 2*D) + (A + 3*D) + ... + (A + (q-2)*D) + (A + (q-1)*D) + (A + q*D)


2*S = 

A + (A + D) + (A + 2*D) + ... + (A + (q-2)*D) + (A + (q-1)*D) + (A + q*D) +

(A + q*D) + (A + (q-1)*D) + (A + (q-2)*D) + ... + (A + 2*D) + (A + D) + A


2*S = (2*A + q*D) + (2*A + q*D) + (2*A + q*D) + ... + (2*A + q*D) + (2*A + q*D) + (2*A + q*D) 


2*S = (q + 1) * (2*A + q*D)


S = (q + 1) * (2*A + q*D) / 2


Example:


A = 10, D = 7; q = 4  (5 terms, increase by 7, initial term is 10)


(4 + 1) * (2*10 + 4*7) / 2 = 5 * (20 + 28) / 2 = 120


Note:  10 + 17 + 24 + 31 + 38  = 120


Source:


Knott, Dr. Ron "Proving that 1+2+3+...+n is n(n+1)/2"  February 12, 2003.  Accessed December 6, 2020.  http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/runsums/triNbProof.html


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, December 13, 2020

Numworks and DM42: Lucas-Lehmer Primality Test

 Numworks and DM42: Lucas-Lehmer Primality Test


Introduction


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


s_i+1 = s_i^2 - 2


with the initial value s_0 = 4.


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


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


Numworks Python Script:  llt.py


from math import *

# Lucas-Lehmer Test

# 2020-12-06 EWS

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

s=4

m=2**p-1

for i in range(p-2):

  # repeat p-2 times

  s=(s*s-2)%m

print("Mersenne Number:")

print(m)

if s==0:

  print("Prime")

else:

  print("Not Prime")


HP 42S/DM42 Program LLT


00 {66-Byte Prgm}

01 LBL "LLT"

02 "P (>2)?"

03  PROMPT

04  STO 01

05  ENTER

06  2

07  X<>Y

08  Y↑X

09  1

10  -

11 STO 04

12 R↓

13 2

14 -

15 STO 02

16 4

17 STO 03

18 LBL 00

19 RCL 03

20 X↑2

21 2

22 -

23 RCL 04

24 MOD

25 STO 03

26 DSE 02

27 GTO 00

28 RCL 04

29 "M= "

30 ARCL ST X

31 AVIEW

32 STOP

33 RCL 03

34 X=0?

35 "PRIME"

36 X=0?

37 AVIEW

38 END


Registers


R01: p

R02: p - 2

R03: s

R04:  m = 2^p - 1


Examples


p = 3

m = 7

Prime


p = 4 

m = 15

Not Prime


p = 5 

m = 31

Not Prime


p = 15

m = 32767

Not Prime


p = 20

m = 1048575

Not Prime


Source:


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


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

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


Eddie


Saturday, December 12, 2020

DM41 and DM42: Self Timing Programs

 DM41 and DM42: Self Timing Programs


Timing a Program's Performance


The Swiss Micros calculators DM41 (including the DM41L, DM41X, Hewlett Packard HP 41CX, HP41C with a Time Module installed) and DM42 have an internal clock which allows us to set the date and time on the calculator.  With the use of the TIME function we can determine the how long a program takes to execute.


One structure that can be used:


[ preliminary storage]

TIME

HR (DM 41), →HR (DM 42)

STO Rxx  (register xx)

[ loop/main program starts here ]

TIME

HR (DM 41), →HR (DM 42)

RCL Rxx

-

ABS 

3600

*


The routine TIME, HR, RCL xx, -, ABS, 3600, * determines the amount of time in term of seconds.  


DM42S:  Accessing the TIME function:  [SHIFT], [ + ] (CATALOG), [down arrow], ( TIME )  ("F1")


Let's demonstrate this technique on three examples.  The time record is the calculator ran on batteries.  


Example 1:  40th Fibonacci Numbers 


Registers:  

R01:  counter

R02:  sum

R03:  time

(counter of 39 is set because the first Fibonacci number is loaded at the beginning)


DM41 Program TFIB


01  LBL ^T TFIB

02  39

03  STO 01

04  0

05  STO 02

06  TIME

07  HR

08  STO 03

09  1

10  0

11  +

12  LBL 00

13  LASTX

14  X<>Y

15  +

16  DSE 01

17  GTO 00

18  TIME

19  HR

20  RCL 03

21  -

22  ABS

23  3600

24  *

25  STO 03

26  END


Y:  Results:  102334155.0

X: Seconds:  0.5100


DM42 Program TFIB


00  {45-Byte Prgm}

01  LBL "TFIB"

02  39

03  STO 01

04  0

05  STO 02

06  TIME

07  →HR

08  STO 03

09  1

10  0

11  +

12  LBL 00

13  LASTX

14  X<>Y

15  +

16  DSE 01

17  GTO 00

18  TIME

19  →HR

20  RCL 03

21  -

22  ABS

23  3600

24  ×

25  STO 03

26  END


Y:  Results:  102334155.0

X: Seconds:  0.0200


Example 2:  The Sum of Cubes Using a Loop from 1 to 250


Registers:  

R01:  counter

R02:  sum

R03:  time


DM41 Program TSUM


01  LBL ^T TSUM

02  250

03  STO 01

04  0

05  STO 02

06  TIME

07  HR

08  STO 03

09  LBL 00

10  RCL 01

11  3

12  Y↑X

13  ST+ 02

14  DSE 01

15  GTO 00

16  RCL 02

17  TIME

18  HR

19  RCL 03

20  -

21  ABS

22  3600

23  *

24  STO 03

25  END


Y:  Results:  984390625.0

X: Seconds:  12.07


DM42 Program TSUM


00  {45-Byte Prgm}

01  LBL "TSUM"

02  250

03  STO 01

04  0

05  STO 02

06  TIME

07  →HR

08  STO 03

09  LBL 00

10  RCL 01

11  3

12  Y↑X

13  STO+ 02

14  DSE 01

15  GTO 00

16  RCL 02

17  TIME

18  →HR

19  RCL 03

20  -

21  ABS

22  3600

23  ×

24  STO 03

25  END


Y:  Results:  984390625.0

X: Seconds:  0.24


Example 3:  Savage Test


Let A = 1, then for 2499 loops:

A = tan(atan(exp(ln(sqrt(A^2))))) + 1   (radians mode is used)


Registers:  

R01:  counter

R02:  sum

R03:  time


DM41 Program SVGE


01  LBL ^T SVGE

02  2499

03  STO 01

04  1

05  STO 02

06  TIME

07  HR

08  STO 03

09  LBL 00

10  RCL 02

11  X↑2

12  SQRT

13  LN

14  E↑X

15  ATAN

16  TAN

17  1

18  +

19  STO 02

20  DSE 01

21  GTO 00

22  RCL 02

23  TIME

24  HR

25  RCL 03

26  -

27  ABS

28  3600

29  *

30  STO 03

31  END


Y:  Results:  2499.970322

X: Seconds:  246.4500240  (about 4 minutes, 6.45 seconds)


DM42 Program SVGE


00  {51-Byte Prgm}

01  LBL "SVGE"

02  2499

03  STO 01

04  1

05  STO 02

06  TIME

07  →HR

08  STO 03

09  LBL 00

10  RCL 02

11  X↑2

12  SQRT

13  LN

14  E↑X

15  ATAN

16  TAN

17  1

18  +

19  STO 02

20  DSE 01

21  GTO 00

22  RCL 02

23  TIME

24  →HR

25  RCL 03

26  -

27  ABS

28  3600

29  ×

30  STO 03

31  END


Y:  Results:  2500  (just over 2500)

X: Seconds:  13.24


Source:


Burkett, John.  "The Savage Benchmark"  TI-89 / TI-92 Plus Tip List 10.0   July 20, 2002.  http://www.technicalc.org/tiplist/en/files/pdf/tips/tip6_50.pdf   Retrieved November 28, 2020 


Eddie 


Sunday, December 6, 2020

Calculus of the Sinc Function

Calculus of the Sinc Function


Introduction and Setup


The unnormalized Sinc function is defined as:


unsinc(x) = sin x / x


And the normalized Sinc function is defined as:


sinc(x) = sin( π x ) / ( π x )


Two things to assume about the sinc function:


1.  The function is not defined at x = 0, and


2.  The function uses radian angle measure.  


(x ≠ 0, and assume radians measure)



Let α be a real constant and define f(x) as:


f(x) = sin( α x ) / (α x)


When α = 1, f(x) becomes unsinc(x).  Likewise, when α = Ï€, f(x) becomes sinc(x).  I am going to analyze this function f(x).


Limit


Limit of sin( α x ) / ( α x )


lim x → 0 ( sin( α x ) / ( α x ) ) → sin 0 / 0 → 0 / 0


This form of improper limit allows us to use L'Hôspital's Rule, which allows us to take the derivative of both the numerator function and denominator function:


lim x → 0 ( α * cos ( α x ) / α ) → lim x → 0 ( cos ( α x ) ) →  cos ( 0 ) → 1


Hence  lim x → 0 ( sin( α x ) / ( α x ) ) → 1


Derivative


Taking the derivative will call for use to use the quotient rule:


d/dx [n(x) / d(x)] = ( n '(x) * d(x) - n(x) * d '(x)) / (d^2(x))


Then:


d/dx [ sin( α x ) / ( α x ) ]:


n(x) = sin ( α x )

n'(x) = α * cos( α x )

d(x) = α * x 

d^2(x) = (α * x)^2

d'(x) = α



d/dx [ sin( α x ) / ( α x ) ]

= [ α * cos( α x ) * α * x - sin( α x ) * α ] / [ α^2 * x^2 ]

= [ α^2 * cos( α x ) * x - sin( α x ) * α ] / [ α^2 * x^2 ]

= [ α * cos( α x ) * x - sin( α x ) ] / [ α * x^2 ]

= cos( α x ) / x^2 - sin( α x ) / (α * x^2)


Integral


The integral of 


∫ sin( α x ) / ( α x ) dx


does not look like it can easily integrated.


Let's use the Taylor Series approach:


sin x = x - x^3 / 3! + x^5 / 5! - x^7 / 7! + x^9 / 9! + . . . 


sin( α x ) =  ( α x ) - ( α x )^3 / 3! + ( α x )^5 / 5! - ( α x )^7 / 7! + ( α x )^9 / 9! + ...


With x≠0


sin( α x ) / ( α x ) 

=  1 - ( α x )^2 / 3! + ( α x )^4 / 5! - ( α x )^6 / 7! + ( α x )^8 / 9! + ...

=  1 -  α^2 * x^2 / 3! + α^4 * x^4 / 5! - α^6 * x^6 / 7! + α^8 * x^8 / 9! + ...



Now integrate the series:


∫ sin( α x ) / ( α x ) dx

=  x - ( α^2 * x^3 ) / (3 * 3!) + ( α^4 * x^5 ) / (5 * 5!) - ( α^6 * x^7 ) / (7 * 7!) +  ( α^8 * x^9 ) / (9 * 9!) + ... + C

 =  x - ( α^2 * x^3 ) / 18 + ( α^4 * x^5 ) / 600 - ( α^6 * x^7 ) / 35280 +  ( α^8 * x^9 ) / 3265920 + ... + C


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, December 5, 2020

HP 71B: Sign "Graph" of Trig Functions

 HP 71B: Sign "Graph" of Trig Functions


Introduction


The program SGNTRIG builds a 22 character binary string that depends on the function:


g(x) = 

1  if  sgn(t(x/c)) > 1

0  if  sgn(t(x/c)) ≤ 0


where:


c is a scaling factor, 


sgn(x) is the sign function,  and


t(x) represents one of three trigonometric functions, sin(x), cos(x), or tan(x).   Angles are assumed to be radians.


If we set to scale to c = 1, then g(x) takes the integer values from 1 to 22.  


The HP 71B builds the result to the string S$.   This is an aid to visualize at least some of the graph.   When the bit is 1, the graph is above the x-axis, otherwise, the graph is either on or below the x-axis.  The program presented can be expanded or modified to explore other functions.


The resulting string is a "psuedo-graph".  


Below is a graphical representation of g(x) (an HP Prime is used to graph g(x)).


HP 71B Program SGNTRIG

Size:  270 bytes


100 DESTROY S,I,N,E,C

105 S$=""

110 RADIANS

115 INPUT 'SCALE? ';C

120 DISP "S:SIN C:COS T:TAN"

125 E$=KEY$

130 IF E$="S" OR E$="C" OR E$="T" THEN 200 ELSE 120


200 FOR I=1 TO 22

205 IF E$="S" THEN N=SGN(SIN(I/C))

210 IF E$="C" THEN N=SGN(COS(I/C))

215 IF E$="T" THEN N=SGN(TAN(I/C))

220 IF N=1 THEN N=1 ELSE N=0

225 S$=S$&STR$(N)

230 DISP S$ @ BEEP 589,0.1 @ WAIT 0.2

235 NEXT I

240 DISP S$ @ BEEP 661,2


Notes:


Line 105:  creates a blank string, which is allowed on the HP 71B


Line 125:  The KEY$ function calls for a key input. S for sine, C for cosine, and T for tangent.


Lines 205 to 215: determine which trigonometric function to use


Line 220:  Sets the character to 0 if the sign function returns 0 or -1


Line 225:  &, the ampersand symbol concatenates two strings


Lines 230 and 240, respectively:  589 Hz is middle D, 661 Hz is middle E


Example


Below are results for each of the trigonometric functions when scale is set to 1.  




YouTube video: https://www.youtube.com/watch?v=GL6urOGvRGY&feature=youtu.be

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

HP Prime: Linear Exponential Combination Fit

 HP Prime:  Linear Exponential Combination Fit


The program LINEXPREG attempts to fit bivariate data to the curve:


y = a + b * x + c * e^x


The LSQ (least square) function is used.  The output is a list of three matrices:



*  A matrix of coefficients:  [ [ a ] [ b ] [ c ] ] 


*  A matrix of y values entered


*  A matrix of predicted y values



HP Prime Program LINEXPREG


EXPORT LINEXPREG(lx,ly)

BEGIN

// 2020-11-17 EWS

// x list, y list

LOCAL n,lx2,lx3,mx,my,k,mr,mq;

n:=SIZE(lx);

lx2:=e^(lx);

lx3:={};

FOR k FROM 1 TO n DO

lx3:=CONCAT(lx3,{1,lx(k),lx2(k)});

END;

mx:=list2mat(lx3,3);

my:=list2mat(ly,1);

mq:=LSQ(mx,my);

mr:=mq(1,1)+mq(2,1)*lx+

mq(3,1)*e^(lx);

mr:=list2mat(mr,1);

RETURN {mq,my,mr};

END;


Example





x list:  {0, 1, 2, 3, 4, 5}

y list:  {2, 7, 13, 18, 26, 34}


LINEXPREG({0, 1, 2, 3, 4, 5},{2, 7, 13, 18, 26, 34})


Results:  {coefficients, y values, predicted y values}


coefficients:

[ [ 1.74935499143 ]

[ 5.39455446221 ]

[ 3.66584105034E-2 ] ] 


y values:

[ [ 2 ]

[ 7 ]

[ 13 ]

[ 18 ]

[ 26 ]

[ 34 ] ]


predicted y values:

[ [  1.78601340193 ]

[ 7.24355734477 ]

[ 12.8093349675 ]

[ 18.6693222357 ]

[ 25.3290542368 ]

[ 34.1627178129 ] ] 


Equation:

y = 1.74935499143 + 5.39455446221 * x + 3.66584105034E-2 * e^x


On to the last month of 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, November 28, 2020

Review: Ativa 2-Line Calculator DD-2361

 Review:  Ativa 2-Line Calculator DD-2361


Just the Facts:


Model:  DD-2361 (I was stated in the manual)

Company: Ativa (Office Depot)

Type: Four Function

Battery:  Solar with backup battery LR1130

Logic: Algebraic

Memory Registers: None

Price:  $8.99





A Two Line Screen

The Ativa DD-2361 calculator has a two lines: the top line shows the entered expression.  Each calculation can have up to 79 characters.   The bottom line shows answers, which can have up to 12 characters.  

Functions include the percent function which, works like four function calculators.  

Example:  

Top:  7 x 8 - 2 x 9

Bottom:  38


The order of operations are used.  


The keys on the keyboard are huge and responsive.  Expressions can be edited using left and right arrow keys.  Characters are replaced in editing.  


Verdict


I like the big keys.  The DD-2361 does lack a few key features: square root, an independent memory register, and due to the calculator following the order of operations, parenthesis.  This is one of few two-line four-function calculators where you can buy it a store, and not just online.  


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

Heron's Formula vs Area by Vertices

Heron's Formula vs Area by Vertices

There are several ways to determine the area of a triangle.

Heron's Formula:

With side lengths A, B, and C, the area is:

Area = √( S * (S - A) * (S - B) * (S - C) ) 

where S = (A + B + C) / 2

Area of Vertices:

With vertices (x1, y1), (x2, y2), and (x3, y3), the area is:

Area = 1/2 * abs( (x1 - x2) * (y1 + y2) + (x2 - x3) * (y2 + y3) + (x3 - x1) * (y3 + y1) )

Testing The Data






I ran a test of 50 randomly selected sets of three points that form the triangle.  The three points are:
*  The origin: (0,0)
*  The second point has 0 ≤ x ≤ 20 and -20 ≤ y ≤ 20, x and y are integers
*  The third point has 0 ≤ x ≤ 20 and 0 ≤ y ≤ 20, x and y are integers

I used the Casio fx-9750gIII Spreadsheet application.    

Casio Spreadsheet Set Up

Column Titles - Row 1:

Column A:  "X1"   x coordinate of point 1
Column B:  "Y1"   y coordinate of point 1
Column C:  "X2"   x coordinate of point 2. 
Column D:  "Y2"  y coordinate of point 2
Column E:  "X3"  x coordinate of point 3
Column F:  "Y3"  y coordinate of point 3
Column G:  "XY1"  distance between points 1 and 2
Column H:  "XY2"  distance between points 2 and 3
Column I:  "XY3"  distance between 3 and 1
Column J:  "S"   semi-perimeter of the triangle
Column K:  "HERON"  Area by Heron's Formula
Column L: "VERT"  Area by Vertices 
Column M:  "DIFF"  Difference between two calculation methods

Formulas for Rows 2 through 51

Column A:  A2 = Fill(0,50)
Column B:  B2 =Fill(0,50)
Column C:  C2 =Seq(Int(22 Ran#) - 1,X,1,50,1)
Column D:  D2 =Seq(Int(41 Ran#) - 21,X,1,50,1)
Column E:  E2 =Seq(Int(22 Ran#) - 1,X,1,50,1)
Column F:  F2 =Seq(Int(22 Ran#)-1, X,1,50,1)
Column G:  G2 Fill:  =√(C2^2 + D2^2) for range G2:G51*
Column H:  H2 Fill:  =√((C2-E2)^2 + (D2-F2)^2) for range H2:H51
Column I:  I2 Fill:  =√(E2^2 + F2^2) for range I2:I51*
Column J: J2  Fill:  =(G2 + H2 + I2) ÷ 2 for range J2:J51
Column K:  K2 Fill =√(J2 (J2 - G2) (J2 - H2) (J2 - I2) ) for range K2:K51
Column L:  L2 Fill =0.5 × Abs( (A2 - C2)(B2 + D2) + (C2 - E2)(D2 + F2) 
+ (E2 - A2)(F2 + B2)) for range L2: L51
Column M:  M2  Fill =K2-L2

 * To take advantage that the first point is (0, 0).  The full distance formula would be needed otherwise.  

This spreadsheet implies that there is no "rounding" the middle results.  


If you want to download the spreadsheet results, click here:


The zip file contains two images, a csv file, and a Casio spreadsheet file that can be ran on Casio calculators with a spreadsheet application. 

Of the sample taken, the areas determined by Heron's Formula and Area by Vertices are substantially equal; any difference is the order of 10^-12.

Happy Thanksgiving,

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

Numworks: 3 x 3 Matrices

 Numworks:   3 x 3 Matrices


The script invthree.py calculates the inverse and determinant of a 3 x 3 matrix.  


Matrices:


[[ a1,  a2,  a3 ]

[ b1, b2, b3 ]

[ c1, c2, c3 ]]



Numworks script invthree.py:

(701 bytes)


from math import *


# 2020-11-12 EWS

print("3x3 Matrix Inverse")

print("[[a1,a2,a3]")

print("[b1,b2,b3]")

print("[c1,c2,c3]]")

a1=float(input('a1: '))

a2=float(input('a2: '))

a3=float(input('a3: '))

b1=float(input('b1: '))

b2=float(input('b2: '))

b3=float(input('b3: '))

c1=float(input('c1: '))

c2=float(input('c2: '))

c3=float(input('c3: '))

# determinant

d=a1*(b2*c3-b3*c2)-a2*(b1*c3-b3*c1)+a3*(b1*c2-b2*c1)

# inverse

d1=(b2*c3-c2*b3)/d

d2=-(a2*c3-c2*a3)/d

d3=(a2*b3-a3*b2)/d

e1=-(b1*c3-c1*b3)/d

e2=(a1*c3-c1*a3)/d

e3=-(a1*b3-a3*b1)/d

f1=(b1*c2-b2*c1)/d

f2=-(a1*c2-a2*c1)/d

f3=(a1*b2-a2*b1)/d

print("det=")

print(d)

print("inv=")

print([d1,d2,d3])

print([e1,e2,e3])

print([f1,f2,f3])


Numworks page:  https://workshop.numworks.com/python/ews31415/invthree


Example:


[[ -5.4, 3.3, -1.7 ], [ 0.6, 8.3, 5.3 ] [ 5.5, 5.4, 1.9 ]] 


returns 


[ -0.05493...,  -0.06604..., 0.13508... ]

[ 0.11974... ,  -0.00389..., 0.11798... ]

[ -0.18130..., 0.20224..., -0.20006... ]


Source:


wikiHow Staff "How to Find the Inverse of a 3x3 Matrix"  WikiHow.   Last Updated November 5, 2020.  https://www.wikihow.com/Find-the-Inverse-of-a-3x3-Matrix  Retrieved November 12, 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. 


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. 


Casio fx-CG50 and TI-84 Plus CE: Multiple Linear Regression

Casio fx-CG50 and TI-84 Plus CE: Multiple Linear Regression We have arrived at the last month of 2024. What a crazy year. I hope for...