Showing posts with label arithmetic-geometric mean. Show all posts
Showing posts with label arithmetic-geometric mean. Show all posts

Saturday, April 20, 2024

Sharp EL-9300 Programs

Sharp EL-9300 Programs


Today’s blog entry takes us to the 1992 Sharp’s EL-9300 graphing calculator. On January 10, 2022, I gave a review of this calculator:

https://edspi31415.blogspot.com/2022/01/retro-review-sharp-el-9300c.html



The programs should also work on the EL-9200. Spaces are added for readability.



Sharp EL-9300 Program: polygon2


The program polygon2 calculates four properties of regular polygons:

* The internal angle of the polygon

* The length of the polygon’s apothem

* The length of the polygon’s radius

* The area of the polygon


A regular polygon is a polygon whose sides all have equal length and all the internal angles are equal.


REAL Mode

Print “Set Degrees 1st”

Wait 1

Print “number of sides”

Input n

Print “side length”

Input x

angle = (n – 2) / n * 180

apothem = x / 2 * tan (angle / 2)

radius = x / (2 * cos (angle / 2) )

area = n * x * apothem / 2

ClrT

Print angle

Print apothem

Print radius

Print area



Note that the calculator must be set in Degrees mode prior to running this program. To set the degrees mode, press [ SET UP ], [ B ], [ 1 ]. Note that this won’t set the angle mode indicator in the program as the angle mode change takes place outside of the program script.


Examples


Inputs: n = 6, x = 8

Outputs:

angle = 120 (internal angle)

apothem = 6.92820323

radius = 8

area = 166.2768775



Inputs: n = 12, x = 1.5

Outputs:

area = 150

apothem = 2.799038106

radius = 2.897777479

area = 25.19134295



Sharp EL-9300 Program: agm


The program agm calculates the arithmetic-geometric mean between two numbers x and y.


(x + y) / 2

√(x * y)


The program also asks for the tolerance. If the tolerance is small, it means we are asking for better accuracy at the expense of additional calculations.


REAL Mode

ClrT

Print “arithmetic/”

Print “geometric mean”

Input x

Input y

Print “tol (10^-nn)”

Input tol

Label loop

a = (x + y) / 2

g = √(x * y)

x = a

y = g

If abs(a – g) >= tol Goto loop

ClrT

Print “results”

Print a

Print g

End


Examples


Inputs: x = 15, y = 70, tol = 10^-6

Outputs:

a = 37.28076573

g = 37.28076573


Inputs: x = 1649, y = 1248, tol = 1E-7

Outputs:

a = 1441.519759

g = 1441.519759


The EL-9300 is pretty quick.



Sharp EL-9300: quadratic


The program quadratic solves the quadratic equation:


a * x^2 + b * x + c = 0


where a, b, and c can be real or complex numbers.


COMPLEX Mode

ClrT

Print “ax^2+bx+c=0”

Print “complex numbers”

Input a

Input b

Input c

x = (-b + √(b^2 – 4 * a * c)) / (2 * a)

z = x - √(b^2 – 4 * a * c) / a

ClrT

Print “solutions=”

Print x

Print z

End


Examples


Inputs:

a = 4 + 3i, b = 2 – 5i, c = 3i

Solutions:

x = 0.346818295 – 0.288439118i

z = -0.066818295 + 1.328439118i


Inputs:

a = 2, b = -6i, c = -4 + 8i

Solutions:

x = 1.370730624 + 0.040924113i

z = -1.370730624 + 2.959075887i



Sharp EL-9300 Program: twobytwo


The program twobytwo solves the simultaneous set of equations:


a * x + b * y = e

c * x + d * y = f


where a, b, c, d, e, and f can be complex numbers.


COMPLEX Mode

Print “2x2 system”

Print “complex numbers”

Print “A=((a,b)(c,d))”

Input a

Input b

Input c

Input d

Print “B=((e)(f))”

Input e

Input f

g = a * d – b * c

h = e * d – f * b

i = a * f – c * e

x = h / g

y = i / g

ClrT

Print “solutions=”

Print x

Print y

End



Examples


Input:

a = 3 + 2i, b = -i

c = 3 – 2i, d = 1 – i

e = 0, f = 5i

Outputs:

x = -0.660377358 + 0.188679245i

y = -0.754716981 + 2.358490566i


Input:

a = 3, b = -6

c = 3i, d = 6i

e = 1, f = -i

Outputs:

x = 0

y = -0.166666667




Eddie


All original content copyright, © 2011-2024. 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, August 7, 2021

TI-95 ProCalc: Arithmetic and Geometric Series, Arithmetic-Geometric Mean

TI-95 ProCalc: Arithmetic and Geometric Series, Arithmetic-Geometric Mean




Welcome to TI-95 ProCalc month!  I think this is the first time I am going to post programs for this classic keystroke calculator.  


To see my review of the TI-95 ProCalc in 2020, click here:

http://edspi31415.blogspot.com/2020/07/retro-review-ti-95-procalc.html

Note, all programs on this series will use the one-letter variables A-Z, which can also be registers 000 - 025. 


Arithmetic Term and Sum


Arithmetic Series:

a + (a + d) + (a + 2d) + ...


Nth Term:

TERM = B = a + (n -1) * d


Sum of N Terms:

SUM = S = n / 2 * (2 * a + (n - 1) * d) = n / 2 * (a + TERM)


Alpha strings are enclosed in singular quotes (' ').


TI-95 ProCalc Program File ARI

Size: 72 bytes


'A+(A+D)+...'  BRK CLR


'A?' BRK STO A


+ ( 'N?' BRK STO N 


- 1 ) * 'D?' BRK = STO B


+ RCL A = * RCL N / 2 = STO S


'TERM=' COL 16 MRG B BRK 


CLR 'SUM=' COL 16 MRG S HLT


Examples

 

A = -1, D = 6, N = 20

Results:  TERM = 113, SUM = 1,120


A = 4.5, D = 1.8, N = 35

Results:  TERM = 65.7, SUM = 1,228.5



Geometric Series and Sum


Geometric Series:

a + a*r + a*r^2 + a*r^3 + ...


Nth Term:

TERM = B = a * r^(n-1)


Sum of N Terms:

SUM = S = (a * (1 - r^n)) / (1 - r) = ( -r * TERM + a ) / (1 - r )


TI-95 ProCalc Program File GMS

Size: 80 bytes


'A+A*R+A*R^2+...' BRK CLR


'A?' BRK STO A* 


'R?' BRK STO R y^x 


( 'N?' BRK - 1 ) = STO B

 

* RCL R +/- + RCL A = 


/ ( 1 - RCL R ) = STO S


'TERM=' COL 16 MRG B BRK


CLR 'SUM=' COL 16 MRG S HLT


Examples


A = 1,000, R = 1.36, N = 32

Results: TERM = 13,794,506.22, SUM = 52,109,801.29 


A = 1,000, R = 0.95, N = 26

Results: TERM = 277.3895731, SUM = 14,729.59811


Arithmetic-Geometric Mean


Given positive real numbers A and G, the follow algorithm repeats until A and G converge:


A_n+1 = (A_n + G_n) / 2

G_n+1 = √(A_n * G_n)


When convergence is satisfied to a set of decimal places, both A_final and G_final are calculated for comparison purposes.


TI-95 ProCalc Program File AGM

Size: 104 bytes


CLR 'ARITH/GEOM MEAN' PAU


CLR 'A?' BRK STO A


CLR 'G?' BRK STO G


CLR '# PLACES?' BRK +/- INV LOG STO T 


LBL 01 RCL A STO B RCL G STO H


( RCL B + RCL H ) / 2 = STO A


( RCL B * RCL H ) SQR = STO G


( RCL A - RCL G ) ABS = IF> T GTL 01 


RCL G x~t RCL A HLT


Examples


A = 2.4, G = 3.6, # PLACES = 6 (6 places)

Results:  2.969616524, 2.969616523


A = 105, G = 207, # PLACES = 6 (6 places)

Results:  151.6836959, 151.6836959


Source for Arithmetic and Geometric Term and Sum:


Lindeburg, Michael R. P.E.  Engineering Fundamentals: Quick Reference Cards Third Edition  Professional Publications, Inc.  Belmont, CA 1988 ISBN 0-932276-88-1


Commas added to the results for readability.  


Eddie


All original content copyright, © 2011-2021.  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 5, 2021

7000G Retro Month - June 5 Edition

7000G Retro Month - June 5 Edition





Introduction


Welcome to the 7000G Retro Month, which features programming for the classic Casio calculators from the mid/late 1980s:  primarily fx-7000G and fx-7500G.  Since the programming language stays similar throughout the years, programs can be translated to the fx-6300G and later graphing calculators with little to no adjustments.  Non graphic programs should be ported to the fx-4000P, fx-4500P (A), fx-3650p (II), fx-50F Plus (II), and fx-5800P with little to no adjustments.  


7000G Retro Month takes place every Saturday during June 2021.


To make text easier to type, I can going to use the following text friendly symbols for the following:


->  for →


/I for ⊿


=> for ⇒


What do you think?   Unicode or simple text equivalents?  


- - - - - - -- - -- - -


Today's subject revolves around General Mathematics.  Enjoy!


- - - -- - - -- - -- -- -



Day Number of the Year


Returns the day number of a year, with January 1 being Day 1 and December 31 being day 365 (or 366 on leap years).  For LEAP? enter 0 for non leap years or 1 for leap years.   


"MONTH"? -> M

"DAY"? -> D

"LEAP"? -> L

M≤2 => D+Int(30.6M+368.8)-399 -> N

M>2 => D+Int(30.6M+1.6)-34+L -> N


Arithmetic-Geometric Mean


The arithmetic-geometric mean of two positive numbers x and y is a convergence of repeated means:


Arithmetic:  a = (x + y)/2

Geometric:  g = √(x y) 


Tolerance:  decimal to determine desired accuracy.  For example, to eight decimal places, set tolerance to 1E-8.  


"AGM"

"A0"? -> X

"G0"? -> Y

"TOL"? -> T

Lbl 1

(X+Y)÷2 -> A

√(XY) -> G

A -> X : G -> Y

Abs (A-G) ≥ T => Goto 1

A /I

G


The final A and G are displayed to show the convergence.  


Now for two classics.


Determinant of a 3 x 3 Matrix


Here the program makes use of the square brackets and indirect storage.  Yes, indirect storage and recall are possible with the fx-7000G and fx-7500G.  Of course, this program is not necessary in later graphing calculators.


A[0] = A

A[1] = B

A[2] = C

A[3] = D

A[4] = E

A[5] = F

A[6] = G

A[7] = H

A[8] = I


Elements are entered left to right, completing row by row.


The determinant is stored in the variable T.


The Isz command is used to increment K by 1.  Since K starts at 0 and K increases by 1 before comparing it, the next command is never going to be skipped.


"3 X 3 DET"

0 -> K

Lbl 1

? -> A[K]

Isz K

K < 9 => Goto 1

A(EI-FH)-B(DI-FG)+C(DH-EG) -> T


Quadratic Formula


I would consider this the "Hello World" of mathematics programs.   


Ax^2 + Bx + C = 0


Let D be the discriminant:  D = B^2 - 4AC.   D is displayed where you can determine the characteristics of the roots:


D ≥ 0:  roots are real, stored in X and Y

D < 0:  roots are complex, that take the form of X + Yi, X - Yi


"A"? -> A

"B"? -> B

"C"? -> C

B^2-4AC -> D /I

D<0 => Goto 1

(-B+√D)÷(2A) -> X

(-B-√D)÷(2A) -> Y

Goto 2

Lbl 1

-B÷(2A) -> X

√ Abs D ÷(2A) -> Y

Lbl 2

X /I Y


Eddie


All original content copyright, © 2011-2021.  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, July 26, 2020

HP 41C, HP 42S, TI-60: Arithmetic-Geometric Mean

HP 41C, HP 42S, TI-60:  Arithmetic-Geometric Mean



Arithmetic-Geometric Mean

The program AGM calculates the arithmetic-geometric mean of two positive integers x and y.   As the graphic above suggests, an iterative process is used to find the AGM, computing both the arithmetic mean and geometric mean until the two means converge.

a0 = x
g0 = y

Repeat:
Arithmetic Mean:  a1 = (a0 + g0)/2
Geometric Mean:  g1 = √(a0 * g0)
Transfer new to old:  a0 = a1, g0 = g1
Until |a1 - g1| < tolerance

You can set the tolerance as low as you want.  The programs presented on this blog set tolerance at 10^(-10)  (1E-10), to fit the calculator's display.

HP 41C Program: AGM

01 LBL^T AGM
02 STO 01
03 X<>Y
04 STO 02
05 X<>Y
06 LBL 00
07 RCL 02
08 RCL 01
09 ENTER
10 R↑
11 R↑
12 X<>Y
13 R↓
14 ENTER
15 R↑
16 +
17 2
18 /
19 STO 01
20 R↓
21 *
22 SQRT
23 STO 02
24 R↑
25 -
26 ABS
27 1E-10
28 X≤Y?
29 GTO 00
30 CLA
31 ^T AGM = 
32 ARCL 01
33 AVIEW
34 END

HP 42S/Swiss Micros DM42/Free42 Program AGM:

00 {53-Byte Prgm}
01 LBL "AGM"
02 STO 01
03 X<>Y
04 STO 02
05 X<>Y
06 LBL 00
07 RCL 02
08 RCL 01
09 ENTER
10 R↑
11 R↑
12 X<>Y
13 R↓
14 ENTER
15 R↑
16 +
17 2
18 /
19 STO 01
20 R↓
21 *
22 SQRT
23 STO 02
24 R↑
25 -
26 ABS
27 1E-10
28 X≤Y?
29 GTO 00
30 CLA
31 "AGM = "
32 ARCL 01
33 AVIEW
34 END

The instructions for both the HP 41C and 42S versions are same:  enter X and Y on the respective stacks and XEQ AGM.

Example (ALL/STD mode is applied):

AGM(37, 78): 
37, 78, XEQ AGM returns:
Alpha:  AGM = 55.5947005279

TI-60 Program: AGM

Instructions:

1.  Store X in memory register 1 and Y in memory register 2.
2.  Press [ RST ] [ R/S ], the value of |a1 - g1| is displayed.
3.  Keep on press [ R/S ] to repeat the calculation until |a1 - g1| falls under 10^(-10).
4.  Recall either memory register 1 or 2 to get the answer.

Registers needed: 1 - 4.

Step;  Key Code; Key
00;  71;  RCL
01;  01;  1
02;  85;  +
03;  71;  RCL
04;  02;  2
05;  95;  =
06;  55;  ÷
07;  02;  2
08;  95;  =
09;  61;  STO 
10;  03;  3
11;  71;  RCL
12;  01;  1
13;  86;  √
14;  65;  ×
15;  71;  RCL
16;  02;  2
17;  86;  √
18;  95;  =
19;  61;  STO
20;  04;  4
21;  71;  RCL
22;  03;  3
23;  61;  STO
24;  01;  1
25;  75;  -
26;  71;  RCL
27;  04;  4
28;  61;  STO
29;  02;  2
30;  95;  =
31;  87;  |X|
32;  13;  R/S

Example:

AGM(37, 78)
37 STO 1
78 STO 2
RST R/S

3.778495926, R/S
0.032100702, R/S
0.000002317, R/S
2 -11  (stop)

RCL 1 (or RCL 2):  55.59470053

Source:
"Arithmetic-geometric mean"  Wikipedia.  https://en.wikipedia.org/wiki/Arithmetic–geometric_mean  Last Edited June 12, 2020.  Accessed June 12, 2020.


Onward to August...

Eddie

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

RPN HP 12C: Fibonacci and Lucas Sequences

  RPN HP 12C: Fibonacci and Lucas Sequences Golden Ratio, Formulas, and Sequences Let φ be the Golden Ratio: φ = (1 + √5) ÷ 2...