Sunday, January 13, 2019

HP Prime, TI-84 Plus, and Casio fx-CG 50: Julian Date/Gregorian Calendar Conversions

HP Prime, TI-84 Plus, and Casio fx-CG 50:  Julian Date/Gregorian Calendar Conversions

Introduction

One conversion that is common in astronomy is to convert dates from our Gregorian calendar (the most commonly used day-to-day calendar) to a Julian Date Number, and visa versa.

JD:  Convert Gregorian Date to Julian Date Number

GREG:  Convert Julian Date Number to Gregorian Date

The Julian date number of 2451545 corresponds to January 1, 2000.

Gregorian Date to Julian Date Number

HP Prime Program JD:  Gregorian Date to Julian Date Number
Arguments:  four digit year, month, day
JD(y,m,d)

EXPORT JD(y,m,d)
BEGIN
// Gregorian to Julian
// year, month, day
// 2019-01-12 EWS
//  Wikipedia
LOCAL x0:=IP((m-14)/12);
LOCAL x1:=IP(((1461*(y+4800+x0))/4));
LOCAL x3:=IP(367*(m-2-12*x0)/12);
LOCAL x5:=IP((y+4900+x0)/100);
LOCAL x6:=IP(3*x5/4);
LOCAL j:=x1+x3-x6+d-32075;
RETURN j;
END;

TI-84 Plus Program JD:  Gregorian Date to Julian Date Number

"GREGORIAN TO JULIAN"
"2019-01-13 EWS"
Input "YEAR: ",Y
Input "MONTH: ",M
Input "DAY: ",D
iPart((M-14)/12)→X
iPart(((1461*(Y+4800+X))/4))→A
iPart(367*(M-2-12*X)/12)→B
iPart((Y+4900+X)/100)→C
iPart(3*C/4)→C
A+B-C+D-32075→J
Disp "JD: ",J

Casio fx-CG50 Program JD:  Gregorian Date to Julian Date Number
This version can be typed in directly in the calculator (not a text file)

"GREGORIAN TO JULIAN"
"2019-01-19 EWS"
"YEAR?"→Y
"MONTH"?→M
"DAY"?→D
Int ((M-14)÷12)→X
Int (((1461×(Y+4800+X))÷4)) →A
Int (367×(M-2-12×X)÷12) →B
Int ((Y+4900+X) ÷ 100) →C
Int (3×C÷4)→C
A+B-C+D-32075→J
ClrText
Locate 1,1,"JD"
Locate 1,2,J

Julian Date Number to Gregorian Date

HP Prime Program GREG:  Julian Date Number to Gregorian Date
Argument:  Julian Date Number
GREG(j)

EXPORT GREG(j)
BEGIN
// Julian to Gregorian
// Wikipedia
// 2019-01-12 EWS
LOCAL x1:=IP((4*j+274277)/146097);
LOCAL x2:=IP(x1*3/4);
LOCAL f:=j+1401+x2-38;
LOCAL E:=4*f+3;
LOCAL G:=IP((E MOD 1461)/4);
LOCAL H:=5*G+2;
LOCAL D:=IP((H MOD 153)/5)+1;
LOCAL M:=((IP(H/153)+2) MOD 12)+1;
LOCAL Y:=IP(E/1461)-4716+IP((12+2-M)/12);
RETURN {Y,M,D};
END;

TI-84 Plus Program GREG:  Julian Date Number to Gregorian Date

"JULIAN TO GREGORIAN"
"2019-01-13 EWS"
Input "JD: ",J
iPart((4*J+274277)/146097)→X
iPart(X*3/4)→X
4*(J+1401+X-38)+3→E
5*iPart(remainder(E,1461)/4)+2→H
iPart(remainder(H,153)/5)+1→D
remainder(iPart(H/153)+2,12)+1→M
iPart(E/1461)-4716+iPart((12+2-M)/12)→Y
Disp "YEAR, MONTH, DAY:",Y,M,D

Casio fx-CG50 Program GREG: Julian Date Number to Gregorian Date 
This version can be typed in directly in the calculator (not a text file)

"JULIAN TO GREGORIAN"
"2019-01-13 EWS"
"JD"?→J
Int ((4 ×J+274277) ÷146097) →X
Int (X ×3 ÷4) →X
4 ×(J+1401+X-38)+3 → E
5 × Int( MOD(E,1461) ÷ 4)+2 → H
MOD(Int  (H ÷153)+2,12)+1 →M
Int (E ÷1461) -4716+Int ((12+2-M) ÷12) → Y
ClrText
Locate 1,1,"YEAR, MONTH, DAY"
Locate 1,2,Y
Locate 1,3,M
Locate 1,4,D

Examples

Gregorian Date:  1988, October 31
JD:  2447466

Gregorian Date:  1999, January 11
JD:  2451190

Gregorian Date:  2017, March 21
JD:  2457834


Source:

"Julian Day"  Wikipedia.  Edited (when retrieved) November 19, 2018.  Retrieved January 11, 2019.  https://en.wikipedia.org/wiki/Julian_day

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.  Please contact the author if you have questions.

TI-84 Plus CE: Lower Case Letters without Assembly

TI-84 Plus CE:  Lower Case Letters without Assembly

Letter Case Letters without Assembly Programs

It is possible to put letter case letters in TI-84 Plus CE programs without running an assembly program.  This is going to require the use of the TI Connect CE computer program.  I am using the Windows version and hopefully my assumption will be correct that this technique will work on the Mac version as well.

Note: You will need the TI-84 Plus CE (the newest, thinnest TI-84) for this.  The TI-84 Plus CE has a back-lit, color screen. 

Steps:

1.  Connect your TI-84 Plus CE to your computer.

2.  Start up the TI Connect CE computer program.

3.  Select PROGRAM EDITOR on the left hand menu.  Next, click on New Program (the folder with the plus key) on the right.  (You can also edit programs but we'll create a new program for this demo.)

4.  Name your program.  For this example, I am going to name it DEMO.  The name can be in lower case, but the letters in the name will become upper case when the program is transferred to the TI-84 Plus CE. 

5.  Type your program.  You can use the catalog on the left to insert commands.  The Keypad section is where you insert pi (π), the store arrow (→), the square root function (√), the exponential function (e^), and the imaginary indicator to build complex numbers (i = √-1). 

We will need to type the program in the Program Editor software, not directly on the TI-84 Plus CE calculator. 

This is my demo program.

TI-84 PLUS CE Program DEMO

Disp "This is a test program."
Input "a: ",A
Input "b: ",B
A^2+B^2→C
A^3+B^3→D
ClrHome
Disp "Results:","a^2+b^2=",C
Disp "a^3+b^3=",D

Notes:

*  Variables must still be in uppercase. 

*  You can use lower case letters with programming through the software, but Unicode characters do not transfer over. 

6.  Save your program (if you want). 

7.  If you have not already, turn on the TI-84 Plus CE.  Then send the program to your TI-84 Plus CE.  There are three ways to accomplish this task (Windows):

* Click on the Send Program to Connect Calculator icon.
* Key Ctrl+E.
* Under the Actions menu, click on the Send to Calculators menu.

If the program is accepted, you program is transferred.

8.  Run the program on your calculator.



Limitations

*  Using lower case in this method requires editing on the program software, not the calculator itself.

*  You must still use single upper case letters for variables.

*  I have not been able to do Unicode characters with this method, as the calculator program will not transfer.

*  This lower case is useful for displaying messages and prompts. 

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.  Please contact the author if you have questions.

Thursday, January 10, 2019

HP 42S Polynomial Operations

HP 42S Polynomial Operations

Note: These programs presented in today's blog are can also be programmed on the Free42 app and the DM 42.  The default setting, 25 memory registers, is assumed to be set.  The programs are written use R24 as a counter. 

This program uses indirect storage (R24).  The maximum order is 23.

HP 42S Program SPOLY

This program asks for the order of a polynomial and then asks the user to store the coefficients.  The order of registers are coefficients of powers of x in descending order from n to 0. 

For example, for a cubic polynomial, the coefficients are stored as such:
R01 = coefficient of x^3
R02 = coefficient of x^2
R03 = coefficient of x
R04 = constant coefficient

Program:

00 { 67-Byte Prgm }
01▸LBL "SPOLY"
02 CLX
03 "ORDER?"
04 PROMPT
05 STO 00
06 IP
07 1
08 +
09 1ᴇ-3
10 ×
11 1
12 +
13 STO 24
14▸LBL 00
15 "X↑"
16 RCL 00
17 RCL 24
18 IP
19 -
20 1
21 +
22 ARCL ST X
23 ├" ="
24 CLX
25 PROMPT
26 STO IND 24
27 ISG 24
28 GTO 00
29 "DONE"
30 AVIEW
31 RTN
32 END

Example:  Store the polynomial p(x) = 2*x^3 - x^2 + 5*x + 7

Keystrokes:  [ XEQ ] (SPOLY)
"ORDER?" 3 [ R/S ]
"X↑3.0000=" 2 [R/S]
"X↑2.0000=" 1 [ +/- ] [R/S]
"X↑1.0000=" 5 [R/S]
"X↑0.0000=" 7  [R/S]
"DONE"

Results
R01 = 2.0000
R02 = -1.0000
R03 = 5.0000
R04 = 7.0000

HP 42S Program HORNER

The HORNER evaluates the polynomial p(x).  The assumes that the order of registers are coefficients of powers of x in descending order from n to 0.  The user is asked about the order of the polynomial and the value of x.

Program:

00 { 65-Byte Prgm }
01▸LBL "HORNER"
02 CLX
03 "X?"
04 PROMPT
05 STO 00
06 CLX
07 "ORDER?"
08 PROMPT
09 IP
10 1ᴇ-3
11 ×
12 1
13 +
14 STO 24
15 RCL 00
16 RCL× IND 24
17 ISG 24
18▸LBL 01
19 RCL+ IND 24
20 RCL× 00
21 ISG 24
22 GTO 01
23 RCL+ IND 24
24 "P(X)="
25 AVIEW
26 RTN
27 .END.

Example:  Let p(x) be the polynomial, p(x) = 2*x^3 - x^2 + 5*x + 7
Calculate p(-3).

The coefficients are have already been stored (from last example).
R01 = 2.0000
R02 = -1.0000
R03 = 5.0000
R04 = 7.0000

Keystrokes:  [XEQ] (HORN)
"X?" 3 [ +/- ] [ R/S ]
"ORDER?" 3  [ R/S ]

Result:  -71.0000

HP 42S Program DX_PX

This program calculates coefficients of the derivative of the polynomial p(x), using the form:

d/dx x^n = n * x^(n-1)

The order of registers are coefficients of powers of x in descending order from n to 0. 

Program:

00 { 79-Byte Prgm }
01▸LBL "DX_PX"
02 CLX
03 "ORDER?"
04 PROMPT
05 STO 00
06 IP
07 1ᴇ-3
08 ×
09 1
10 +
11 STO 24
12▸LBL 02
13 RCL IND 24
14 RCL 00
15 RCL 24
16 IP
17 -
18 1
19 +
20 ×
21 STO IND 24
22 "X↑"
23 RCL 00
24 RCL 24
25 IP
26 -
27 ARCL ST X
28 X<>Y
29 AVIEW
30 STOP
31 ISG 24
32 GTO 02
33 1
34 RCL+ 00
35 STO 24
36 CLX
37 STO IND 24
38 "DONE"
39 AVIEW
40 RTN
41 .END.

Example:  Calculate the derivative of p(x) = 2*x^3 - x^2 + 5*x + 7.  Assume that coefficients from the previous example.

Keystrokes:  [ XEQ ] (DX_PX)
"ORDER?" 3 [R/S]

Results:
"X↑2.0000=" 6.0000 [R/S]
"X↑1.0000=" -2.0000 [R/S]
"X↑0.0000=" 5.0000  [R/S]
"DONE"

dp/dx = 6*x^2 - 2*x + 5

Registers:
R1 = 6.0000
R2 = -2.0000
R3 = 5.0000
R4 = 0.0000

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.  Please contact the author if you have questions.

Tuesday, January 8, 2019

Review: Casio DJ-120D

Review:  Casio DJ-120D

Type:  Desktop
Number of Digits: 12
Power:  Solar with Battery Backup (LR44)
Operating Mode: Chain




Large Size Calculator

This calculator is huge.  The keyboard is nice and large.  The keys are large, that you can easily rapidly type calculations.  The screen is also large, making the numbers the screen easy to read. 

The keyboard has a double zero ( [00] ) and a a triple zero ( [000] ) key, you can enter large numbers rapidly. 

Display Options

There are many display options, primarily by two switches.  One switch sets the number of decimal points (0 through 4 and add mode).  The other switch determines how numbers are rounded (float (not at all), cut (truncated), up (round up), and 5/4 (regular rounding)). 

You can set additional displays modes, such as comma or decimal point for fractional marks using the [ AC ]/[DISP] key and scrolling through the options.  You actually make two settings.  Those two settings get toggled with the [DISP] key in regular calculator mode. 

Add Mode

Add mode allows numbers to be added and subtracted in "dollars and cents" (divided by 100).  The automatic division by 100 is not affected by multiplication and division.  Add Mode is activated when the rounding mode is set to either cut, up, or 5/4. 

Reviewing and Editing Calculations

The DJ-120D has a 150 step memory.  All the arithmetic calculations are stored in each step.  Historical calculations are finalized by either pressing the equals sign [ = ] or the percent sign [ % ].  Calculations can be reviewed by using the arrow keys, the [GO TO] key, or the [AUTO REVIEW] key. 

When you are using the review feature, the display may not be intuitive.  For the arithmetic and percent sign, the function is read on the top of screen.  When you conclude a calculation, the display will show the equals sign on the left side of the screen.  This takes getting used to. 

Example:  Reviewing the Calculations

1120 [+ ]
365 [ - ]
630 [ = ]  

The result is 855.

Review of the calculations:

01  REV  1120 +
02  REV  365 -
03  REV  =  630
04  REV  ANS 855

Note how the equals sign is on the left, not on the right.  It may be confusing to read at first.  Also, square root operations affects only the number in history, the square root function is not recorded as a step. 

While editing operations, you can correct steps.  For example, I change the first step to 1210 +. 

[GO TO] 1 [GO TO]
[CORRECT] 1210 [ + ] [CORRECT]

Reviewing the steps:

01  REV  1210 +
02  REV  365 -
03  REV  =  630
04  REV  ANS 945

The Grand Total Feature

The DJ-120D has a Grand Total feature.  This accumulates every calculation that is completed by pressing the equals key.  You can recall the grand total by pressing [ GT ].   The grand total is a separate memory register.

Example:

46 [ + ] 43 [ = ]  (89)
100 [ - ] 57 [ = ]  (43)
5 [ * ] 9 [ = ]  (45)
[GT] returns 177.  (89 + 43+ 45)

The all clear key [AC] (also ON) clears both the grand total and history.

The Markup Key

The markup key [MU] performs the operation x/(1 - p%). 

Verdict

I love the large keyboard and the display.  I would recommend this calculator for students who are learning math (the review function makes it useful to review math calculations), and office professionals.

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.  Please contact the author if you have questions.

Saturday, January 5, 2019

Solar Scientific Calculators: Dealing with Integrals with Infinite Limits

Solar Scientific Calculators:  Dealing with Integrals with Infinite Limits

Integrals with Infinite Limits

Today's post deals with integrals with infinite limits in the forms:

∫( f(x) dx, x = a to x = ∞)

∫( f(x) dx, x = -∞ to x = ∞)

∫( f(x) dx, x = -∞ to x = a)

One method to deal with these integrals, as suggested by W.A.C. Mier-Jedrzejowicz Ph. D. (see the source), is to use the substitution

x = tan θ

Then:

dx = dθ/cos^2 θ

and θ = atan x.

Also, as x approaches π/2, tan x approaches +∞.

And, as x approaches -π/2, tan x approaches -∞.

With the substations, let's test four integrals on four solar-powered scientific calculators:

1.  Casio fx-991EX Classwiz
2.  Sharp EL-W516T
3.  Texas Instruments TI-36X Pro
4.  Casio fx-115ES Plus

Set the calculator to radians mode. 




Example 1:  ∫(1/x^2 dx, x = 1 to x = ∞) = 1

∫(1/x^2 dx, x = 1 to x = ∞)

with the substitutions x = tan θ and dx = dθ/(cos^2 θ):

∫( 1/tan^2 θ * dθ/cos^2 θ, θ = atan 1 to θ = π/2)

∫( 1/sin^2 θ * dθ, θ = atan 1 to θ = π/2)

We can evaulate the integral straight away.  Here are the results:

1.  Casio fx-991EX Classwiz
Time: 1.37 seconds
Answer: 1

2.  Sharp EL-W516T
Time: 38 seconds
Answer: 1

3.  Texas Instruments TI-36X Pro
Time: 4.5 seconds
Answer: 1

4.  Casio fx-115ES Plus
Time: 4.2 seconds
Answer: 1

A promising start.

Example 2:  ∫(e^(-0.5*x^2), x = 0 to x = ∞) ≈ 1.25331413732

∫(e^(-0.5*x^2), x = 0 to x = ∞)

with the substituions, this becomes:

∫(e^(-0.5 * tan^2 θ)/cos^2 θ dθ, θ = atan 0 to θ = π/2)

atan 0 = 0

But look at the denominator, we have cos^2 θ.  Since cos^2 π/2 = 0, there will be a problem.  Let's use an approximation of π/2 of 1.5708.

∫(e^(-0.5 * tan^2 θ)/cos^2 θ dθ, θ = 0 to θ = 1.5708)

Here are the results:

1.  Casio fx-991EX Classwiz
Time: 15.4 seconds
Answer: 1.253314137

2.  Sharp EL-W516T
Time: 1 minute, 8 seconds
Answer: errors out

3.  Texas Instruments TI-36X Pro
Time: 36 seconds
Answer: 1.253314138

4.  Casio fx-115ES Plus
Time: 1 minute, 6.8 seconds
Answer: 1.253314137

Example 3:  ∫(x^2*e^-x dx, x = 0 to x = ∞) = 2

∫(x^2*e^-x dx, x = 0 to x = ∞)

with the substitutions and simplification, we get:

∫( (sin^2 θ * e^(-tan θ))/cos^4 θ dθ, θ = 0 to θ = π/2)

Like the last situation, there is a potential problem with the denominator.  Let's see if we can use an approximation of π/2, this time using 1.57 in hopes to cut the calculation time down.

∫( (sin^2 θ * e^(-tan θ))/cos^4 θ dθ, θ = 0 to θ = 1.57)

Here are the results:

1.  Casio fx-991EX Classwiz
Time: 27 seconds
Answer: 2

2.  Sharp EL-W516T
Time: 1 minute, 34 seconds
Answer: 1.999999999

3.  Texas Instruments TI-36X Pro
Time: 1 minute, 9 seconds
Answer: 2

4.  Casio fx-115ES Plus
Time: 1 minute, 6.8 seconds
Answer: 1.253314137

Example 4:  ∫( e^-x/x^2 dx, x = 1 to x = ∞) ≈ 0.148495506776

∫( e^-x/x^2 dx, x = 1 to x = ∞)

with the substitutions and simplification, we get:

∫( e^(-tan θ)/sin^2 θ dθ, θ = 0 to θ = π/2)

I'm going to use the 1.57 approximation again and set the integral as:

∫( e^(-tan θ)/sin^2 θ dθ, θ = 0 to θ = 1.57)

Here are the results:

1.  Casio fx-991EX Classwiz
Time: errors out immediately
Answer: N/A

2.  Sharp EL-W516T
Time: 1 minute, 6 seconds
Answer: error

3.  Texas Instruments TI-36X Pro
Time: 7 seconds
Answer: 0.148495519

4.  Casio fx-115ES Plus
Time: errors out after 1 second
Answer: N/A

Some Observations

1.  Not all calculations of improper integrals will be successful.

2.  Out of the four calculators tested, from the four calculations:  the Casio fx-991ES is the fastest, but I found the most successful with the Texas Instruments TI-36X Pro.

3.  Be ready to spend a little for calculations by using this method.

Source:

Mier-Jedrzejowic, W.A.C. Ph.D.  Extend Your 41  London, UK 1985  ISBN 0-9510733-0-03

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.  Please contact the author if you have questions.

Friday, January 4, 2019

HP Prime and HP 42S: Noise Figure and Noise Voltage

HP Prime and HP 42S:  Noise Figure and Noise Voltage

Notes:  The programs for the HP 42S format are designed to work with the HP 42S's solver.  The programs were created using Thomas Okken's Free42, and should also be compatible with the Swiss Micros DM42.

Noise Figure

Given system temperature (in Kelvins), this program calculates the noise figure (in Decibels), which describes the noise performance of an amplifier.  The noise figure is described as the difference between the noise output of an actual receiver to an ideal, noiseless receiver.  A noiseless receiver is said to have a resistor operating at room temperature, 290 K (about 16.85°C or 62.33°F). The lower the noise figure, the better.

Formula:

F = 10 * log(T/290 + 1)

where:

F = noise figure (dB)
T = system temperature (K)

HP Prime Program Function:  NOISEDB

EXPORT NOISEDB(T)
BEGIN
// Noise Figure in dB
// Input: T: Temperature (K)
// 2019-01-04 EWS
10*LOG(T/290+1);
END;

HP 42S Program for Solver:  NSEFG

00 { 35-Byte Prgm }
01▸LBL "NSEFG"
02 MVAR "F"
03 MVAR "T"
04 RCL "T"
05 290
06 ÷
07 1
08 +
09 LOG
10 10
11 ×
12 RCL "F"
13 -
14 END

Example (Fix 4):

Input:  T = 57.8°F, convert it to Kelvins, enter 287.4833 K (approximately)
Result:  F = 2.9914 dB

Noise Voltage

Given the noise bandwidth (in Hertz) and the resistance (in Ω), calculate the open-circuit voltage (in RMS volts).

Formula:

e_n = √(1.6*10^-20 * B * R)

where:

e_n = open circuit voltage noise (RMS volts)
B = bandwidth (Hz)
R = resistance (Ω)

HP Prime Program Function: NOISEVOLT

EXPORT NOISEVOLT(b,r)
BEGIN
// Noise Voltage in V
// Input: B=bandwidth (Hz)
// Input: R=resistor (Ω)
// input numbers only
√(1.6ᴇ−20*b*r);
END;

HP 42S Program for Solver:  NSEVT

00 { 37-Byte Prgm }
01▸LBL "NSEVT"
02 MVAR "B"
03 MVAR "R"
04 MVAR "En"
05 16ᴇ-21
06 RCL× "B"
07 RCL× "R"
08 SQRT
09 RCL- "En"
10 .END.

Example (FIX 4):

Input:  B = 31,000 Hz, R = 950 Ω
Result:  e_n = 6.8644e-7 V

Sources: 

Ball, John A.  Algorithms For RPN Calculators  John Wiley & Sons: New York  1978.  ISBN 0-471-03070-8

Eddie

All original content copyright, © 2011-2018.  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.  Please contact the author if you have questions.

Wednesday, January 2, 2019

HP Prime and Casio fx-5800p: Rational Binomial Coefficients

HP Prime and Casio fx-5800p:  Rational Binomial Coefficients

Introduction

Let p be a rational fraction, p = num/dem.  The rational binomial coefficients of order n are defined by:

B_0(p) = 1

B_n(p) = COMB(p, n) = ( p * (p - 1) * (p - 2) * (p - 3) * ... * (p - n + 1) ) / n!

There are algorithms, but the program RATBIN uses the definition. 

HP Prime Program RATBIN

Arguments:  rational fraction, order

EXPORT RATBIN(p,n)
BEGIN
// 2018-12-26 EWS
// p-q, n
// Rational Binomial Coefficient
LOCAL X;
IF n==0 THEN
RETURN 1;
ELSE
IF n==1 THEN
RETURN p;
ELSE
RETURN QPI(ΠLIST(p-MAKELIST(X,X,0,n-1))/n!);
END;
END;
END;

* Note: the result is not always a fraction, but you can convert the answer to fraction by pressing [ a b/c ]

Casio fx-5800p Program RATBIN

For fractional results, use the fraction button [  []/[] ].

"2018-12-26 EWS"
"FRACTION"? → P
"ORDER?" → N
If N=0
Then
0
IfEnd
If N=1
Then
1
IfEnd
If N>1
Then
Prod (P-Seq(X,X,0,N-1,1)) ÷ N! → Q
Q
IfEnd

Examples

b_2(1/2) = -1/8

b_3(1/2) = 1/16

b_4(1/2) = -5/128

b_5(1/2) = 7/256

Source:

Henrici, Peter.  Computational Analysis With the HP-25 Calculator  A Wiley-Interscience Publication. John Wiley & Sons: New York 1977 .  ISBN 0-471-02938-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.  Please contact the author if you have questions.

Tuesday, January 1, 2019

Celebrating the New Year With 2019: 19 Ways to Mathematically Express 2019

Celebrating the New Year With 2019

HAPPY NEW YEAR!!!



19 Ways to Mathematically Express 2019

2019 = 3 * 673  (Prime Factorization)

2019 = 2^10 + 2^9 + 2^8 + 2^7 + 2^6 + 2^5 + 2 + 1

2019 = 3 + 2 * (3^6 + 3^5 + 3^3 + 3^2)

2019 = 42^2 + 4^4 - 1

2019 = 41^2 + 7^3 - 5

2019 = 4^5 + 3^6 + 2^8 + 10

2019 = 11^3 + 5^4 + 2^6 - 1

2019 = 12^3 + 17^2 + 2

2019 = int(10^3.3) + int(e^3) + 2^2   (e = 2.718281828...,  int: integer function)

2019 = 2 * (10^3 + 9.5)

2019 = 3^7 - 13^2 + 1

2019 = 4 * 505 - 1

2019 = 2 * 6! + 4 * 5! + 16 * 3! + 3

2019 = (10^4 + 19 * 5) / (2^2 + 1)

2019 = (13^4 - 12^3 - 9^3 + 12^2 - 1) / (2^2 + 3^2)

2019 = (2^13 + 3^8 + 4^5 + 5^3 + 6^3 + 34) / 8

2019 = 50 * 19 + 50 * 18 + 9 * 17 + 16

2019 = 25 * 19 + 25 * 18 + 26 * 13 + 71 * 11

2019 = √(4 * 10^6 + 7 * 10^4 + 6 * 10^3 + 3 * 10^2 + 6 * 10 + 1)




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.  Please contact the author if you have questions.

Sunday, December 30, 2018

TI-84 Plus Fast Fourier Transform

TI-84 Plus Fast Fourier Transform

HAPPY NEW YEAR!

Introduction

The program FFT1 performs the fast Fourier transform of discrete data points named in List 1 (small x, signal at time points) to  List 2 (big X, frequency), using the formula:

X_k = ∑( x_n * e^(-i*2*π*k*m)/n from m = 0 to n - 1)

For the set of n signals.

The program IFFT1, the Inverse Fast Fourier Transform, reverses the process (big X to small x, List 2 to List 1).

x_k = 1/n * ∑( x_n * e^(i*2*π*k*m)/n from m = 0 to n - 1)


TI-84 Plus Program FFT1

"FFT VERSION 1"
"EWS 2018-12-09"
Input "SMALL X LIST:",L₁
"SETUP"
dim(L₁)→N
L₁→L₂
a+bi
Radian
"LOOP"
For(M,0,N-1)
0→T
For(K,0,N-1)
T+L₁(K+1)*e^(-­2*π*i*K*M/N)→T
End
T→L₂(M+1)
End
Pause L₂

TI-84 Plus Program IFFT1

"IFFT VERSION 1"
"EWS 2018-12-09"
Input "BIG X LIST:",L₂
"SETUP"
dim(L₂)→N
L₂→L₁
a+bi
Radian
"LOOP"
For(M,0,N-1)
0→T
For(K,0,N-1)
T+L₂(K+1)*e^(2*π*i*K*M/N)→T
End
T/N→T
T→L₁(M+1)
End
Pause L₁

Example 

FFT Example:
L1 = {2i, 1+i, 3}
Result (Fix 4):   {4.0000+3.0000*i, -1.1340+3.2321*i, -2.8660-0.2321*i}

Inverse FFT Example:
L2 = {0.5, -0.7i, 0.9+0.3i}
Result (Fix 4): {0.4667-0.1333*i, 0.3053-0.1931*i, -0.2720+0.3265*i}

Trigonometric Version

For calculators that do not handle complex numbers, here are the sample code that can handle FFT and IFFT.  The techinque here is to use a pair of lists, one for the real parts, the other for imaginary parts.  Example:  {2, 3+3i, -2i} get split into {2, 3, 0} and {0, 3, -2}.

The following identities and calculation are used:

e^(i*θ) = cos θ + i * sin θ

(a + b*i)*e^(-i*θ)
=  (a + b*i) * (cos θ - i * sin θ)
=  a * cos θ +  i * b * cos θ - i * a * sin θ + b * sin θ
= (a * cos θ + b * sin θ) + i * (b * cos θ - a * sin θ)

(a + b*i)*e^(i*θ)
=  (a + b*i) * (cos θ + i * sin θ)
=  a * cos θ +  i * b * cos θ + i * a * sin θ - b * sin θ
= (a * cos θ - b * sin θ) + i * (b * cos θ + a * sin θ)

where θ = 2*π*m*k/n 

TI-84 Plus Program FFT1

"FFT VERSION 2"
"EWS 2018-12-10"
Disp "SMALL X","L₁ + I*L₂"
Input "REAL: ",L₁
Input "IMAG: ",L₂

"SETUP"
dim(L₁)→N
L₁→L₃
L₂→L₄
Radian
"LOOP"
For(M,0,N-1)
0→S
0→T
For(K,0,N-1)
2*π*M*K/N→θ
S+L₁(K+1)*cos(θ)+L₂(K+1)*sin(θ)→S
T+L₂(K+1)*cos(θ)-L₁(K+1)*sin(θ)→T
End
S→L₃(M+1)
T→L₄(M+1)
End
Disp "REAL = L₃","IMAG = L₄"

TI-84 Plus Program IFFT1

"IFFT VERSION 2"
"EWS 2018-12-10"
Disp "BIG X","L₃ + I*L₄"
Input "REAL: ",L₃
Input "IMAG: ",L₄
"SETUP"
dim(L₃)→N
L₃→L₁
L₄→L₂
Radian
"LOOP"
For(M,0,N-1)
0→S
0→T
For(K,0,N-1)
2*π*M*K/N→θ
S+L₃(K+1)*cos(θ)-L₄(K+1)*sin(θ)→S
T+L₄(K+1)*cos(θ)+L₃(K+1)*sin(θ)→T
End
S/N→S
T/N→T
S→L₁(M+1)
T→L₂(M+1)
End
Disp "REAL = L₁","IMAG = L₂"

Source:  

"An Interactive Guide To The Fourier Transform"  Better Explained.  Retrieved December 9, 2018.  https://betterexplained.com/articles/an-interactive-guide-to-the-fourier-transform/

All original content copyright, © 2011-2018.  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.  Please contact the author if you have questions.


Friday, December 28, 2018

HP 42S/DM 42/Free42: Argument, Real Part, Imaginary Part, and Sign Function

HP 42S/DM 42/Free42: Argument, Real Part, Imaginary Part, and Sign Function

Introduction

The HP 42S* has only one extraction function for complex numbers: ABS (absolute value) by default.  To complete the list, here are some programs for ARG (argument), REAL (real part), and IMAG (imaginary part).  The three functions take a complex number, in either rectangular or polar form. 

Using stack commands and flag checks, I am able to get obtain results without affecting the stack much (although the z and t stacks will have the same value).

Also included is the SIGN (signum) function.

* This applies to the Swiss Micros DM42 (it should work), Free42 from Thomas Oakken, and any other HP 42S emulator apps.  The print out is from Free42 (and I also have a physical HP 42S).

HP 42S Program: ARG

00 { 19-Byte Prgm }
01▸LBL "ARG"
02 COMPLEX
03 X<>Y
04 FC? 73
05 →POL
06 R↑
07 STO ST Y
08 R↓
09 R↓
10 RTN
11 .END.

HP 42S Program:  REAL

00 { 21-Byte Prgm }
01▸LBL "REAL"
02 COMPLEX
03 X<>Y
04 FS? 73
05 →REC
06 X<>Y
07 R↑
08 STO ST Y
09 R↓
10 R↓
11 RTN
12 END

HP 42S Program: IMAG

00 { 20-Byte Prgm }
01▸LBL "IMAG"
02 COMPLEX
03 X<>Y
04 FS? 73
05 →REC
06 R↑
07 STO ST Y
08 R↓
09 R↓
10 RTN
11 END

Example - Rectangular Mode:

7+8i   (7 [ENTER] 8 [ (shift) ] (COMPLEX) )
XEQ ARG:  48.8141 (Degrees)
XEQ REAL: 7.0000
XEQ IMAG: 8.0000

Example - Polar Mode: (Degrees):

4 ∡ 60  (4 [ENTER] 60 [ (shift) ] (COMPLEX) )
XEQ ARG:  60.0000
XEQ REAL:  2.0000
XEQ IMAG:  3.4641

HP 42S Program:  SIGN

00 { 15-Byte Prgm }
01▸LBL "SIGN"
02 X=0?
03 RTN
04 ENTER
05 ABS
06 X<>Y
07 ÷
08 RTN
09 END

Example:

-1.4641  XEQ SIGN returns -1
5.525 XEQ SIGN returns 1
0 XEQ SIGN returns 0

Eddie

All original content copyright, © 2011-2018.  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.  Please contact the author if you have questions.

Sunday, December 23, 2018

Casio fx-5800p and HP Prime: American Wire Gauge (AWB)

Casio fx-5800p and HP Prime:  American Wire Gauge (AWB)

Everyone, I wish you all a Happy Holiday season, Merry Christmas and Happy New Year!  I'm thankful for all of you.  Wishing you the best!  - Eddie

Introduction

The following formula calculates the diameter of an American Wire Gauge:

d = 460 / (92^((3 + g)/39))  (in mils)

where g is the wire number (integer).

Define g as:
Wire number:  0000000,  g = -6
Wire number:  000000,  g = -5
Wire number:  00000, g = -4
Wire number:  0000, g = -3
Wire number:  000, g = -2
Wire number:  00, g = -1
Wire number:  0, g = 0
Any other wire number, enter g as the wire number (1, 2, 3, 4, etc.)

Conversion factor:  1000 mils = 1 in

Cross area of the wire:

a = d^2

Casio fx-5800p Program WIRES

Given the wire number, the program WIRES returns the diameter of the wire in inches and the cross sectional area in square inches.

"WIRE NUMBER: "? → G
460 ÷ (92 ^((3 + G) ÷ 39)) → D
D ÷ 1000 → D
D^2 → A
"DIAMETER: (IN)" ⊿
D ⊿
"CROSS AREA:  (IN^2)" ⊿


HP Prime Program Function AWB

Given the wire number, the function AWB returns the diameter of the wire in inches. 

EXPORT AWG(g)
BEGIN
// American Wire Gauge Diameter Function
// 2018-12-23 EWS
// in inches
RETURN (460/(92^((3+g)/39)))/1000;
END;

Examples:

g = -2  (000);  d ≈ 0.4096 in, a ≈ 0.1678 in^2
g = 3; d ≈ 0.2294 in, a ≈ 0.0526 in^2
g = 6; d ≈ 0.1620 in, a ≈ 0.0263 in^2


Sources: 

Ball, John A.  Algorithms For RPN Calculators  John Wiley & Sons: New York  1978.  ISBN 0-471-03070-8

Glover, Thomas J.  Pocket Ref 4th Edition. Sequoia Publishing, Inc.:  Littleton, CO  2012.  ISBN 978-1-885071-62-0

Eddie

All original content copyright, © 2011-2018.  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.  Please contact the author if you have questions.

Thursday, December 20, 2018

HP Prime and TI-84 Plus: Fibonacci Triangles (updated)

HP Prime and TI-84 Plus:  Fibonacci Triangles

This program is the request of John Cvetan.  I thank you for your suggestion.

Introduction

The program FIBMAT generates the Fibonacci Triangle in matrix form.  The Fibonacci triangle is a triangle generated where the outer entries of each row contain the Fibonacci sequence.  The Fibonacci sequence is generated by:

f_0 = 1
f_ 1 = 2
f_n = f_n-1 + f_n-2

You can quickly calculate the nth Fibonacci number by the formula:

f_n = ( (1 + √5)^n - (1 - √5)^n ) / (2^n * √5)

To generate the Fibonacci triangle,

1.  Let r the row and c be the column with

f_0,0 =  1
f_1,0 = 1
f_1,1 = 1
f_2,1 = 1

2.  Each row will be determined by adding the last two terms going diagonally.  You can use one of two formulas:

f_r,c = f_r-1,c + f_r-2,c

f_r,c = f_r-1,c-1 + f_r-1,c-2

The Program FIBMAT

FIBMAT generates a Fibonacci triangle in matrix form.  It's the result is a triangle that is "tilted".  n will need to be 3 or greater.



HP Prime Program FIBMAT

EXPORT FIBMAT(n)
BEGIN
// Fibonacci "triangle" in
// matrix form
// 2018-12-17 EWS
LOCAL M1,k;
M1:=MAKEMAT(0,n+1,n+1);
M1(1,1):=1;
M1(2,1):=1;
M1(2,2):=1;
FOR k FROM 3 TO n+1 DO
M1(k):=row(M1,k-1)+row(M1,k-2);
M1(k,k):=M1(k-1,k-1)+M1(k-2,k-2);
END;
RETURN M1;
END;

Here's an alternate code for Fibonacci Triangle Matrices.  The row command has been eliminated and I used a second For loop in its place.  (added 12/23/2018)

EXPORT FIBMATALT(n)
BEGIN
// 2018-12-23 EWS
// Fibonacci Matrix Alternate
// matrix form
// This version does not have the
// row function.
LOCAL M1,k,j;
M1:=MAKEMAT(0,n+1,n+1);
M1(1,1):=1;
M1(2,1):=1;
M1(2,2):=1;
FOR k FROM 3 TO n+1 DO
FOR j FROM 1 TO n DO
M1(k,j):=M1(k-2,j)+M1(k-1,j);
END;
M1(k,k):=M1(k-1,k-1)+M1(k-2,k-2);
END;
RETURN M1;
END;


TI-84 Plus Program FIBMAT

"2018-12-18 EWS"
"FIBONACCI MATRIX"
Input "ORDER: ",N
{N+1,N+1}→dim([A])
1→[A](1,1)
1→[A](2,1)
1→[A](2,2)
For(K,3,N+1)
For(J,1,N)
[A](K-2,J)+[A](K-1,J)→[A](K,J)
End
[A](K-1,K-1)+[A](K-2,K-2)→[A](K,K)
End
Pause [A]

The Program FIBTRI

This is a visual program for Fibonacci Triangle.



FIBTRI(n) generates a visual Fibonacci Triangle - although I don't recommend going beyond 12 rows due to the constraints of the screen.  I used the small font for the rows.

HP Prime Program FIBTRI

EXPORT FIBTRI(n)
BEGIN
// Fibonacci triangle
// 2018-12-17 EWS
LOCAL M1,k;
M1:=MAKEMAT(0,n+1,n+1);
M1(1,1):=1;
M1(2,1):=1;
M1(2,2):=1;
FOR k FROM 3 TO n+1 DO
M1(k):=row(M1,k-1)+row(M1,k-2);
M1(k,k):=M1(k-1,k-1)+M1(k-2,k-2);
END;

RECT();
LOCAL s;
FOR k FROM 1 TO n+1 DO
s:=STRING(SUB(row(M1,k),1,k));

IF k≤6 THEN
TEXTOUT_P(s,
140-5.5*(k-1),(k-1)*15,2);
END;

IF k>6 AND k≤11 THEN
TEXTOUT_P(s,
140-8*(k-1),(k-1)*15,2);
END;

IF k>11 THEN
TEXTOUT_P(s,
140-11.5*(k-1),(k-1)*15,2);
END;

END;
WAIT(0);
END;

Source:

Hosoya, Haruo.  "Fibonacci Triangle"  Ochanomizu University, Tokyo, Japan.  1976.  https://www.fq.math.ca/Scanned/14-2/hosoya.pdf

Eddie

All original content copyright, © 2011-2018.  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.  Please contact the author if you have questions.

Wednesday, December 19, 2018

HP Prime and TI-84 Plus: Sieve of Eratosthenes

HP Prime and TI-84 Plus: Sieve of Eratosthenes

Introduction

The program SIEVEMIN shows a miniature version of the famous Sieve of Eratosthenes.  The Sieve of Eratosthenes is a Greek algorithm that determines prime numbers from 2 to N through eliminating multiplies.

Algorithm:

1.  List all integers from 1 to n.  Of course, you choose what n is. 

2.   1 is not a prime number, hence eliminate 1. 

3.  Start with 2.  Eliminate multiple of 2, but not 2 itself.

4.  Then do step 3, but with multiples of 3, but not 3 itself.

5.  Then do step 5, but with multiples of 5, but not 5 itself. 

6.  Continue on with the next available number until there are no multiples remaining.  At the end, you have all the prime numbers from 1 to n.

Most sieves will demonstrate the algorithm from 1 to 100.  However, to fit the calculator screens, SIEVEMIN finds all the prime numbers from 1 to 49. 

HP Prime Program: SIEVEMIN 



sub1(); // subroutine

EXPORT SIEVEMIN()
BEGIN
// 2018-12-18 EWS
// Mini Sieve
HFormat:=0; // standard
PRINT();
PRINT("Mini Sieve");
WAIT(1);
LOCAL M0,T,R,C,K;
T:=1;
M0:=MAKEMAT(0,7,7);

FOR R FROM 1 TO 7 DO
FOR C FROM 1 TO 7 DO
M0(R,C):=T;
T:=1+T;
END;
END;

sub1(M0);

M0(1,1):=0;
FOR K FROM 2 TO 7 DO
FOR R FROM 1 TO 7 DO
FOR C FROM 1 TO 7 DO
IF FP(M0(R,C)/K)==0 AND 
M0(R,C)>K THEN
M0(R,C):=0;
sub1(M0);
END;
END;
END;
END;

// end of program

END;

sub1(M1)
BEGIN
PRINT();
LOCAL I;
FOR I FROM 1 TO 7 DO
PRINT(row(M1,I));
END;
WAIT(0.5);
END;

TI-84 Plus CE Program:  SIEVEMIN



"2018-12-11 EWS"
Disp "MINI SIEVE OF","ERATOSHENES","TI-84 PLUS CE"
Float
Wait 1
{7,7}→dim([J])
1→T
For(R,1,7)
For(C,1,7)
T→[J](R,C)
1+T→T
End
End
ClrHome
Disp [J]
Wait 1

0→[J](1,1)
For(K,2,7)
For(R,1,7)
For(C,1,7)
If fPart([J](R,C)/K)=0 and [J](R,C)>K
Then
0→[J](R,C)
ClrHome
Disp [J]
Wait .5
End
End
End
End

Eddie

All original content copyright, © 2011-2018.  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.  Please contact the author if you have questions.

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues The programs are listed for the Swiss Micros DM42 an...