Monday, December 30, 2019

HP 42S & DM42 Complex Roots (Happy New Year)

HP 42S & DM42 Complex Roots (Happy New Year)

Introduction

The program CROOTS calculates the roots of a complex number.

(a+bi)^n   (n is a positive integer).

The roots are determined by the formula:

(a + bi)^(1/n) =  r^(1/n) * e^(i * (θ + 2*k*π)/n)    (k = 0, 1, 2, ... , n-1)

The results are stored in matrix MATZ.  The calculator is switched to Radians mode during execution.

Stack when running CROOTS:

Y:  complex number
X:  n

HP 42 & DM42 Program CROOTS

00 { 108-Byte Prgm }
01▸LBL "CROOTS"
02 RAD
03 STO 01
04 R↓
05 STO "ZC"
06 1
07 RCL 01
08 NEWMAT
09 ENTER
10 COMPLEX
11 STO "MATZ"
12 RCL 01
13 1
14 -
15 1ᴇ3
16 ÷
17 STO 02
18 INDEX "MATZ"
19 RCL "ZC"
20 COMPLEX
21 X<>Y
22 →POL
23 RCL 01
24 1/X
25 Y↑X
26 STO 03
27 R↓
28 STO 04
29▸LBL 01
30 RCL 04
31 2
32 PI
33 ×
34 RCL 02
35 IP
36 ×
37 +
38 RCL÷ 01
39 0
40 ENTER
41 1
42 COMPLEX
43 ×
44 E↑X
45 RCL 03
46 ×
47 1
48 RCL 02
49 IP
50 1
51 +
52 STOIJ
53 R↓
54 R↓
55 STOEL
56 ISG 02
57 GTO 01
58 EDITN "MATZ"
59 .END.

Link to download croots.raw:  https://drive.google.com/open?id=1YtxgNTAJ6OdhyQRwEXSYAPSZuiYc-RaA
Example
(FIX 4 mode)

Find the three roots of 5+4i.   (5+4i)^(1/3)

Y:  5.0000 i4.0000
X:  3

Result:
1:1=1.8102 i0.4141
1:2=-1.2637 i1.3606
1:3=-0.5464 -i1.7747

(approximately 1.8102+0.4141i, -1.2637+1.3606i, -0.5464-1.7747i)

I want to wish every one a fun, happy, and safe New Year's Celebration.  Thank you for joining me this year and I wish you a happy, healthy, and prosperous 2020! 

HAPPY NEW YEAR!

See you on January 4, 2020,

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, December 29, 2019

Retro Review: Casio fx-280 FRACTION

Retro Review:  Casio fx-280 FRACTION



Quick Facts:

Model:  fx-280 FRACTION
Company:  Casio
Type:  Scientific
Years:  Introduced 1995 (mid 1990s)
Display:  10 digits
Batteries:  Solar with Battery backup, LR 44

Special thanks to Tom Manning for furnishing this calculator.  Much appreciated. 

A Bigger fx-260 Solar (II)



The Casio fx-280 FRACTION is a variation of the Casio fx-260 Solar and the fx-260 Solar II.  The modes and features are:

*  Trigonometric Functions
*  Angle Conversions:  polar, rectangular, degrees/radians/grads
*  Random Numbers
*  Logarithms and exponents
*  1 Variable Statistics
*  Fractions
*  DMS/Decimal conversions

Like the great fx-260 Solar, the fx-280 calculator is an impressive basic scientific calculator, handy for both beginners and experts.  You can check my review for the fx-260 Solar II here:  http://edspi31415.blogspot.com/2017/03/review-casio-fx-260-solar-ii-fx-82.html

Any Differences?



Yes.  The main difference is that the fx-280 has three memory registers:  A, B, and M.   Only memory M has storage addition.  Memories A, B, and M are assigned to the [ ( ], [ ) ], and [ x^y ] keys, respectively. 

The top row of keys has a [STO] (RCL)  (store/recall), pushing the [x^2] (√), [log] (10^x), and [ln] (e^x) keys to the right.  The fx-280 has no [ON] key, and the [AC] key acts as the ON key. 

The arithmetic keys, equals key, and M+/DATA key are blue instead of black.  The [ C ] and [AC] keys are red.

The fx-280 came with a quick reference card.

Thank you Tom! 

Source:

"Casio fx-280 (FRACTION)"  calculator.org  https://www.calculator.org/calculators/Casio_fx-280.html  Retrieved December 11, 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, December 28, 2019

HP Prime: Base Conversions

HP Prime:  Base Conversions 

Introduction

The program BASEDEC converts a number in a base representation to decimal (base 10).   BASEDEC accepts any positive number, including non-integers up to base 36.  Each of the letters of alphabet represents a value:

A = 10
B = 11
C = 12
D = 13
E = 14
F = 15
...
Z = 35

BASEDEC takes two arguments: number to be converted, entered as a string;  and the base representation of the number.

Examples: 

BASEDEC("531",8) converts 531_8 to decimal.  Result:  345

BASEDEC("63.95A", 11) converts 63.95A_11 to decimal.  Result:  69.86701728

BASEDEC("4H", 18) converts 4H_18 to decimal.  Result:  89  (H = 17)

HP Prime Program BASEDEC

EXPORT BASEDEC(s,b)
BEGIN
// string, original base
// number can have fractional
// part in decimal form
// convert to base 10
// A=10,B=11,C=12...Z=35
// 2019-12-09 EWS
LOCAL l,pt,sl,sr,ls,lr,d;
LOCAL k,ac,al,dg,sd;
d:=0; // decimal
l:=DIM(s);
// split the string
pt:=INSTRING(s,".");
CASE
IF pt==0 THEN 
sl:=s;
sr:="";
END;
IF pt==1 THEN 
sl:="";
sr:=RIGHT(s,l-1);
END;
DEFAULT
sl:=LEFT(s,pt-1);
sr:=RIGHT(s,l-pt);
END;
// conversion to decimal
// integer part
ls:=DIM(sl);
IF ls>0 THEN
FOR k FROM 1 TO ls DO
sd:=MID(sl,k,1);
ac:=ASC(sd);
al:=ac(1);
dg:=when(al>64,al-55,EXPR(sd));
d:=d+dg*b^(ls-k);
END;
END;
// fractional part
lr:=DIM(sr);
IF lr>0 THEN
FOR k FROM 1 TO lr DO
sd:=MID(sr,k,1);
ac:=ASC(sd);
al:=ac(1);
dg:=when(al>64,al-55,EXPR(sd));
d:=d+dg/(b^k);
END;
END;
// return decimal
RETURN d;
END;

Introduction Part II

The program DECBASE converts a number in decimal form to any base you want.  DECBASE works will all positive real numbers.  There are three arguments to DECBASE:

*  The number in decimal form
*  The desired base
*  Accuracy:  how many decimal points do you want.  Conversions from decimal to other bases are approximations.   If the number is a integer (frac(number) = 0), then this argument is ignored (put 0).

The result is returned as a string.

Examples:

DECBASE(69, 6, 0) converts 69 to base 6.  Result:  "153"

DECBASE(5.875, 8, 4) converts 5.875 to base 8 to four decimals.  Result:  "5.7000"  (exact:  5.7_8)

DECBASE(635.05, 12, 12) converts 635.05 to base 12 to twelve decimals.  Result:  "44B.072497249724"   (exact:  44B.07249..._12  (7249 repeats))

HP Prime Program DECBASE

EXPORT DECBASE(d,b,acc)

BEGIN

// decimal, base, accuracy

// convert from decimal to base

// 2019-12-09 EWS

LOCAL n,f,nl,nd;

LOCAL nf,k,dg,s,fd;

n:=IP(d); // integer

f:=FP(d); // fractional

s:="";

// integer

IF n>0 THEN

nl:=IP(LOG(n)/LOG(b));

nd:=n;

FOR k FROM nl DOWNTO 0 DO

dg:=IP(nd/(b^k));

IF dg<10 THEN

s:=s+STRING(dg);

ELSE

s:=s+CHAR(dg+55);

END;

nd:=nd-dg*b^k;

END;

END;

// numbers < 1

IF n==0 THEN

s:="0";

END;

// fractional part

IF f>0 THEN

s:=s+".";

fd:=f;

FOR k FROM 1 TO acc DO

dg:=IP(fd*b^k);

IF dg<10 THEN

s:=s+STRING(dg);

ELSE

s:=s+CHAR(dg+55);

END;

fd:=fd-dg/(b^k);

END;

END;

RETURN s;

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.

Sunday, December 22, 2019

TI-84 Plus CE: Drawing an Isosceles Triangle

TI-84 Plus CE:  Drawing an Isosceles Triangle

Introduction



The program ISOTRI draws an isosceles triangle given the following:

The coordinates of the vertex (F,G). 

The length R, which is the length of the line segments from (F,G) to (A,B) and (F,G) to (C,D). 

The tilt angle, T, the tilt of the triangle.  The counterclockwise convention is used. 

The angle, θ,  between the line segments connecting (F,G) to (A,B) and (F,G) to (C,D). 

TI-84 Plus CE Program:  ISOTRI
(Version 5.3 or later required to use the string commands)

Note:  The degree angle inserted in the calculations allows for user to enter angles in degrees, regardless of calculator setting. 

"2019-12-06 EWS"
ClrHome
Disp "ISOC TRIANGLE"
Disp "(F,G):"
Prompt F,G
Input "LENGTH? ",R
Input "TILT?°",T
Input "ANGLE?°", θ
"("+toString(F)+","+toString(G)+")"→Str1
F+R cos(θ°+T°) → A
G+R sin(θ°+T°) → B
"("+toString(A)+","+toString(B)+")"→Str2
F+R cos(T°) → C
G+R sin(T°) → D
√((D-B)²+(C-A)²) → E
"("+toString(C)+","+toString(D)+")"→Str3
ClrHome
Disp "(F,G):"
Pause Str1
Disp "(A,B):"
Pause Str2
Disp "(C,D)"
Pause Str3
Disp "DIST (A,B)-(C,D):"
Pause E
"DRAW TRIANGLE"
ClrDraw
FnOff
BackgroundOn BLACK
Line(F,G,A,B,1,LTGRAY)
Line(F,G,C,D,1,LTGRAY)
Line(A,B,C,D,1,YELLOW)
Pt-On(F,G,2,ORANGE)
Pt-On(A,B,2,LTBLUE)
Pt-On(C,D,2,LTBLUE)
DispGraph

Examples

Example 1:

(F,G):  (1,1)
R = 6
T = 30°
θ = 60°



Example 2:

(F,G):  (-6,0)
R = 8
T = -10°
θ = 70°




Merry Christmas and Happy Holidays,

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, December 21, 2019

Retro Review: Casio FC-100 Financial Calculator

Retro Review:  Casio FC-100 Financial Calculator



Quick Facts:

Model:  FC-100
Company:  Casio
Type:  Finance
Years:  1987 - 1991
Display:  10 digits
Batteries:  1 CR 2035

I paid $18 on eBay, I suspect that the original price was somewhere in the $20 - $30 neighborhood. 

All the Basics Are Covered

Time Value of Money

The FC-100 has the following financial features:

Time Value of Money:  The standard cash convention is used, where cash inflows are positive, cash outflows are negative.  The [COMP] key is used to compute the needed variable.  There are two keys dedicated to amortization.  Given the number of payments:

[AMRT]:  principal paid on the nth payment, interest paid on the nth payment, balance after the first n payments

[ACC]:  accumulated principal on the first n payments, accumulated interest on the first n payments

Similar to the Hewlett Packard HP 12C, the 12× multiplies the number of years by 12 and stores the result in n (number of payments), while the 12÷ divides the annual interest rate and stores the result in i% (periodic rate). 

Cash Flows

The FC-100 can store up to 16 cash flows.  The two calculations available are net present value and initial rate of return (NPV and IRR, respectively).  The interest rate is entered using the [ i% ] key.  We can clear all the cash flows quickly by KAC (pressing [SHIFT] [ Min ]). 

Days Between Dates

There are two modes that deal with date setting:  actual (365) and 30/360 year.  There are two functions:  days between dates and adding/subtracting dates.  Only days between dates is available on the 365 setting. 

What is cool about the FC-100, is the dates are allowed between January 1, 1900 and December 31, 2099. This is pretty impressive for a calculator of the late 1980s.  Dates in the 1900 century are entered with two-digit years while dates in the 2000 century are entered with four-digit years. 

The result of any calculation will include the day of the week (0 for Sunday, 6 through Saturday).

Statistics

Single variable and linear regression are available.  The FC-100 uses the six registers for statistical sums:

K1 = ⅀x^2
K2 = ⅀x
K3 = n
K4 = ⅀y^2
K5 = ⅀y
K6 = ⅀xy

Memory Registers

Another theme of Casio calculators from the 1980s are the use of independent memory registers K1 through K6.  Store data by using Kin, recall data by using Kout.  Storage arithmetic is also available.  An independent memory register M is available.

Keyboard

The FC-100 has an on-off switch on the side of the keyboard.  I like this placement.

The keyboard is clean, the keys are nice and responsive.  I like the size of the keys of the numeric and arithmetic keys (brown).  The keys on the top four rows (in ivory) are smaller in size, a little smaller than I like.  However, the keys are comfortable to press. 

Verdict

The Casio FC-100 is a great user-friendly financial calculator. 

Source:
"Casio FC-100 (FINANCIAL CONSULTANT)"  calculator.org  https://www.calculator.org/calculators/Casio_FC-100.html  Retrieved December 6, 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.

Sunday, December 15, 2019

Tandy PC-4: What Can You Do With 1,568 Bytes in Basic?

Tandy PC-4: What Can You Do With 1,568 Bytes in Basic?

On December 1, 2019, reviewed the Tandy Pocket Computer PC-4.  (link here:  http://edspi31415.blogspot.com/2019/12/retro-review-tandy-pc-4-pocket-computer.html ).  The PC-4 comes with 544 bytes, but with an OR-1 RAM card, the memory goes up to 1,568 bytes. 

How much can I fit in 1,568 bytes?  Here's an attempt. 

P0:  Factorial

10 PRINT "N!"
20 INPUT "N",N
25 F=0
30 FOR I=1 TO N
40 F= LOG(I)+F
50 NEXT I
60 E= INT(F)
70 R=10↑( FRAC(F))
80 PRINT N;"! ="
90 PRINT R;"*10↑";E

P1:  Quadratic Equation

100 PRINT "AX↑2+BX+C=0"
105 INPUT "A",A
110 INPUT "B",B
115 INPUT "C",C
120 D=B↑2-4*A*C
125 S=-B/(2*A)
130 T=SQR( ABS(D))/(2*A)
135 IF D<0 300="" font="" then="">
200 R=S-T
205 T=S+T
210 S=R
215 PRINT "X1 =";S
220 PRINT "X2 =";T
225 GOTO 400
300 PRINT "REAL: ";S
305 PRINT "IMAG: ";T
400 PRINT "AGAIN?"
405 INPUT "0 FOR NO ",R
410 IF R≠0 THEN 105
415 END

P2:  Horizontal Curve

10 MODE 4     (Degrees Mode)
15 INPUT "TAN. LNGTH",T    (tangent length)
20 INPUT "ANGLE",D
25 R=T/ TAN(D/2)
30 L=R*D*π/180
35 C=2*R* SIN(D/2)
40 PRINT "R =";R     (radius)
45 PRINT "L=";L     (arc length)
50 PRINT "C =";C    (chord length)
55 END

P3:  Amortizing a Monthly Loan (Annual Principal and Interest)

50 SET F2  (Fix 2)
100 INPUT "LOAN",L
105 INPUT "RATE",I
110 I=I/1200
115 INPUT "YEARS",T
120 N=12*T
125 U=(1-(1+I)↑(-N))/I
130 P= RND(L/U,-2)   (note the -2 in the round command)
135 PRINT "PMT: $";P
140 B=L
200 FOR Y=1 TO T
201 S=0
202 C=0
205 FOR K=1 TO 12
210 E= RND(B*I,-2)
215 S=S+E
220 A=P-E
225 C=C+A
230 B=B-A
235 NEXT K
240 PRINT "YEAR: ";Y
245 PRINT "INT= $";S
250 PRINT "PRN= $";C
255 PRINT "BAL= $";B
260 NEXT Y
270 PRINT "LAST= ";P+B   (last payment)
275 SET N   (floating decimal)
280 END

P4:  Linear Regression, Y=A+BX with correlation, R

100 VAC    (clear variables A-Z)
200 N=N+1   (N: counter)
205 PRINT "POINT ";N
210 PRINT "X",X
215 PRINT "Y",Y
220 C=C+X:F=F+X↑2
230 D=D+Y:G=G+Y↑2
240 E=E+X*Y
245 INPUT "DONE? NO=0 ",Z
250 IF Z=0 THEN 200
300 H = SQR((F-C↑2/N)/N)
305 I= SQR((G-D↑2/N)/N)
310 B=((N*E-C*D)/(N*F-C↑2))
315 A=(D-B*C)/N:R=B*H/I
325 PRINT "SLP=";B
330 PRINT "ITC=";A
335 PRINT "CORR=";R
340 END

P5:  Snell's Law

10 MODE 4      (degrees mode)
15 INPUT "N1",M    (index of refraction - 1st medium)
20 INPUT "INCIDENCE",T   (angle of incidence)
25 INPUT "N2",N     (index of refraction - 2nd medium)
30 H = ASN(M/N* SIN(T))
35 R= SIN(T-H)↑2/ SIN(T+H)↑2
40 R=1/2*R*100
50 PRINT "REFRACTION=";H;"°"
55 PRINT "REFLECT=";R;"%"
60 END

°  (degree character):  EXT mode, SHIFT C
% (percent character):  EXT mode, SHIFT Q

P6:  Rectangular/Polar Conversions

100 MODE 4
105 INPUT "1.P>R 2.R>P",C
110 IF C=1 THEN 200
115 IF C=2 THEN 300
120 GOTO 105
200 INPUT "RADIUS",R
205 INPUT "ANGLE,"T
210 X=R* COS(T)
215 Y=R* SIN(T)
220 PRINT "X=";X
225 PRINT "Y=";Y
230 GOTO 900
300 INPUT "X",X
305 INPUT "Y",Y
310 R= SQR(X↑2+Y↑2)
315 IF X>0 THEN 500
320 IF X<0 600="" font="" then="">
325 IF X=0 THEN 700
500 IF Y≥0 THEN T= ATN(Y/X)
505 IF Y<0 t="ATN(Y/X)+360</font" then="">
510 GOTO 800
600 IF Y≥0 THEN T= ATN(Y/ ABS(X))+180
605 IF Y<0 t="ATN(Y/X)+180</font" then="">
610 GOTO 800
700 IF Y>0 THEN T=90
705 IF Y=0 THEN T=0
710 IF Y<0 t="270</font" then="">
715 GOTO 800
800 PRINT "RADIUS=";R
805 PRINT "ANGLE=";T
900 PRINT "AGAIN (NO=0)",C
905 IF C≠0 THEN 105
910 END

P7:  Area and Circumference on a Circle

10 INPUT "R",R
25 PRINT "C=";2*π*R
35 PRINT "A=";π*R↑2

Remaining:  8 bytes

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, December 14, 2019

HP 71B: Amortization of a Loan

HP 71B: Amortization of a Loan

Introduction

The program AMORT calculates:

*  The monthly payment of a loan. 
*  An amortization table where the year's interest and principal is calculated.
*  The amount of the final payment based on the balance.

Assumptions:

*  Payments are made at the end of the month.
*  The payment and the amount of interest calculated at each month are rounded to the nearest two decimal places.  Not every one in finance follows this practice, so you mileage may very.


HP 71B Program:  AMORT

100 FIX 2
105 INPUT "LOAN $";L
110 INPUT "RATE? ";I
115 I=I/1200
120 INPUT "TERM? ";T
125 N=12*T
130 U=(1-(1+I)^(-N))/I
135 P=L/U
140 P=IP(100*P+.5)/100
145 DISP "PAYMENT= $";P
150 PAUSE
155 B=L
200 FOR Y=1 TO T
205 S=0
210 C=0
215 FOR K=1 TO 12
220 E=IP(100*B*I+.5)/100
225 S=S+E
230 A=P-E
235 C=C+A
240 B=B-A
245 NEXT K
255 DISP "YEAR ";Y @ PAUSE
265 DISP CHR$(28);"INT= $";S @ PAUSE
275 DISP CHR$(28);"PRN= $";C @ PAUSE
285 DISP "BALANCE= $";B @ PAUSE 
295 NEXT Y
310 W=P+B
315 DISP "LAST PMT= $";W @PAUSE
320 STD

Notes:

*  There is no rounding command in the HP 71B's programming language.  Lines 140 and 220 has a formula for rounding results to two decimal places: 

IP(100*n+.5)/100

*  STD is floating point display mode (standard)

*  CHR$(28) prints the capital Sigma character, "Σ"

Examples

Example 1:

Loan:  $35,000.00
Rate:  5.8%
Term:  5 years

Payment:  $673.40

Year 1:  Interest:  $1,866.54,  Principal:  $6,214.26,  Balance: $28,785.74
Year 2:  Interest:  $1,496.37,  Principal:  $6,584.43,  Balance: $22,201.31
Year 3:  Interest:  $1,104.14,  Principal:  $6,976.66,  Balance: $15,224.65
Year 4:  Interest:  $688.59, Principal:  $7,392.21, Balance:  $7,832.44
Year 5:  Interest:  $248.25, Principal:  $7,832.55, Balance:  -$0.11
Final Payment:  $673.29

Example 2:

Loan:  $76,000.00
Rate:  4%
Term:  6 years

Payment:  $1,189.03

Year 1:  Interest:  $2,831.83,  Principal:  $11,436.53,  Balance: $64,563.47
Year 2:  Interest:  $2,365.89,  Principal:  $11,902.47,  Balance: $52,661.00
Year 3:  Interest:  $1,880.98,  Principal:  $12,387.38,  Balance: $40,273.62
Year 4:  Interest:  $1,376.30, Principal:  $12,892.06, Balance:  $27,381.56
Year 5:  Interest:  $851.04, Principal:  $13,417.32, Balance:  $13,964.24
Year 6:  Interest:  $304.41, Principal:  $13,963.95, Balance:  $0.29
Final Payment:  $1,189.32

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, December 8, 2019

HP 71B: Population Deviation Derivation and Program

HP 71B:  Population Deviation Derivation and Program 

Derivation

The standard formula for the population deviation for a set of statistical data is given by:

σx = √( Σ(x - μ)^2 / n)

where μ is the mean, where μ = Σx / n

Σx = the sum of all the data points
 n = the number of data points

If this function needs to be programmed, using the definition as will probably require the use of two FOR structures: one for the mean, and one for the deviation.  Is there a way to use a formula where a FOR structure can be saved?

Turns out, the answer is yes. 

σx = √( Σ(x - μ)^2 / n)
= √( Σ(x^2 - 2*x*μ + μ^2) / n)

Note that:
Σ( f(x) + g(x) ) = Σ f(x) + Σ g(x)
For a constant, a:   Σ( a * f(x) ) = a * Σ f(x)
And:  Σ a = a * n   (sum from 1 to n)

Then:

σx = √( Σ(x - μ)^2 / n)
= √( Σ(x^2 - 2*x*μ + μ^2) / n)
= √( (Σ(x^2) -  2*μ*Σx + Σ( μ^2 )) / n)
= √( (Σ(x^2) -  2*μ*Σx + n*μ^2) / n) 
= √( (Σ(x^2) -  2*Σx*Σx/n + n*(Σx)^2/n^2 ) / n) 
= √( (Σ(x^2) -  2*(Σx)^2/n + (Σx)^2/n) / n)
= √( (Σ(x^2) -  (Σx)^2/n ) / n)

The above formula allows to use a sum and sum of square of data points in calculating population deviation, eliminating the need for an additional FOR structure. 
 
Standard deviation follows a similar formula:
sx = √( (Σ(x^2) -  (Σx)^2/n ) / (n - 1))

HP 71B Program:  Population Deviation

File:  PDEV
20 N=0
22 A=0
24 B=0
30 INPUT "X? ";X
40 N=N+1
50 A=A+X
60 B=B+X^2
70 INPUT "DONE? NO=0"; C
80 IF C=0 THEN 30
90 M=A/N
95 S=SQR((B-A^2/N)/N)
100 DISP "MEAN= ";M
105 PAUSE
110 DISP "PDEV= ";S
120 END

Example

Data Set:  150, 178, 293, 426, 508, 793, 1024

MEAN = 481.7142857
PDEV = 300.6320553

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

HP 42S and DM42: Solar Declination, Zenith, and Sunrise

HP 42S and DM42: Solar Declination, Zenith, and Sunrise

Introduction

The program SUNS will calculate:

1.  Approximation declination given month and day.  A 365-year is assumed.

δ ≈ 23.45° sin(.9863 * (284 + n))

where n is the nth day of the year:

If month = 1 or month = 2, then:
n = IP(30.6 * month + 368.8) + day - 399

If month ≥ 3 then:
n = IP(30.6 * month + 1.6) + day - 34

2.  Zenith angle θ:

θ ≈ acos(sin δ * sin ϕ + cos δ * cos ϕ * cos hour_angle)

where:
ϕ = latitude, north is positive
hour_angle = (12 - number of hours before noon) * 15

3.  Approximate time of sunrise:

ω ≈ acos(-tan ϕ * tan δ)
Sunrise time ≈ (12 - ω/15) converted to HMS

The program was entered on a HP 42S, and should work for the Free42 and Swiss Micros DM42.

HP 42S/DM42 Program SUNS

00 {206-Byte Prgm}
01 LBL "SUNS"
02 DEG
03 "MONTH?"
04 PROMPT
05 STO 01
06 "DAY?"
07 PROMPT 
08 STO 02
09 "HRS BEFORE NOON"
10 PROMPT 
11 STO 03
12 "LAT (N+)?"
13 PROMPT
14 →HR
15 STO 04
16 RCL 02     // calculate n
17 RCL 01
18 CF 00
19 3
20 X>Y?
21 SF 00
22 R↓
23 30.6
24 *
25 1.6
26 +
27 FS? 00
28 367.2
29 FS? 00
30 +
31 IP
32 +
33 34
34 -
35 FS? 00
36 365
37 FS? 00
38 -
39 CF 00
40 STO 11
41 284     // calculate δ
42 +
43 0.9863
44 *
45 SIN
46 23.45
47 * 
48 STO 12
49 "DEC="
50 ARCL ST X
51 AVIEW 
52 STOP
53 12
54 RCL- 03
55 15
56  *
57 STO 13
58 RCL 12   // calculate θ
59 SIN
60 RCL 04
61 SIN
62 *
63 RCL 12
64 COS
65 RCL 04
66 COS
67 *
68 RCL 13
69 COS 
70 *
71 +
72 ACOS
73 STO 14
74 "ZENITH="
75 ARCL ST X
76 AVIEW
77 STOP
78 RCL 04   // calculate ω
79 TAN
80 +/-
81 RCL 12
82 TAN
83 *
84 ACOS
85 15
86 ÷
87 12
88 X<>Y
89 -
90 →HMS
91 STO 15
92 "SUNRISE="
93 ARCL ST X
94 AVIEW
95 END

Variables:
R01 = month
R02 = day
R03 = hours before moon
R04 = latitude

R11 = n,  nth day of the year
R12 = δ,  declination
R13 = hour_angle
R14 = θ,  zenith
R15 = ω, approximate sunrise

Example

March 15, 8:00 AM (4 hours before noon), latitude is 40°

Results:
DEC = -2.8191   (-2.8191°)
ZENITH = 114.4672
SUNRISE = 6.0928  (around 6:09:28)

Remember, these results are approximate!

Source:
Hewlett Packard.  "Solar-Beam Irradiation"  Hewlett Packard User's Library Solution:  Solar Engineering.  HP 41C  January 1984.

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

Retro Review: Tandy PC-4 Pocket Computer

Retro Review:  Tandy PC-4 Pocket Computer



Quick Facts:

Model:  Tandy PC-4
Company:  Tandy/Radio Shack
Type:  BASIC Programming Calculator
Based Off Of:  Casio PB-100, Radio Shack TRS-80 Pocket Computer PC-4
Memory: 544 bytes or 1,568 bytes with OR-1 RAM card
Years:  1982 (PB-100) - approximately 1986
Display:  One line, scrolling display, 12 character screen
Batteries:  2 CR 2032
Program Slots: 10
Other Clones: Olympia OP-544
Peripheral Devices:  12 pin expansion port for FP-12 thermal printer, FA-3 audio cassette recorder

I have the calculator from Ghostbusters.  OK, technically the Radio Shack TRS-80 Pocket Computer PC-4 (an earlier version of the Tandy PC-4).  However Tandy computers were sold through Radio Shack.  Close enough. (https://ghostbusters.fandom.com/wiki/PC-4_Calculator)

Basic Programming at its Basic

The PC-4 has a simple, non-intimidating, keyboard.  All the arithmetic functions are present on the keyboard, where as the scientific functions are typed from the QWERTY keyboard.  The scientific functions available are:

ABS:  absolute value
ACS:  arc cosine
ASN:  arc sine
ATN:  arc tangent
COS:  cosine
FRAC:  fractional part
INT:  integer part
LN:  natural logarithm
LOG:  common logarithm
RAN#:  random number
RND:  round numbers  (RND(A,B) round A to 10^B precision)
SGN:  sign
SIN:  sine
SQR:  square root, note the lack of the letter "T"

The angle unit selection were selected through modes 4, 5, and 6 (degrees, radians, and grads respectively) outside of the programming environment.

You notice that the set of commands is very basic, like a basic TI-30 from the 1980s.  Statistics, factorials, polar-rectangular conversions, and the like will have to be programmed manually.  I am considering doing a series of basic programs for the PC-4 in the near future.

You can enter lower case letters and characters printed in gold (°, &, %, yen symbol ¥, etc.) by turning on EXT mode ([ S ] [ . ]).

Only two structures are available:  IF and FOR.  There are a few string commands, mainly KEY, SCR, LEN, MID (that uses a special variable $), and VAL.

The variables available are A-Z.  They can made into strings by attaching a dollar sign after the letter.

You can set which program is the current program by pressing [ S ] and any of the number keys.  For example,  [ S ] [ 0 ] makes program 0 (P0) the current program, both in editing and running.

Clearing

Clearing programs are supposed to be done by the CLEAR command.  Unfortunately for me, the CLEAR command does nothing.  It could be a bug of the Tandy version PC-4.

Update:  I found about NEW, and NEW does clear the program space.  Thank you Don Shepherd!  (Discussion of the Tandy PC-4:  https://www.hpmuseum.org/forum/thread-14082-post-124509.html#pid124509)

Thankfully, entering blank lines  (example:  10 [EXE] erases line 10) will erase lines, allowing me to clear programs one line at a time.  Also, there is a reset button on the back of the calculator that clears everything.  With the limited memory available, this would not be such a big deal.

Listing Program Lines

You can list the program lines by the LIST command, which is very helpful to review program lines.

Verdict

This is a really basic, programming calculator.  I really like the PC-4 as a beginning level programming tool.   If you get the PC-4, (or TRS-80 PC-4 from Radio Shack or Casio PB-100), make sure you get it with the RAM card installed or part of the package.  There are probably many Android and iOS apps that emulate a PC-4.

The PC-4 is a pleasure to use and the keyboard is responsive.

I wonder if there will be a basic version of Python or C++ pocket computers - to get people to start learning programming languages.

Unfortunately, I still don't know the equation for determining the ionization level of spiritual appropriations.

Source:
Omegas.  "Casio PB-100"  https://everything2.com/title/Casio+PB-100  Retrieved November 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.

Spotlight: Akron Brass FireCalc Pocket Computer

Spotlight: Akron Brass FireCalc Pocket Computer Welcome to a special Monday Edition of Eddie’s Math and Calculator blog. Thi...