Post Reply 
(Plus 42) Fraction approximation equation
02-17-2022, 01:38 PM (This post was last modified: 02-17-2022 08:41 PM by Vincent Weber.)
Post: #1
(Plus 42) Fraction approximation equation
Hi all,

Since Plus42 does not (have) yet a fraction mode à la 32SII/35S, and since this mode is anyway limited (4096 denominator maximum, no expression of tolerance, just max denominator) I made an equation for it.

It has no intelligence whatsoever, no limited fractions algorithm, just plain stupid brute force try of every possible denominator. Plus42 is so fast anyway :)

Just enter X, the value to be approximated, and TOL (e.g. 1E-8), the tolerance of the approximation. Press EVAL, now N holds the numerator of the approximated fraction, D the denominator, and RES the difference with the original number.

Cheers

FRAC:0×FOR(SEQ(L(N:IP(X)):L(D:1)):L(RES:ABS(N÷D-X))>TOL:0:SEQ(L(D:D+1):L(N:RND(D×X:0))))+RES
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(Plus 42) Fraction approximation equation - Vincent Weber - 02-17-2022 01:38 PM



User(s) browsing this thread: 1 Guest(s)