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.

Saturday, June 29, 2019

HP 42S/DM42/Free 42: Auto Solvers

HP 42S/DM42/Free 42:  Auto Solvers

Introduction

This blog entry has four solvers for use the on the HP 42S (or Free42, DM42) in the subject of automobiles:

1.  Displacement, Bore, Strokes
2.  Gear Ratio, MPH, RPM
3.  Quarter Mile Estimation:  Elapsed Time, Car's Weight, Horsepower
4.  Tire Sizes

If you  are entering these programs by hand, I suggest that you create the needed variables ahead of time by storing an arbitrary value (it doesn't matter) into the variable.  Therefore when you recall the variables, they will be available in the soft menu.  Activate the solvers by pressing the orange shift key ([SHIFT]) [ 7 ] (SOLVER).

Link to the programs can be downloaded here:  https://drive.google.com/file/d/1N4wpO9Q-Mhyp51kdubAh5guf2xZhp8Tc/view?usp=sharing

1.  Displacement, Bore, Strokes  (File:  displacement.raw)

00 { 79-Byte Prgm }
01▸LBL "DISPMNT"
02 MVAR "DISPMNT"
03 MVAR "BORE"
04 MVAR "STROKE"
05 MVAR "#CYLIN"
06 PI
07 4
08 ÷
09 RCL "BORE"
10 X↑2
11 ×
12 RCL× "STROKE"
13 RCL× "#CYLIN"
14 RCL- "DISPMNT"
15 .END.

Variables:

(DISPM):  displacement of the a cylinder (cubic inches)
(BORE):  diameter of the cylinder (inches)
(STRO):  distance traveled by the piston (inches)
(#CYLI):  number of cylinders

Equation:

π/4 * bore^2 * stroke * #cylinders - displacement = 0

Example:

Bore = 4 in
Stroke = 3.5 in
4-cylinder engine

Result:  Displacement = 175.9292 in^3

2.  Gear Ratio, MPH, RPM  (File:  gearratio.raw)

00 { 74-Byte Prgm }
01▸LBL "GEARRTO"
02 MVAR "RPM"
03 MVAR "MPH"
04 MVAR "TIREDIA"
05 MVAR "GEARRAT"
06 PI
07 RCL× "RPM"
08 RCL× "TIREDIA"
09 RCL÷ "MPH"
10 1056
11 ÷
12 RCL- "GEARRAT"
13 .END.

Variables:

(RPM):  the tire's revolution per minute
(MPH):  speed of the vehicle (miles/hour)
(TIREDI): diameter of the tire (inches)
(GEAR):  gear ratio = transmission ratio * final drive ratio

Equation:

(RPM * π * tire_diameter) / (MPH * 1056) - gear_ratio = 0

Example:

RPM = 3,400 rpm
Tire Diameter = 28 in
Gear Ratio = 3.85

Result:  MPH = 73.5635 mph

3.  Quarter Mile Estimation:  Elapsed Time, Car's Weight, Horsepower
(File:  quartermile.raw)

00 { 52-Byte Prgm }
01 ▸ LBL "QRTMI"
02 MVAR "ET"
03 MVAR "WEIGHT"
04 MVAR "HP"
05 5.825
06 RCL "WEIGHT"
07 RCL÷ "HP"
08 3
09 1/X
10 Y↑X
11 ×
12 RCL- "ET"
13 .END.

Variables:

(ET): elapsed time for the car to travel 1/4 mile (seconds)
(WEIG):  weight of the car including passengers, drivers, fuel, and other items carried (pounds)
(HP):  horsepower

Equation:

(weight/horsepower)^(1/3) * 5.825 - elapsed_time = 0

Note:  MPH = (horsepower/weight)^(1/3) * 234 = 1363.05/elapsed_time

Example:

Weight:  3,540 lb
HP:  215 hp

Result:

ET: 14.8190
(MPH = 91.9802 mph,  [SHIFT] (TOP.FCN) ( 1/X ) 1363.05 [ * ])

4.  Tire Sizes (file name:  tiresize.raw)

00 { 87-Byte Prgm }
01 ▸ LBL "TIRESZE"
02 MVAR "SECWDTH"
03 MVAR "RIMDIA"
04 MVAR "ASPECT"
05 MVAR "TIREDIA"
06 2
07 RCL× "SECWDTH"
08 RCL× "ASPECT"
09 2540
10 ÷
11 RCL+ "RIMDIA"
12 RCL- "TIREDIA"
13 .END.

Variable:

(SECW):  section width (millimeter)
(RIMDI):  rim diameter (inches)
(ASEPC):  aspect ratio
(TIREDI):  tire diameter (inches)

On a side of a tire, we can get three of the four values by from a code that looks like this:

P235 / 75R17

P:  passenger car  (L for light trucks)
235:  section width
75:  aspect ratio
R:  radial tire
17: rim diameter

Equation:

(2 * section_width * aspect_ratio) / 2540 + rim_diameter - tire_diameter = 0

Example:  Use the stats of the tire above to calculate tire diameter.

Result:  30.8780 in

Source:

John Lawlor.  "Auto Math Handbook:  Mathematical Calculations, Theory, and Formulas for Automotive Enthusiasts"  HPBooks:  New York 1992  ISBN 1-55788-020-4

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, June 22, 2019

Time Value of Money: Using Present Value Factors

Time Value of Money:  Using Present Value Factors

Introduction

The time value of money equation is:

0 = PV + PMT * PVAF + FV * PVSF

where

PVAF = present value of annuity factor = Σ( (1 + i%)^(-k), k, 1, n )
PVSF = present value of single factor = (1 + i%)^-n
n = number of payments
i% = periodic interest rate (as a decimal)

The cash flow convention is maintained with this model.  Cash outflows (payments) are negative, cash inflows (receipts) are positive.

Solving for Payment (PMT)

0 = PV + PMT * PVAF + FV * PVSF
-PMT * PVAF = PV + FV * PVSF
-PMT = (PV + FV * PVSF) / PVAF
PMT = -(PV + FV * PVSF) / PVAF

Example

PV = $50,000.00
FV = -$10,000.00
n = 60  (5 years of monthly payments)
i% = 0.05/12

PVAF = 52.99071
PVSF = 0.77921

PMT = -(50000 - 10000 * 0.77921) / 52.99071 = -796.5150873
(cash payment of $796.52)

Solving for Future Value (FV)

0 = PV + PMT * PVAF + FV * PVSF
-FV * PVSF = PV + PMT * PVAF
FV = -( PV + PMT * PVAF ) / PVSF

Example

PV = -$1,000.00
PMT = -$250.00
n = 60  (5 years of monthly payments)
i% = 0.05/12

PVAF = 52.99071
PVSF = 0.77921

FV = -( -1000 - 250 * 52.99071) / 0.77921 = 18284.7724
(future value of deposit $18,284.77)

We can use this method with any calculator.  A partial present value factor table, one for single payment, and one for annuity, is presented below.





Source:

"HP 17BII Financial Calculator Owner's Manual"  Edition 1  Hewlett Packard.  Corvallis, OR.  December 1989.

Have fun,

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, June 15, 2019

HP 42S and TI-60: Dimensions of a Race Track

HP 42S and TI-60:  Dimensions of a Race Track



We have a race track that consists of two rectangular tracks connected by a circular ring that is cut in half.  A half ring attaches to each end. 

Let the variables define the following measurements:

R0 = radius from the center of the circular ring to the outside of the track
RI = radius from the center of the circular ring to the inside of the track
C = length of the rectangular potion of the track
R0 - RI = width of the rectangular portion of the track

I am taking an imaginary line in the middle of the track (see the pink dotted line on the right side of the illustration).  The radius from the center of the ring to the pink dotted line is:
 RI + (R0 - RI)/2.

Area: 

Area
= area of the circular ring + area of the top rectangular portion + area of the bottom rectangular portion
= (π * RO^2 - π * RI^2) + C * (RO - RI) + C * (RO -RI)
= π * (RO^2 - RI^2) + 2 * C * (RO - RI)

Perimeter:

Perimeter
= circumference of the circle at the half way point between the outside and inside radius + length of the top rectangular portion + length of the bottom rectangular potion
= 2 * π * (RI + (RO - RI)/2) + C + C
= 2 * π * (RI + (RO - RI)/2) + 2 * C
= 2 * π * 1/2 * (2 *RI + RO - RI) + 2 * C
= π * (RO - RI) + 2 * C

Now that we have the calculations, let's put them to practice.

Input Variables (see above):

R0 = RO
R1 = RI
R2 = C

Ouput Variables:

R3 = area
R4 = perimeters

HP 42S/DM42/Free42 Program RACETRK

00  {68-Byte Prgm}
01  LBL "RACETRK"
02  RCL 00
03  X ↑ 2
04  RCL 01
05 X ↑ 2
06  -
07  PI
08  *
09  2 
10  RCL * 02
11  RCL 00
12  RCL - 01
13  *
14  +
15  STO 03
16  "AREA="
17  AVIEW
18  STOP
19  2
20  RCL * 02
21  RCL 01
22  RCL + 00 
23  PI
24  *
25  +
26  STO 04
27  "MID PERIMETER="
28  AVIEW
29  RTN
30  END

TI-60 Program Race Track

Format:   line number :  key code : key

00 :  91  :  π
01  :  65  :  *
02  :  53  :  (
03  : 71  : RCL
04  :  00 :  0
05  :  96  : x^2
06  :  75  :  -
07  :  71  :  RCL
08  :  01  :  1
09  :  96  :  x^2
10  :  54  :  )
11  :  85  :   +
12  :  02  :  2
13  :  65 :  *
14  :  71  :  RCL
15  :  02 :  2
16  :  65  :  *
17  :  53  :  (
18  :  71   :  RCL
19  :  00  :  0
20  :  75  :  -
21  :  71  :  RCL
22  :  01  :  1
23  :  54   :  )
24 :  95  :  =
25  :  61  :  STO
26  :  03  :  3
27  :  13   : R/S
28  :  02  :  2
29  :  65  :  *
30  :  71   :  RCL
31   :  02 :  2
32  :  85  :  +
33  :  91  :  π
34  :  65  :  *
35  :  53  :  (
36  :  71  : RCL
37  :  00  :  0
38 :  85  :  +
39  :  71  :  RCL
40  :  01 :  1
41  :  54  :  )
42  :  95  :  =
43  :  61  :  STO
44  :  04  :  4
45  :  13  : R/S
46  :  22  :  RST

Example

R0 = radius to outside ring = 12 ft
R1 = radius to inside ring = 8 ft
R2 = length of the rectangular portion of the trace = 45 ft

Results:

Area (R3) = 611.3274123 ft^2
Perimeter of the mid-line (R4) = 152.8318531 ft

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, June 7, 2019

Casio fx-5800P: Cash Flow Program (Pierre Gillet)

Casio fx-5800P:  Cash Flow Program (Pierre Gillet)

Introduction:  Cash Flows Using the Stat List

Today's program comes from Pierre Gillet, who emailed me a set of programs to calculate net present value (NPV) and internal rate of return (IRR) for the Casio fx-5800P.  A key feature is that these programs use the statistical lists List X and List Freq from the SD mode.

There are three programs listed:

"NPV":  calculates Net Present Value.  Store the interest rate in decimal in variable X in Comp mode before running "NPV".

"SOLVE":  solves for the Internal rate of return (IRR) using the secant method.  Again, use decimals for interest rates.  For the IRR, your YTARGET is always 0.

"YFX":  The function to solve.  In this case, YFX refers the program to "NPV".

The programs here are from Pierre Gillet and are presented with permission.

Casio fx-5800P program "NPV"  (Pierre Gillet) 

Notes:
1.  Small n  is from the Statistics variable n.  [ FUNCTION ], 7:  STAT, 2: VAR, 1: n
2.  Call up the Stat lists by:  [ FUNCTION ], 7: STAT, 1: LIST  (1: List, 2:  Freq, or type X for List X)

0 → Y : 1 → U : 2 → W 
Lbl 1
U + List Freq[W] → V
Lbl 2
Y (1 + X) + List X[W] → Y
Isz U
U < V ⇒ Goto 2
Isz W
U < n ⇒ Goto 1
List X[1] + Y ÷ ( ( 1 + X ) ^ ( n - 1 ) ) → Y

Casio fx-5800P program "SOLVE"  (Pierre Gillet)

Note:  Keep recycling the loop with [ EXE ] until an error occurs.  The final result is the IRR (stored in X).

Note: The frequency of the first data point (X[1]) is not considered in the calculation.

"X1" ? → A
"X2" ? → B
"YTARGET" ? → T
A → X : Prog "YFX"
Y - T → R
B → X : Prog "YFX"
Y - T → S
Lbl 1
B - S ( B - A ) ÷ ( S - R ) → C
C → X ⊿
Prog "YFX" : Y - T → Q
A → B : R → S : C → A : Q → R
Goto 1

Casio fx-5800P program "YFX"  (Pierre Gillet)

Prog "NPV"

Example

Go to SD mode.  Make sure that the Frequency is turned on by pressing [ SHIFT ],  ( SETUP), 5: STAT, 1: FreqOn

Data:  List X, Freq
-5600, 1
1300, 1
2500, 1
3000, 1

NPV:  interest rate of 8%.  (store 0.08 in X)

Result:  $128.55

Solve for IRR,  run SOLVE with guesses X1 = 0, X2 = .15, and YTARGET = 0.

Final result:  0.0912 (9.12%)

Thank you Pierre Gillet!

Note: I wasn't called to jury duty - back to normal life for me.  I'm also posting this a day early. 

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.

Sunday, June 2, 2019

TI-Nspire Survival Guide

TI-Nspire Survival Guide









With both the TI-Nspire CX II and the TI-Nspire CX II CAS here, there is a renewed interest in the TI-Nspire.  To be honest, I have not used the TI-Nspire CX in quite while, so I had to re-learn some of the basics of the calculator.

The TI-Nspire calculators operates like a computer, with files, folders, documents, and each file containing a set of problems.

I put together a tns (TI-Nspire) documents, TI-Nspire Guide, available for download.  This document is for both the non-CAS and CAS version.  Hopefully, this document provides help with learning some of the basics for the TI-NSpire.

Problems (Table of Contents):

1.  Calculator Basics
2.  Programming functions to use anywhere (public functions)
3.  Graphing
4.  Data and Statistics
5.  Geometry
6.  Other Functions

 Link:  https://drive.google.com/open?id=15XolSFnCFLkj6pPm446PTdvpmVJfwcfw

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, June 1, 2019

HP Prime and Casio fx-CG 50: Black Scholes-Merton Model

HP Prime and Casio fx-CG 50:  Black Scholes-Merton Model

Introduction

The Black Scholes-Merton model, often known as the Black-Scholes model, is a model to estimate the call and put options.  Even though this model is designed for European options, the model is used on options worldwide.  The formula to calculate the call option is:

C = S * N(d1) - K * e^(-r * T) * N(d2)

where:

C = call price
S = stock price
K = exercise price
r = risk free rate (percent)
v = implied volatility (standard deviation of log returns) (percent)
(also symbolized as σ)
T = the time until the stock matures, in the measure in years  (if you are given the number days, divide this number by 365 (or 365.25, 366, 360))

N(d1) and N(d2):  lower tail probability of the Normal Distribution of points d1 and d2, respectively.  (NormCDF( -∞,d1) and NormCDF(-∞,d2))

d1 and d2:

d1 =  ( ln(S/K) + ( r^2 + v^2/2 ) * T ) / ( v * √T )

d2 = d1 - v * √T

Normal Distrubtion:

NormCDF(a, b) = 1 / √(2 * π) * ∫( e^(-t^2/2) dt, a, b)

Also note:

Expected Stock Value = S * N(d1)
Expected Strike Value =  K * e^(-r * T) * N(d2)
Call Price = Expected Stock Value - Expected Strike Value

HP Prime:  Black-Scholes Model

There is no need to enter a program to calculate Call Price and Put Price.  The Black-Scholes Model is in the Finance app.  Select Black-Scholes on the Symb page.  Enter and solve for call and put price on the Num screen.



Casio fx-CG50 Program BLACKSCH

This program calculates the expected stock value, expected strike value, and the call price. 

"BLACK SCHOLES"
"STOCK PRICE: "? → S
"STRIKE PRICE: "? → K
"TIME-EXPIR. (DAYS): "? → T
T ÷ 365.25 → T
"RISK FREE %: "? → R
R ÷ 100 → R
"VOLITALITY σ%: "? → V
V ÷ 100 → V
(ln (S ÷ V) + (R + V^2 ÷ 2 ) * T) ÷ ( V * √T ) → D
D - V * √T → E
S * NormCD(-10,D) → W
K * e^(-R * T) * NormCD(-10, E) → X
W - X → C
"EXEPECTED STOCK VALUE"
RndFix(W,2) ⊿
"EXPECTED STRIKE VALUE"
RndFix(X,2) ⊿
"CALL PRICE"
RndFix(C,2)

Example

Input:
Stock Price:  $55.00
Strike Price: $41.00
Days to Expiration: 90 days    (90/365.25 ≈ 0.25 year)
Risk Free Rate:  2.5%
Volatility Rate:  25%

Output:
Expected Stock Value: $54.64
Expected Strike Value:  $40.37
Call Option: $14.27

Source:

Black-Scholes-Merton Brilliant.org.  Retrieved April 24, 2019, from https://brilliant.org/wiki/black-scholes-merton/

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.

Thursday, May 30, 2019

HP Prime and HP 17BII: Trapezoid Rule Using Distinct Points

HP Prime and HP 17BII: Trapezoid Rule Using Distinct Points



Introduction

We can estimate the area of any surface by the use of sums and integral.  In calculus, we usually are given a function f(x), but here we are using measurements from one end to the other at various intervals. 

Technically, the intervals between each measurement do not have to be equal length.  However, having intervals of equal length makes things a lot easier, and in this blog entry, we assume they are. 

We have various methods to estimate the area.  One of the easiest ways is the Trapezoid Rule:

Area ≈ h/2 * ( y_1 + y_n + 2 * Σ( y_k , k, 2, n-1 ) )

Where:

h = interval length
y_k = length of each measurement, there are  n measurements
y_1 and y_n:  measurement of lengths at each end, respectively

Another rule to estimate area is the Simpson's Rule:

Area ≈ h/3 ( y_0 + y_n + 4 * Σ( y_k, k, 1, n-1, 2) + 2 * Σ( y_k, k, 2, n-2, 2) )

The program presented here uses the Trapezoid Rule. 

HP Prime Program AREAHGT

Two arguments:  h, a list of measurements

EXPORT AREAHGT(h, ms)
BEGIN
// h:  increment between measurements
// ms: list of measurements
// 2019-05-09 EWS
LOCAL k,n:=SIZE(ms);
RETURN h/2 * (ms(1) + ms(n) + 2 * Σ( ms(k), k, 2, n-1 ));
END;

HP 17BII+ (Silver)/HP 17BII Solver:  Trapezoid Rule

First:  define a SUM list named MS.  The solver uses that list to get the reference measurements.

Solver:

AREAHGT: AREA = 0 * L(N:SIZES(MS)) + H÷2 * (ITEM(MS:1) + ITEM(MS:G(N)) + 2 * Σ(K:2: G(N)-1: 1: ITEM(MS:K) )

Example

h = 0.5

MS:
y_1 = 1174
y_2 = 1078
y_3 = 979
y_4 = 984
y_5 = 810
y_6 = 779
y_7 = 800
y_8 = 852
y_9 = 966

Area:  3676

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.

Monday, May 27, 2019

Fractal Plots: TI-84 Plus CE and HP Prime

Fractal Plots:  TI-84  Plus CE and HP Prime

Introduction

The program CHAOS1 plots a fractal to simulate a Julia Set.  Given the complex numbers z_k and c, repeats the equation:

z_n = z_n-1 + c^2

The program will ask for a sample graphing space with the a border B.  The viewing window will be set up as:

Xmin = -B
Xmax = B
Ymin = -B
Ymax = B

The program CHAOS1 will also as for the number of points (G), this will determine the number of points plotted in the graph.  The higher G is, the more detailed the fractal is; however, the plot will take longer to complete.

We start with each point on the graph z_0 = a + b*i, where i = √-1.  Then we calculate:

z_1 = z_0^2 + c
z_2 = z_1^2 + c
z_3 = z_2^2 + c
and so on.

For each z_0, we have two possibilities for the repeated calculations:

1.  |z_n| = abs(z_n) eventually goes towards infinity or

2.  |z_n| = abs(z_n) eventually settles (or converges) to a specific point.

A color is assigned to each point z_0.  The color is determined by the amount of iterations it takes to reach |z| > 2.  For such points that fit criteria 2, and never reaches |z| >2, the point is colored black.  This method creates the Julia set for any given c.

For the program CHAOS1, I set up a rank of colors to plot each point, and arbitrary pick a maximum amount of iterations.  For example, I picked 9 colors for the TI-84 Plus CE version.  Hence for each point, if |z| ≤ 2 after 9 iterations, color the point black.

Obviously the more levels (colors) we have, the more accurate our fractal is.  With the programs listed, you can adjust the number of colors.   Keep in mind the TI-84 Plus CE has up to 15 colors, the Casio fx-CG50 has up to 7, and the HP Prime's colors have 256 levels of red, green, and blue.

You can download CHAOS1 for both the TI-84 Plus CE and HP Prime here:
https://drive.google.com/open?id=1A06e_pAPk7fMik07Pbi1tyjbLSUkVUN2

TI-84 Plus CE Program CHAOS1  (File:  CHAOS1.8xp)

For the Ti-84 Plus CE, I recommend the number of grid points of no more than 75.

The list of colors that I use in this code is:

1.  WHITE:  color value of 20
2. LTGRAY: color value of 21
3.  YELLOW: color value of 19
4.  ORANGE:  color value of 15
5.  BROWN: color value of 16
6.  GREEN: color value of 14
7.  LTBLUE:   color value of 18
8.  BLUE:  color value of 10
9.  BLACK: color value of 12

Note:  ⅈ represents √-1 ([Shift] [ 3 ])


Func: a+b ⅈ
FnOff: ClrDraw
Input "BORDER: ",B
Input "NO. GRID PTS: ",G
Input "PT C X+Yi: ", C
{20,21,19,15,16,14,18,10,12} → L6
dim(L6) → S
-B → Xmin: B → Xmax
-B → Ymin: B → Ymax
For(I, -B, B, 2B/G)
For(J, -B, B, 2B/G)
1 → K
I + J ⅈ→ Z
Lbl A
If abs(Z)>2 or K=S
Goto B
Z^2 + C → Z
1 + K → K
Goto A
Lbl B
L6(K) → L
Pt-On(I, J, 3, L)
End

Examples

B = 1, G = 75, C = -0.79 + 0.15i

B = 1, G = 75, C = 0.334 - 0.169i

HP Prime Program CHAOS1 (File:  CHAOS1.hpprgm)

I set 18 color levels, starting from white to black.   Because of the faster processor and calculating speed, I have increased the number of grid points to 500.  250 makes a picture with lines.

Note:  I use the parenthesis notation (x,y) for the complex number x + yi because the imaginary character i unfortunately does not transfer to computer text.  (updated 5/27/2019 - this allows for copying the code to the HP Prime connectivity kit/emulator)

EXPORT CHAOS1()
BEGIN
// 2019-05-19 EWS
LOCAL b,g,c,l6,s;
LOCAL i,k,j,z,l; 
STARTAPP("Function");
INPUT( {b, g, {c, [[0],[3]] }, "Fractal",
{ "Border: ", "Grid: ", "C: "},
{ "Min/Max - X/Y", "# Grid Pts", "C: x + yi " });
// size the screen
Xmin:=-b; Xmax:=b;
Ymin:=-b; Ymax:=b;
// clear the screen
RECT();
// list of colors
l6:= { #FFFFFFh, #C0C0C0h,
#D0D0D0h, #FFFF00h,
#B0B0B0h, #FF8000h,
#905000h, #400808h,
#00FF00h, #004060h,
#003000h, #00FFFFh,
#80D0FFh, #0000FFh,
#000080h, #400080h,
#404040h, #000000h};
// plotting
s:=SIZE(l6);

FOR i FROM -b TO b STEP (2*b)/g DO
FOR j FROM -b TO b STEP (2*b)/g DO 
k:=0;

REPEAT
k:=k+1;
IF k==1 THEN
z:=(i,j); 
ELSE
z: = z^2 + c;
END;
UNTIL ABS(z)>2 OR k==s;

l:=l6(k);
PIXON(i,j,l);
END;
END;

WAIT(0);
END;

Examples

B = 1, G = 500, C = 0.38 + 0.008i

B = 1, G = 500, C = -0.11 -0.8i

Have fun!  Explore the possibilities,

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.





Thursday, May 23, 2019

Review: EAI-350 Scientific Calculator

Review:  EAI-350 Scientific Calculator 



Basic Facts

Type:  Scientific
Display:  Two Line:  entry on the top and result on the bottom
Power:  Solar with battery backup, LR44
Memory Registers: 8:  A,B,C,D,E,F,X,Y,M
Price: $8.67, sold online:  https://www.eaieducation.com/Product/560440/CalcPal%C2%AE_EAI-350_Scientific_Calculator.aspx
Documentation:  2 fold out manuals, one full manual and one short manual detailing the more advanced functions

Keypad

The EAI-350 scientific calculator is similar to the Casio fx-991MS and fx-115MS.  The differences:

The keys are blue, white, and lime green.  The case is dark silver.  The keys work fine, but I don't think they are as solid as the Casio calculators.  The biggest flaw came in the keypad, I had to press the up on the keypad several times and with a firm touch.  This is not a deal breaker, just be something to aware of. 

Modes

The EAI-350 has a rich set of features.    The modes include:

*  Compute mode (general math mode)
*  Complex Mode  (arithmetic, x^2, √, Abs, arg, rectangular/polar conversions)
*  Statistics (single variable, Linear Regression, Logarithmic Regression, Exponential Regression, Power Regression, Inverse Regression, Quadratic Regression)
*  Base Operations (Decimal, Hexadecimal, Octal, Binary)
*  Equation Mode (2 x 2 and 3 x 3 linear systems, quadratic equations, cubic equations)
*  Matrices (3 matrices, up to 3 x 3)
*  Vectors (3 vectors, up to 3 elements)

One thing that I noted is that the logic functions only include AND, OR, and XOR.  Entering negative integers will require the use of the minus ([ - ]) key. 

Fractions

Fractions can be entered and calculated.  Results are simplified.  Fractions can be displayed as mixed fractions or improper fractions. 

Calculus

Calculus functions of the EAI-350 include the numeric integral, numeric derivative, evaluation, and a solve function.  The solve function can solve for any variable. 

Engineering Symbols

You can attach engineering symbols (powers of 10) to numbers from f (10^-15) to T (10^12). 

Constants and Conversions

The EAI-350 has 40 sets of conversions and 40 scientific constants.  You will need the fold out manual because calling the conversion and constants by numerical code.  The manual states that the constants are based on the 1992 ISO Standard and 1998  CODATA recommended values.  (a little dated)

Verdict

The EAI-350 is a good alternative to the Casio calculators.  The keyboard could be more solid, but it works.  I wish I could adjust the screen contrast, so be aware of where the calculator is operated because the screen can reflect. 

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.

Monday, May 20, 2019

Intensity/Illumination, Days Since Jan. 1, Derivatives: HP 20S and 21S

Intensity/Illumination, Days Since Jan. 1, Derivatives: HP 20S and 21S

Table of contents

1.  Intensity and Illumination
2.  Days Since January 1
3.  Numerical Derivative

Disclaimer: I believe the key codes for the programs in this blog entry are the all the same even though the HP 20S and HP 21S have slightly different codes.  Format:   Step  Key: Key Code.  I took turns programming the HP 20S and HP 21S.

1.  Intensity and Illumination

The follow equation relates the luminous intensity (measured in candelas, cd) and illuminance (measured in lux) of a light source.  The equation assumes the light source radiates a spherical matter.

E = I / R^2

E = illuminance
I = luminous intensity
R = radius of the sphere's light (meters)

LBL A:  Solve for E
LBL B:  Solve for I
LBL C:  Solve for R

Registers:
R0 = E
R1 = I
R2 = R

Store the following values in the register and execute the appropriate label.

Program:

01  LBL A:  61,41,A
02 RCL 1:  22, 1
03 ÷:  45
04 RCL 2:  22, 2
05 x^2:  51, 11
06 =: 74
07 STO 0:  21, 0
08 R/S:  26
09 LBL B:  61,41,B
10  RCL 0: 22,0
11  *:  55
12  RCL 2: 22,2
13  x^2:  51,11
14  =:  74
15  STO 1: 21, 1
16  R/S:  26
17  LBL C: 61,41,C
18  RCL 1: 22,1
19 ÷: 45
20 RCL 0: 22,0
21  =:  74
22 √:  11
23 STO 2: 21, 2
24 R/S:  26

Example 1:
R1 = I = 400, R2 = R = 2.
Solve for E,  XEQ A returns 100

Example 2:
R0 = E = 180, R2 = R = 3
Solve for I, XEQ B returns 1620

Example 3:
R1 = I =420, R0 = E = 195
Solve for R, XEQ C returns 1.467598771

2.  Days Since January 1

Calculate the number of days since January 1.  For more information, please see:  http://edspi31415.blogspot.com/2019/03/ti-84-plus-and-hp-41c-number-of-days.html

Input:
R1:  day
R2: month
R3: 0 if we are working in a non-leap year, 1 if we are working in a leap year

Output:
R4:  number of days since January 1

Program:

01 LBL A: 61,41,A
02 RCL 1:  22,1
03 STO 4: 21, 4
04 3:  3
05 5:  5
06 STO - 4:  21,65,4
07 RCL 2: 22,2
08  INPUT:  31
09  2:  2
10  x ≤ y?:  61,42
11  GTO 2:  51,41,2
12  RCL 2: 22,2
13  *:  55
14  3:  3
15  0:  0
16  . : 73
17 6:  6
18  +:  75
19  1:  1
20  .  : 73
21  6:  6
22  =:  74
23  IP:  51, 45
24  STO + 4:  21,75,4
25  RCL 3:  22,3
26  STO + 4:  21,75,4
27  RCL 4: 22,4
28  RTN:  61, 26
29  LBL 2:  61,41,2
30  RCL 2:  22,2
31   *:  55
32  3:  3
33  0:  0
34  .  : 73
35  6:  6
36  +:  75
37  3:  3
38  6:  6
39  8:  8
40:  .  : 73
41  8:  8
42 =: 74
43  IP:  51,45
44  STO + 4:  21,75,4
45  3:  3
46  6:  6
47  5:  5
48  STO - 4:  21,65,4
49  RCL 4:  22,4
50  RTN:  61,26

Example 1:
1/1/2019 - 5/7/2019  (non-leap year)
R1:  7,  R2:  5,  R3:  0
Result:  R4 = 126

Example 2:
1/1/2020 - 11/14/2020  (leap year)
R1:  14,  R2:  11, R3:  1
Result:  R4 = 318

3.  Numerical Derivative

f'(x0) ≈ ( f(x0 + h) - f(x0 - h) ) / ( 2*h )

x = point
h = small change of x, example h = 0.0001

LBL A:  Main Progam
LBL F:  f(X), where R0 acts as X

Input variables:
R1 = h
R2 = point x0

Used variables:
R0 = x   (use R0 for f(x), LBL F)

Calculated Variables:
R3 = f'(x)

Radians mode will be set.

Program:

01  LBL A:  61,41A
02  RAD:  61,24
03  RCL 2:  22,2
04  +:  75
05  RCL 1:  22, 1
06  =:  74
07  STO 0:  21,0
08 XEQ F:  41,F
09  STO 3:  21, 3
10  RCL 2: 22,2
11 -:  65
12 RCL 1: 22,1
13 =:  74
14 STO 0: 21,0
15 XEQ F:  41,F
16 STO - 3:  21,65,3
17 2:  2
18 STO ÷ 3:  21,45,3
19  RCL 1:  22,1
20 STO ÷ 3: 21,45,3
21  RCL 3:  22,3
22 R/S:  26
23 LBL F:  61,41,F
...
xx  RTN:  61,26  (end f(X) with RTN)

Example:  e^x * sin x

LBL F
RCL 0
e^x
*
RCL 0
SIN 

RTN

R1 = 0.0001
R2 = x0 = 0.03
Result:  1.060899867

R1 = 0.0001
R2 = x0 = 1.47
Result:  4.7648049


Note:  I am going on vacation this week and I have jury duty in June. So far, I have blog entries scheduled to be posted throughout June 22.  I plan to have a weekly post every Saturday in June.  - E

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.

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