Casio fx-3800P "Programming"
|
03-10-2020, 11:02 PM
Post: #15
|
|||
|
|||
RE: Casio fx-3800P "Programming"
(03-10-2020 01:33 PM)Csaba Tizedes Wrote: Today evening (CET) I will go back with a little program for my 50F, which can be run on any similar unit. Estimating real numbers with fractions ====================================== Let K is a (real) number and estimate it with the fraction A/B, where A and B are relative primes and ABS(A/B-K)<=E, where E is a small number. The algorithm is a simple brute-force-counting algorithm: Let A=0 and B=1. If ABS(A/B-K)<=E, the program stops. If A/B-K<0 then A=A+1, else B=B+1. The above in BASIC: ------------------- 10 D=A/B-K 20 IF E>=ABS(D) THEN PRINT A,B:END 30 IF D<0 THEN A=A+1:GOTO 10 40 B=B+1:GOTO10 On blind programmable CASIOs: ----------------------------- Code: P1: Variables: ---------- K1: A (numerator) K2: B (denominator) K3: H (=A/B) K4: K (the number) K5: E (eps = absolute error of estimation; can be calculated as percent of K for relative error) M: for decisions For type in: (let K=PI) ------------ 1 Kin1 Kin2 PI Kin4 ×0.001 = Kin5 For running: ------------ 0 Kin1 1 Kin2 P1 The results: ------------ Tested on CASIO fx-50F Code:
Short explanation: ------------------ In 05~12 steps the A is increased until H>K-E. If we are in K+/-E "good" range (tested in step 23) the program ends... ...or A is too high and H>K+E, in this case we must to increase the B. We can increase B in the following way: first decrease A in step 14 because in steps 05~12 the A will be increased during the next cycle and the original A will be present and increase B in step 15. Important: the H is not changed when A and B changed, because H is required in step 23, but when the program finished, must to correct A and B in step 24~26. nJoy! Csaba |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)