Monday, July 29, 2019

TI Nspire CX and Casio Micropython: Recursion Polynomials

TI Nspire CX and Casio Micropython:  Recursion Polynomials

Introduction

This blog entry deals with how to calculate functions defined as a recursion polynomial.  An example:

f_n(x) = 2 * f_n-1(x) + 1    where f_0(x) = x^2

We'll cover the TI Nspire CX (which is programmed in Basic) and the Casio fx-CG50's Micropython Module.

TI Nspire CX

The programs for the TI Nspire are in Basic (or some flavor of it), so it can easily be adapted for many programming and graphing calculators.  A possible template could be:

Input "X: ", x
Input "N: ", n
Local f, g, h, i 
//  f represents the function f_n
// g represents f_n-1
// h represents f_n-2
If n = 0: Then Return f_0(x):  Stop: IfEnd
If n = 1: Then Return f_1(x):  Stop: IfEnd
Else // if n > 1
For i =2 to n do
f := f_(x,g,h,i)   // i is used in placed for n
h:= g   // move values for the next loop
g:= f
Next
Return f  // final result

This is just one example on how to tackle this. 

Example 1: 
f_n = f_n-1 * (x + 1) - f_n-2
f_0 = 1
f_1 = x

Define recur1(n,x)=
Prgm
:Local f,g,h,i
:If n=0 Then
:  Disp 1
:ElseIf n=1 Then
:   Disp x
:ElseIf n>1 Then
:   h:=1
:   g:=x
:   For i,2,n
:     f:=g*(x+1)-h
:     h:=g
:     g:=f
:   EndFor
:   Disp f
:EndIf
:EndPrgm

Example 2:  Hermite Polynomial
H_n = 2 * x * H_n-1 - (2 * n - 2) * H_n-2
H_0 = 1
H_1 = 2 * x

Define numhermite(n,x)=
Prgm
:© numerical hermite polynomial
:Local f,g,h,i
:If n=0 Then
:  Disp 1
:ElseIf n=1 Then
:  Disp 2*x
:ElseIf n>1 Then
:  h:=1
:  g:=2*x
:  For i,2,n
:    f:=2*x*g-(2*i-2)*h
:    h:=g
:    g:=f
:  EndFor
:  Disp f
:EndIf
:EndPrgm

Example 3:  Parabolic Cylinder Function (aka Weber Function)
D_v+2 = x * D_v+1 - v * D_v
D_0 = e^(-x^2/4)
D_1 = x * e^(-x^/4)

Define parabcylin(v,x)=
Prgm
:© parabolic cylinder polynomial
:Local f,g,h,i
:If v=0 Then
:  Disp e^(((−x^(2))/(4)))
:ElseIf v=1 Then
:  Disp x*e^(((−x^(2))/(4)))
:ElseIf v>1 Then
:  h:=e^(((−x^(2))/(4)))
:  g:=x*e^(((−x^(2))/(4)))
:  For i,2,v
:    f:=x*g-(i-1)*h
:    h:=g
:    g:=f
:  EndFor
:  Disp f
:EndIf
:EndPrgm

Casio fx-CG 50 Micropython

Here is an approach using Python:

import math
N = float(input("N = "))
X = float(input("X = "))
if N==0:
  print(f_0)
elif N==1:
  print(f_1)
elif N>1:
  H = f_0
  G = f_1
  for i in range (2,N+1):
     F = f_n
     H = G
     G = F
 print(F)

Example 1: 
f_n = f_n-1 * (x + 1) - f_n-2
f_0 = 1
f_1 = x

recursio.py:
import math
N=float(input("N = "))
X=float(input("X = "))
if N==0:
  print(1)
elif N==1:
  print(X)  
else:
  H=1
  G=X
  for i in range(2,N+1):
    F=G*(X+1)-H
    H=G
    G=F
  print(F)
   
Example 2:  Hermite Polynomial
H_n = 2 * x * H_n-1 - (2 * n - 2) * H_n-2
H_0 = 1
H_1 = 2 * x

hermite.py:
import math
N=float(input("N = "))
X=float(input("X = "))
if N==0:
  print(1)
elif N==1:
  print(2*X)
else:
  H=1
  G=2*X
  for i in range(2,N+1):
    F=2*X*G-(2*i-2)*H
    H=G
    G=F
  print(F) 


Example 3:  Parabolic Cylinder Function (aka Weber Function)
D_v+2 = x * D_v+1 - v * D_v
D_0 = e^(-x^2/4)
D_1 = x * e^(-x^/4)

import math
N=float(input("N = "))
X=float(input("X = "))
if N==0:
  print(math.exp(-X**2/4))
elif N==1:
  print(X*math.exp(-X**2/4))
else:
  H=math.exp(-X**2/4)
  G=X*math.exp(-X**2/4)
  for i in range(2,N+1):
    F=X*G-(i-1)*H
    H=G
    G=F
  print(F) 
 

Numeric Examples to Try:

Example 1:
n = 2, x = 0.5,  result: -0.25
n = 3, x = -1.7, result: 1.567

Example 2:
n = 2, x = 2.2, result:  17.36
n = 4, x = -0.8, result: -12.1664

Example 3:
n = 0, x = 6.7, result: 1.3369921208E-5
n = 2, x = 0.3, result: 5.86807637482E-4

Happy Programming!

Source:

Keith Oldham, Jan Myland, Jerome Spainer.  An Atlas of Functions.  2nd Edition Springer:  New York.  2009  ISBN 978-0-387-48806-6

Eddie

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

Saturday, July 27, 2019

HP Prime and TI-84 Plus CE: Maximum Probability - Incomplete Gamma Law

HP Prime and TI-84 Plus CE:  Maximum Probability - Incomplete Gamma Law

Introduction

The program IGLMAX calculates four calculation points of the Incomplete Gamma Law:

Three parameters of A, γ, and β of the IGL (Incomplete Gamma Law):

g(x) = 1 / (β^γ * gamma(γ)) * x^(γ - 1) * e^(x/β)

where:

X = list of data points, where x_i ≥ 0
s = number of data points
r = number of points where x_i = 0 (zero points)

A = ln(mean(X)) - (Σ ln(X_i))/(s - r)
γ = 1/(4*A) * (1 + √(1 + 4*A/3))
β = mean(X)/γ

And

p = probability that x is not exceeded
p = r/s + (1 - r/s) * (1 - uigf(γ, x)/gamma(γ))

Gamma Function:
gamma(γ) = ∫( t^(γ - 1) * e^(-t) dt, 0, ∞ )

Upper Incomplete Gamma Function:
uigf(γ, x) = ∫( t^(γ - 1) * e^(-t) dt, x/β, ∞ )

One particular application is determining the maximum limit that rainfall exceeds x (inches or mm).  The book "Pocket Computers in Agrometeorology" introduces this concept and provides a program for the classic TI-59 (see source below). 

HP Prime Program IGLMAX

EXPORT IGLMAX(L1,X)
BEGIN
// list of data ≥0, X
// 2019-06-16 EWS
LOCAL S,R,M,L,I;
LOCAL A,Y,B,N,G,P;
// set up
S:=SIZE(L1);
R:=0; // count zeros
M:=0; // ΣX
L:=0; // Σ(LN(X))
// counting loop
FOR I FROM 1 TO S DO
IF L1(I)==0 THEN
R:=R+1;
ELSE
M:=M+L1(I);
L:=L+LN(L1(I));
END;
END;
// parameters
A:=LN(M/(S-R))-L/(S-R);
Y:=(4*A)^(−1)*(1+√(1+4*A/3));
B:=M/(S-R)*1/Y;
// gamma
G:=CAS.Gamma(Y);
// upper incomplete gamma
N:=∫(T^(Y-1)*e^(−T),T,X/B,∞);
// maximum probability
P:=R/S+(1-R/S)*(1-N/G);
// results
RETURN {"A=",A,"γ=",Y,
"β=",B,"Max Prob=",P};
END;


TI-84 Plus Program IGLMAX
(Text to enter)

Note: probability is rounded to six decimal places

"EWS 2019-06-16"
Input "DATA (X≥0):",L1
Input "X:",X
"INITIALIZE"
dim(L1)→S
0→R
0→M
0→L
"COUNTING LOOP"
For(I,1,S)
If L1(I)=0
Then
R+1→R
Else
M+L1(I)→M
L+ln(L1(I))→L
End
End
"PARAMETERS"
ln(M/(S-R))-L/(S-R)→A
(4*A)^(­1)*(1+√(1+4*A/3))→Y
M/(S-R)*1/Y→B
"GAMMA"
fnInt(T^(Y-1)*e^(­T),T,0,500)→G
"INCOMPLETE GAMMA"
fnInt(T^(Y-1)*e^(­T),T,X/B,500)→N
"PROB"
R/S+(1-R/S)*(1-N/G)→P
round(P,6)→P
ClrHome
Disp "A=",A,"GAMMA=",Y,"BETA=",B
Pause 
Disp "MAX PROB (FIX 6)=",P

Example

Data from a city of the rainfall in 2017 and 2018 (in inches):

2017
January: 3.90
February: 2.84
March: 2.31
April: 0.98
May: 0.64
June: 0.05
July:  0.00
August: 0.01
September: 0.00
October: 0.33
November: 0.72
December: 1.08

2018
January: 2.49
February: 2.66
March:  3.06
April: 2.94
May: 2.33
June: 0.81
July: 0.05
August: 0.00
September: 0.00
October: 0.14
November: 0.50
December: 2.24

Parameters:
A:  0.7237035089
γ (Gamma): 0.8296776362
β (Beta): 1.812752248

Probability that X inches of rainfall will not exceed:
X = 1 in:  0.593857
X = 2 in:  0.781173
X = 3 in: 0.879613

Source:

R.A. Gommes  Pocket Computers In Agrometeorology  Food and Agriculture Organization of the United Nations.  FAO PLANT PRODUCTION AND PROTECTION PAPER.  Rome, 1983.  ISBN 92-5-101336-5

Eddie

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

Friday, July 26, 2019

DM42S/Free42/HP 42S: Hyperbolic Triangles: Law of Sines and Cosines

DM42S/Free42/HP 42S:  Hyperbolic Triangles: Law of Sines and Cosines



There are three solvers: 

HYPSIN:  Law of Sines - Hyperbolic Triangles

sinh SA / sin ∠A = sinh SB / sin ∠B = sinh SC / sin ∠ C

The solver uses sinh SA / sin ∠A = sinh SB / sin ∠B .  Use the clever use of the labels is needed with the solver.

HYPANG:  Law of Cosines - Angle Dominant - Hyperbolic Triangles

cos ∠A = - cos ∠B * cos ∠C + sin ∠B * sin ∠C * cosh SA

HYPSDE:   Law of Cosines - Side Dominant - Hyperbolic Triangles

cosh SA = cosh SB * cosh SC - sinh SB * sinh SC * cos ∠A

HP 42S/DM42/Free 42 Solver Programs

HYPSIN:  Law of Sines - Hyperbolic Triangles

00 { 51-Byte Prgm }
01▸LBL "HYPSIN"
02 MVAR "SA"
03 MVAR "∡A"
04 MVAR "SB"
05 MVAR "∡B"
06 RCL "SA"
07 SINH
08 RCL "∡A"
09 SIN
10 ÷
11 RCL "SB"
12 SINH
13 RCL "∡B"
14 SIN
15 ÷
16 -
17 END

HYPANG:  Law of Cosines - Angle Dominant - Hyperbolic Triangles

00 { 63-Byte Prgm }
01▸LBL "HYPANG"
02 MVAR "∡A"
03 MVAR "∡B"
04 MVAR "∡C"
05 MVAR "SA"
06 RCL "∡B"
07 COS
08 +/-
09 RCL "∡C"
10 COS
11 ×
12 RCL "∡B"
13 SIN
14 RCL "∡C"
15 SIN
16 ×
17 RCL "SA"
18 COSH
19 ×
20 +
21 RCL "∡A"
22 COS
23 -
24 .END.

HYPSDE:   Law of Cosines - Side Dominant - Hyperbolic Triangles

00 { 66-Byte Prgm }
01▸LBL "HYPSDE"
02 MVAR "SA"
03 MVAR "SB"
04 MVAR "SC"
05 MVAR "∡A"
06 RCL "SB"
07 COSH
08 RCL "SC"
09 COSH
10 ×
11 RCL "SB"
12 SINH
13 RCL "SC"
14 SINH
15 ×
16 RCL "∡A"
17 COS
18 ×
19 -
20 RCL "SA"
21 COSH
22 -
23 END

Examples

Degrees mode is used

Example 1



Step 1:  Solve for Z, use HYPSDE:

23° -> ∠A
1.766 -> SB
1.8 -> SC
Solve for SA:  1.0969

Step 2:  Solve for X°, use HYPSIN:

1.8 -> SA
23° -> ∠A
1.766 -> SB
Solve for ∠B:  22.1432°

Step 3: Solve for Y°, use HYPSIN:

1.8 -> SA
23° -> ∠A
1.0969 -> SB
Solve for ∠B:  10.1773°

Example 2



Step 1:  Solve for Z°, use HYPANG

40° -> ∠A
42° -> ∠B
1.365 -> SA
Solve for ∠C:  57.0139°

Step 2:  Solve for X, use HYPSIN

40° -> ∠A
42° -> ∠B
1.365 -> SA
Solve for SB: 1.4004

Step 3:  Solve for Y, use HYPSIN

40° -> ∠A
57.10739° -> ∠B
1.365 -> SA
Solve for SB: 1.6050

Sources:

Martin, Angel  "Hyperbolic Triangles for the HP-41"  http://hp41programs.yolasite.com/hyperbolictriangle.php  Retrieved May 15, 2019

Wikipedia "Hyperbolic Triangles" Last edited May 29, 2019.  https://en.wikipedia.org/wiki/Hyperbolic_triangle  Retrieved June 9, 2019

Eddie

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

Saturday, July 20, 2019

TI Nspire CX II and TI Nspire CX II CAS: User Input in Graphics Mode with getKey

TI Nspire CX II  and TI Nspire CX II CAS:  User Input in Graphics Mode with getKey

Introduction

In graphics mode, the TI Nspire CX II cannot use the Text, Request, or RequestStr.  However, with the use of getKey command, we can have the user interact with the program. 

TI Nspire CX II Program keydemo2

This program is a game where the user stops a spinner in hopes to win money or a car.  Good luck!

Define keydemo2()=
Prgm
:Clear 
:Local l,str,k,n
:l:={"$200","$300","$500","$1000","CAR","Nope."}
:While getKey(0)≠"enter"
:  Clear 
:  UseBuffer 
:© get key continous execution
:  n:=randInt(1,6)
:  SetColor 0,0,0
:  DrawText 50,25,"PRESS enter TO STOP"
:  If n≤5 Then
:    SetColor 0,128,128
:  Else
:    SetColor 255,0,0
:  EndIf
:© use square brackets for elements 
:© we can clear only dynamic areas
:© but it does not look good
:  DrawText 50,50,l[n]
:  PaintBuffer 
:© usebuffer and paintbuffer allows all objects to be displayed at once, ensuring a smooth transition, can also use wait
:EndWhile
:EndPrgm



TI Nspire CX II Program enterdemo

With the use of getKey, the user enters a number in graphics mode.  This can be used as a template. 

Define enterdemo()=
Prgm
:© goal: develop input in graphics mode
:© use float mode
:setMode(1,1)
:Local str,num,k
:str:=""
:© use initial text
:Clear 
:  SetColor 0,0,0
:  DrawText 0,50,"Press [enter] to stop."
:
:
:© main loop: enter the numbers
:Loop
:  Clear 
:  UseBuffer 
:  SetColor 0,0,0
:  DrawText 0,50,"Press [enter] to stop."
:
:  k:=getKey(1)
:  If k="." and inString(str,".")=0 Then
:    str:=str&"."
:  ElseIf k="0" Then
:    str:=str&"0"
:  ElseIf k="1" Then
:    str:=str&"1"
:  ElseIf k="2" Then
:    str:=str&"2"
:  ElseIf k="3" Then
:    str:=str&"3"
:  ElseIf k="4" Then
:    str:=str&"4"
:  ElseIf k="5" Then
:    str:=str&"5"
:  ElseIf k="6" Then
:    str:=str&"6"
:  ElseIf k="7" Then
:    str:=str&"7"
:  ElseIf k="8" Then
:    str:=str&"8"
:  ElseIf k="9" Then
:    str:=str&"9"
:  ElseIf k="−" Then
:    str:=string(−1*expr(str))
:  ElseIf k="del" and dim(str)>0 Then
:    str:=left(str,dim(str)-1)
:
:  ElseIf k="enter" Then
:© "lock" the number and leave
:  SetColor 0,0,0
:  DrawText 0,100,str
:  PaintBuffer 
:    Exit
:  EndIf
:
:SetColor 0,0,255
:DrawText 0,100,str
:PaintBuffer 
:
:EndLoop
:© return number to home
:num:=expr(str)
:Disp num
:EndPrgm



There are two ways the getKey command can be used in graphics mode.

Eddie

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

Friday, July 19, 2019

TI Nspire CX II and TI Nspire CX II CAS: Drawing Demo

TI Nspire CX II  and TI Nspire CX II CAS:  Drawing Demo

Introduction

The new TI Nspire CX II  and TI Nspire CX II CAS has an expanded library of programming commands.  We are now able to draw and place text anywhere on the screen. 

When a drawing command is used, the Nspire shifts into graphics mode.  The graphics screen is treated as a final output screen.  Graphics mode only executes in one of two places:

*  Running the program in a Calculator page in a document
*  Running the program in the Calculator part of the Sketchpad

When a graphics screen has an initial (and maximum) height of 212 pixels and an initial (and maximum) width of 318 pixels.  The default background is white. 

Shifting a Program to Graphics Mode

The Nspire shifts into graphics mode automatically any time a drawing command is executed.  Followed by their basic syntax, the commands are:

Clear (blank to clear the entire screen),  (x, y, width, height)

DrawArc  x, y, width, height, startAngle, sweepAngle

DrawCircle x, y, radius

DrawLine x1, y1, x2, y2

DrawPoly (see plotdemo2 for further details)

DrawRect upper_x_pixel, upper_y_pixel, width, height

DrawText x, y, string/text/expression

FillArc x, y, width, height, startAngle, sweepAngle

FillCircle x, y, radius

FillPoly (see plotdemo2 for further details)

FillRect upper_x_pixel, upper_y_pixel, width, height

getPlatform() (returns dt for desktop, hh for handheld, ios for the iOS App)

PaintBuffer  (buffers the paint screen)

PlotXY x, y, shape  (13 shapes available: 1 for dot, 5 for cross, 6 for plus, 8, for medium dot)

SetColor  red, green, blue    (sets the Nspire's color pen)

SetPen thickness, style  (1 thin, 2 medium, 3 thick; 1 smooth, 2, dotted, 3 dashed)

SetWidnow xMin, xMax, yMin, yMax  (establishes drawing area - use this command to switch coordinates to Cartesian)

UseBuffer  (tells the Nspire to use an off screen to draw objects, then use
PaintBuffer to call them back up)

Once graphics mode is entered, the following commands cannot be used:

Request
RequestStr
Text

This means if you want the user to able to input during graphics mode, you will need to use Getkey.

When the Graphics Is Displayed

The graphics will be displayed until the user presses [ enter ]. 

Caution:   The drawing commands are only available for the CX II.  The original CX, nor any previous incarnations of the TI Nspire will not have these commands. 

TI NSpire CX II Program plotdemo1

This demo shows all the possible shapes that PlotXY has.  Colors are set randomly. 

Define plotdemo1()=
Prgm
:© graphics uses pixels: 318 * 212
:© Plotxy demo
:Local r,g,b,n,x,y
:For n,1,13
:© set colors
:r:=randInt(0,255)
:g:=randInt(0,255)
:b:=randInt(0,255)
:SetColor r,g,b
:© draw text and points
:DrawText 1+22*n,40,n
:PlotXY 5+22*n,50,n
:EndFor
:EndPrgm



TI NSpire CX II Program plotdemo2

This demo draws filled polygons.  There are two syntax sets for DrawPoly and FillPoly:

Draw/FillPoly  x1, y1, x2, y2, ... ,xn, yn

With this format the polygon stops at the coordinate (xn, yn).  The polygon is not automatically completed under this format.  To complete the polygon, make sure that the coordinate (x1, y1) is the last two coordinates listed.

Draw/FillPoly x_coordinate_list, y_coordinate_list

With this format, the polygon is automatically completed.

Define plotdemo2()=
Prgm
:© draw four triangles, filled
:Clear 
:© draw background box - gray
:© use fill, no draw
:SetColor 128,128,128
:FillRect 0,0,212,212
:© remember: x,y,width,height
:
:© now the triangles
:SetColor 128,0,0
:FillPoly 56,0,106,106,156,0
:FillPoly 56,212,106,106,156,212
:SetColor 127,255,255
:FillPoly 0,56,106,106,0,156
:FillPoly 212,56,106,106,212,156
:EndPrgm



TI Nspire CX II Program plotdemo3

This demo draws the function y = 1.5 cos (x^2).  The angle is set to radians mode.  The coordinates are converted to pixels prior to plotting them.

Define plotdemo3()=
Prgm
:© draw y=1.5cos(x^((2)))
:Clear 
:© radians
:setMode(2,1)
:© denim color
:SetColor 16,36,192
:© main
:Local x,xs,xp,y,ys,yp
:xs:=((4*π)/(319))
:ys:=((4)/(213))
:For x,−2*π,2*π,xs
:  y:=1.5*cos(x^(2))
:  xp:=((x+2*π)/(xs))
:  yp:=((−(y-2))/(ys))
:  DrawText 10,10,xp
:  PlotXY xp,yp,1
:EndFor
:EndPrgm

TI Nspire CX II Program plotdemo5

Like in plotdemo3, this program draws y = 1.5 cos (x^2).  Instead of converting coordinates to pixels, SetWindow is used and adjust the coordinates so that Cartesian coordinates can be used. 

Define plotdemo5()=
Prgm
:© draw y=1.5cos(x^((2)))
:Clear 
:© radians
:setMode(2,1)
:© denim color
:SetColor 16,36,192
:© main
:Local x,xs,y,ys
:© only x scaling is necesary
:xs:=((4*π)/(319))
:SetWindow −2*π,2*π,−2,2
:© changes pixels to Cartesian
:For x,−2*π,2*π,xs
:  y:=1.5*cos(x^(2))
:  PlotXY x,y,1
:EndFor
:
:EndPrgm



This is a basic demonstration of drawing with the TI Nspire CX II.  On the next post, I show how to use getKey in graphics mode.

Happy drawing,

Eddie


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

Saturday, July 13, 2019

TI-84 Plus and Casio fx-CG50: Which Die Wins?

TI-84 Plus and Casio fx-CG50: Which Die Wins?

Introduction:  Which Die Wins? 

The program DICEODDS compares a pair of dice against each other.  Each die, having values on its six faces and a different distribution of those values, is rolled against each other.  The program determines which die has a better chance of winning.

The face of each die can have any value, and values can repeat.  These dice can and usually are  different from the standard dice (1, 2, 3, 4, 5, 6).

Example 1:

Die 1 is your standard die:  {1, 2, 3, 4, 5, 6}
However, Die 2 has all threes:  {3, 3, 3, 3, 3, 3}

If we roll Die 1 against Die 2, Die 1 wins if a 4, 5, or 6 is rolled.  The odds of Die 1 having a higher value is 1/2. 

Example 2:

Die 1:  {3, 3, 3, 4, 4, 4}
Die 2: {2, 2, 2, 2, 7, 7}

Die 1 wins when a 2 is rolled on Die 2, which occurs 4/6 or 2/3 of the time.  If a 7 is rolled from Die 2, then Die 2 wins, and this has a probability of 1/3. 

DICEODDS compares each value of Die 1 against Die 2 on a single roll of each die.

This is an idea based on a article from James Grime, mathematician who is part of Numberphile. (see Source below)  Numberphile has a YouTube channel which discusses mathematics.   

Grime starts the article by presenting a game where two players choose one of three dies.  The red die has five 3s and one 6, the blue die has three 2s and three 5s, and the olive has one 1 and five 4s.  By comparing dies against each other, the red has a better chance of winning over blue, the blue has better chance of winning over olive, and olive has a better chance of winning over red.  It happens that the dice in this game represent paper-rock-scissors.

Grime also covers games where a chosen die is rolled twice during a game.  There is Efron Dice, a game involving choosing one of four dice (all 3s, half 0s and half 4s, half 1s and half 5s, half 2s and half 6s).  Grime also presents a game involving five dice, each die with an equal chance of winning. 

Dice are considered to be non-transitive when in a game of comparing dice, no die is dominant.

Running DICEODDS

DICEODDS compares two dice on a single role and their probability of winning.  The user is allowed to either enter their own values or generate two random dice, with values ranging from 0 to 9.  Values can repeat, and if you want, do not have to be positive integers.  The screen shots below are from the Casio fx-CG50 version of DICEODDS. 




TI-84 Plus Program DICEODDS

"2019-06-03 EWS"
Menu("WHICH DIE WINS?","RANDOM DICE",1,"ENTER DICE",2)
Lbl 1
seq(randInt(0,9),X,1,6)→L₁
seq(randInt(0,9),X,1,6)→L₂
Goto 3
Lbl 2
Disp "ENTER DIE OF 6 VALUES"
Input "DIE 1: ",L₁
Input "DIE 2: ",L₂
Lbl 3
0→P
For(I,1,6)
sum(L₁(I)>L₂)/6*1/6→F
P+F→P
End
ClrHome
Disp "DIE 1,2",L₁,L₂,"ODDS DIE 1 WINS",P▶Frac,"ODDS DIE 2 WINS",(1-P)▶Frac

Casio fx-CG50 Program DICEODDS - (text file format)

'ProgramMode:RUN
"2019-06-04 EWS"
Menu "WHICH DIE WINS?","RANDOM DICE",1,"ENTER DICE",2
Lbl 1
6->Dim List 1
6->Dim List 2
For 1->I To 6
RanInt#(0,9)->List 1[I]
RanInt#(0,9)->List 2[I]
Next
Goto 3
Lbl 2
"ENTER DIE: 6 VALUES"
"DIE 1:"?->List 1
"DIE 2:"?->List 2
Lbl 3
0->P
For 1->I To 6
Sum (List 1[I]>List 2)/6*1/6->F
P+F->P
Next

ClrText
Red Locate 1,1,"DIE 1:"
Blue Locate 1,2,"DIE 2:"
For 1->I To 6
6+2*I->J
Red Locate J,1,List 1[I]
Blue Locate J,2,List 2[I]
Next
Locate 1,4,"ODDS DIE 1 WINS:"
Red Locate 1,5,P
Locate 1,6,"ODDS DIE 2 WINS:"
Blue Locate 1,7,1-P

Source:

Grime, James "The Bizzare World of Nontransitive Dice: Games for Two or More Players" from:
Pritici, Micrcea (editor) "The Best Writing on Mathematics 2018"  Princeton University Press: Princeton, NJ.  2019  ISBN 978-0-691-18276-6

The article can also be found on the web:  https://singingbanana.com/dice/article.htm
(Retrieved June 5, 2019)

Eddie

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

Friday, July 12, 2019

TI-84 Plus CE: Addition and Multiplication Math Tables

TI-84 Plus CE:  Addition and Multiplication Math Tables 


Addition Table

Multiplication Table


The programs ADDTABLE and MULTABLE create a 10 x 10 addition and multiplication table, respectively.  The programs are presented on the TI-84 Plus CE because colors are included.

I use the drawing commands on a graphing screen instead of using a matrix to accomplish the look I want.

TI-84 Plus CE Program ADDTABLE

"EWS 2019-04-14"

"BUILD THE TABLE"
{11,11}→dim([J])
For(I,2,11)
I-1→[J](1,I)
I-1→[J](I,1)
End

"ADD"
For(I,2,11):For(J,2,11)
[J](I,1)+[J](1,J)→[J](I,J)
End:End

"DRAW"
ClrDraw:AxesOff:FnOff 
For(I,1,11):For(J,1,11)

If I=1 or J=1
Then
TextColor(RED)
Else
TextColor(BLACK)
End

Text(1+14(I-1),1+20(J-1),[J](I,J))
TextColor(BLACK)
Text(1,1,"+")
End:End


TI-84 Plus CE Program MULTABLE

"EWS 2019-04-14"

"BUILD THE TABLE"
{11,11}→dim([J])
For(I,2,11)
I-1→[J](1,I)
I-1→[J](I,1)
End

"MULTIPLY"
For(I,2,11):For(J,2,11)
[J](I,1)*[J](1,J)→[J](I,J)
End:End

"DRAW"
ClrDraw:AxesOff:FnOff 
For(I,1,11):For(J,1,11)

If I=1 or J=1
Then
TextColor(GREEN)
Else
TextColor(BLACK)
End

Text(1+14(I-1),1+20(J-1),[J](I,J))
TextColor(BLACK)
Text(1,1,"*")
End:End

Eddie

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

Saturday, July 6, 2019

Review: SpecExp Calculator App (Android)

Review:  SpecExp Calculator App (Android)

Welcome to my blog post 1,001!   (happy dance)






Quick Facts

Author:  Scientific Software Team
Type:  Scientific and Function Graphing
Input:  Textbook
Platform:  Android
Current Version:  4.0.4
Price:  Free version (has ads),  $19.99 (no ads)

Links

To the SpecExp Calculator website:  https://spec-exp.appspot.com/#

To the Paid Version:  https://play.google.com/store/apps/details?id=az.elten.specexp.calculator.paid

I recommend the paid version, I'm not a fan of the ads.

Features

*  Textbook input of mathematical expressions
*  Matrices and vectors
*  Fractions
*  Base conversions
*  Function Graphing

The File System

Calculations and graphs are stored in files.  To start a new calculation, press the round plus button ( + ) on the bottom right hand of the screen.  You will be prompted to select CALCULATE or GRAPH.

Entering Mathematical Calculations

Each mathematical calculations are stored in separate files.  The calculations can be simple or complex as you want.  You can pinch zoom to adjust the font on the calcuation.  Multiplication is symbolized by a middle dot.

Functions are located on top of the soft keypad, and is a scrollable menu:

π i :   Π (inserts π), e, i (√-1 for complex numbers), ° (degrees), ' (minutes/seconds), % (to divide the number by 100)

sin sec:  sin, cos, tan, ctan (cot), csc, asin, acos, atan, actan (acot), sec

The angle measure defaults to radians, but you can use the degree symbol to indicate any angle in degrees ( ° ).

ln sh:  sh (sinh), ch (cosh), th (tanh), cth (coth), ln, lg (log), Log_ (log to any base)

√ | | :  √, | | (absolute value), arg (argument or angle), _√ (universal root), sign

Matrices:
det rang:  det (determinant),  rang (rank)*,  ransp (transpose, the menu shows the key as ransp, but the function is transp)

* I wasn't sure about the rang function.  I emailed the author and he stated it was the rank function.

( ) [ ] { }:
*  Use the parenthesis in expressions and to signify vectors.  Separate arguments by the colon ( ; )
*  The square brackets are used in expressions with sum (Σ), product (Π), and limit
*  The menu has both LCM and GCD

A  C:   A (permutations),  C (combinations), ! (factorials, positive integers from 0 to 170)

| |:  Matrix template and builder

lim ∫:  limits (two sided and one sided), sums, products, integrals, you can use ∞

ABC_ : used for base conversions (A = 10, B = 11, C = 12, D = 13, E = 14, F = 15), ABC_ puts a subscript

Use two subscripts to convert bases.  For example, converting 11101 from binary to octal:  11101_2_8, result 35_8

Viewing Answers

To calculate the result, press the equals key ( = ).  The result will be displayed on a separate page.  There are four options:

* Improper fraction (when available)
* Decimal
* Mixed Fraction
* Degrees (the result is assumed to be radians unless marked by °, shown in degrees-minutes-seconds format)

Graphing Functions

Graphing pages are represented by two arrows are right angles (going right and up).  You can graph multiple functions.  The function's colors are automatic (blue for the first, red for the second, etc).  The graphs are displayed  and can be pinch zoomed.

Verdict

I like how the screen is used to write and display expressions.  This is a very promising app.

There are few things I would like to see in future updates:  numerical derivatives, graphing analysis (intersections, roots, tracing, areas, slopes, etc).

The $19.99 price tag may be high for some, so if are not sure, you can try the free version first (of course you get ads).

Eddie

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

Friday, July 5, 2019

The 1000th Post: HP Prime and TI-84 Plus: Log-Normal Distribution

The 1000th Post:  HP Prime and TI-84 Plus: Log-Normal Distribution



This is a landmark for this blog, this is post 1,000.  One Thousand.   And it is still fun.  I thank you all for your support - very grateful.

On to the next 1,000!

Introduction - Log-Normal Distribution

The programs presented in this blog will calculate the PDF (probability density function) and the CDF (cumulative density function).  The CDF calculates the lower tail probability.   The formulas are:

PDF:   e^(-(ln x - μ)^2 / (2 * σ^2) )

CDF:  1/2 + 1/2 * erf( (ln x - μ) / (σ * √2) )

where:  x = point on the distribution, μ = mean (default 0), σ = deviation (default 1)

Log-Normal Distribution

HP Prime Program LOGNORM_PDF

EXPORT LOGNORM_PDF(μ,s,x)
BEGIN
// log normal pdf
// μ, σ, x 
RETURN (x*s*√(2*π))^(-1)*
e^(−(LN(x)-μ)^2/(2*s^2));
END;

TI-84 Plus Program LOGNRMPD

Input "MEAN: ",M
Input "STDDEV: ",S
Input "X: ",X
(X*S*√(2*π))^-1*e^(­(ln(X)-M)²/(2*S^2))→P
Disp "PDF=",P

Example 1:
Mean = 0, Standard Deviation = 1, X = 2.5
PDF = 0.1048710669

HP Prime Program LOGNORM_CDF

EXPORT LOGNORM_CDF(μ,s,x)
BEGIN
// log normal cdf - lower tail
// μ, σ, x
RETURN .5+
.5*CAS.erf((LN(x)-μ)/(s*√2));
END;

TI-84 Plus Program LOGNRMCD

Input "MEAN: ",M
Input "STDDEV: ",S
Input "X: ",X
"ERF"
(ln(X)-M)/(S*√(2))→Z
2/√(π)*fnInt(e^(­T^2),T,0,Z)→E
"CDF"
.5+.5*E→C
Disp "CDF: ",C

Example 2:
Mean = 0, Standard Deviation = 1, X = 2.5
PDF = 0.8202427861

Thank you, here's to the next 1,000 posts....

Source:

"Log-normal distribution" Wikipedia Last edited May 15, 2019.  https://en.wikipedia.org/wiki/Log-normal_distribution  Retrieved May 25, 2019


Eddie

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