Showing posts with label continued fractions. Show all posts
Showing posts with label continued fractions. Show all posts

Sunday, February 20, 2022

HP 48GX and HP 12C: Continued Fractions

HP 48GX and HP 12C: Continued Fractions


Continued Fractions


A continued fraction is a nested fraction in the form, shown in a linear fashion:


a_0 + 1 ÷ (a_1 + 1 ÷ (a_2 + 1 ÷ (a_3 + 1 ...    ÷ (a_n-1 + 1 ÷ a_n  ) ... )


Below are two examples of continued fractions:





HP 48GX Program: CNFRC


Instructions:


1.  Clear the stack.

2.  Enter values from a_0, a_1, a_2, to a_n.

3.  Run CNFRC


Program:

<< DEPTH 1 - 1 SWAP START INV + NEXT EVAL >>


Example 1 (refer to the above):  


Input: Clear the stack, 5, ENTER, 3, ENTER, 7, run CNFRC

Output:  5.31818181818


Example 2 (refer to the above):


Input:  Clear the stack, 6, ENTER, 4, ENTER, 2, ENTER, 5, run CNFRC

Output:  6.22448979592


HP 12C Program: Continued Fractions


1.  Enter a_n, ENTER a_n-1

2.  Press [ R/S ]

3.  Work backwards, enter a_n-2, press [ R/S ] until the end


Program:  (step, key code, key)

01   34   x<>y

02   22   1/x

03   40   +

04   43,33,00   GTO 00*


*43,33,000 GTO 000 for HP 12C Platinum


For the examples, the HP 12C set to FIX 5


Example 1 (refer to the above):  


Input:  7, ENTER, 3, R/S, 5, R/S

Output:  5.31818


Example 2 (refer to the above):


Input:  5, ENTER, 2, R/S, 4, R/S, 6, R/S

Output:  6.22449


March Madness Sweet Sixteen Calculus 


In the spirit of college basketball's March Madness, I will be posting a calculus post each day from March 16 to March 31, 2022.  


Going On a Break


I am going on a blog break.  This blog is a one-person band, me, all done on spare time between family, a full time job, relationships, and possibly some house repairs.  I am grateful for everyone who reads, subscribes, and enjoys my blog, it is an absolute joy to do.

Next blog entry is on March 12, 2022.

Thank you.  


Eddie 


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

HP 42S & Casio fx-260 Solar: Continued Fractions

HP 42S & Casio fx-260 Solar: Continued Fractions

Introduction

Let x be a real number.  Then x can be represented by the fraction:

x = n_1 + 1/(n_2 + 1/(n_3 + 1/(n_4 + 1/(n_5 + ...))))

The above form is known as a continuous fraction, which can either have a finite set of terms or infinite set of terms.   In short form, continuous fractions can be written in a vector form:

x = [ n_1, n_2, n_3, n_4, n_5, ... ]

If you are given a continuous fraction (n_1, n_2, etc.), you can calculate x with the following keystrokes, starting with the last term n_k and working left to n_1:

RPN Calculators

1.  Start by entering n_k, then press [ 1/x ]
2.  Loop:  For each n_m for 1 < m < k:  enter n_m, [ + ], [ 1/x ]
3.  For n_1:  Enter n_1, [ + ]

Remember, we are working leftwards. 

Example:

Calculate 2 + 1/( 3 + 1/(5 + 1/2)).   In other words x = [2, 3, 5, 2]

2 [ 1/x ]
5 [ + ] [ 1/x ]
3 [ + ] [ 1/x ]
2 [ + ]

Result:  81/35 ≈ 2.31429

The program CF for the HP 42S (and Swiss Micros DM42 and Free42 emulator) calculates the value of a continued fraction.  Instructions:

1.  Run CF ( [ XEQ ] (CF) )
2.  Enter n_k, press (LAST)
3.  For each n_m for 1 < m < k, enter n_m, press (MID)
4.  For n_1, enter n_1, press (1ST).  You get the result.

HP 42S/DM42/Free 42 Program CF

00 {56-Byte Prgm}
01 LBL "CF"
02 LBL 04
03 CLMENU
04 "LAST"
05 KEY 1 GTO 01
06 "MID"
07 KEY 2 GTO 02
08 "1ST"
09 KEY 3 GTO 03
10 MENU
11 LBL 00
12 STOP
13 GTO 00
14 LBL 01
15 1/X
16 GTO 04
17 LBL 02
18 +
19 1/X
20 GTO 04
21 LBL 03
22 + 
23 CLMENU
24 EXITALL
25 RTN
26 END

Classic Algebraic (AOS) Calculators

We can use the same strategy for classic algebraic calculators such as the Casio fx-260 Solar II and TI-30Xa Solar:

1.  Start by entering n_k, then press [ 1/x ]
2.  Loop:  For each n_m for 1 < m < k: press [ + ], enter n_m, press [ = ], [ 1/x ]
3.  For n_1:  Enter n_1, [ + ]

Remember, we are working leftwards. 

Calculate 2 + 1/( 3 + 1/(5 + 1/2)).   In other words x = [2, 3, 5, 2]

2 [ 1/x ]
[ + ] 5 [ = ] [ 1/x ]
[ + ] 3 [ = ] [ 1/x ]
[ + ] 2 [ = ]

Result:  81/35 ≈ 2.31429


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.

Casio fx-50F/Radio Shack EC-4024 Program Collection: October 2026

Casio fx-50F/Radio Shack EC-4024 Program Collection: October 2026 Notes: * The fx-50F/EC-4024 has a 29 step program space betwe...