HP49-50G: help for recursive
|
02-02-2024, 12:46 PM
(This post was last modified: 02-02-2024 01:26 PM by Gil.)
Post: #1
|
|||
|
|||
HP49-50G: help for recursive
I have, from Albert Chan, the following recursive program:
200 DEF FNL(X) ! = ln(1+X) - X, but more accurate 210 IF ABS(X)>=.4 THEN X=X/(SQRT(1+X)+1) @ FNL=FNL(X)*2-X*X @ GOTO 250 220 X2=X/(X+2) @ X4=X2*X2 230 X4=X4*(5005-X4*(5082-X4*969))/(15015-X4*(24255-X4*(11025-X4*1225))) 240 FNL=X2*(X4+X4-X) 250 END DEF I transformed the FNL function for the HP50G, but without the recursion formulae: « 0 0 0 { } -> x X2 X4 fnl l « WHILE x .4 >= REPEAT x l + 'l' STO 'x/(sqrt(1+x)+1)' ->NUM 'x' STO END 'x/(x+2)' ->NUM 'X2' STO X2 DUP * 'X4' STO 'X4*(5005-X4*(5082-X4*969))/(15015-X4*(24255-X4*(11025-X4*1225)))' ->NUM 'X4' STO 'X2*(X4+X4-x)' ->NUM 'fnl' STO x l + 'l' STO l SIZE 1 > IF THEN 1 l SIZE 1 - FOR i fnl 2 * l i GET SQ - 'fnl' STO NEXT END fnl » » 'FNL' STO Or, with INOUT transcription: Code: \<< 0 0 0 { } \-> x X2 X4 fnl l I try now to have a HP50G recursive version FNL2: « 0 0 0 -> x X2 X4 fnl « IF x .4 >≠ THEN 'x/(sqrt(1+x)+1 )' ->NUM FNL2 2 * x SQ - ELSE 'x/(x+2)' ->NUM 'X2' STO X2 DUP * 'X4' STO 'X4*(5005- X4*(5082-X4*969))/( 15015-X4*(24255-X4*( 11025-X4*1225)))' ->NUM 'X4' STO 'X2*(X4 +X4-x)' ->NUM END » » Suppose I have an initial value of 2 for x. Then its successive values will be, as expected: .732050807569 and .316074012953. Then, as .316074012953 <0.4, we jump to the ELSE branch to get a value of -4.14209407856E-2 before the END instruction. Now the program carries on just after the FNL2. Unfortunately, before multiplying the last result -4.14209407856E-2 by 2, it closes one of the ». Consequence: the last value of x, 316074012953, disappears, and we get instead the previous value of x, 732050807569. Question: How could we change the program into a correct recursive version? Thanks for your help. Regards, Gil |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
HP49-50G: help for recursive - Gil - 02-02-2024 12:46 PM
RE: HP49-50G: help for recursive - Gil - 02-02-2024, 01:52 PM
RE: HP49-50G: help for recursive - Albert Chan - 02-02-2024, 04:27 PM
RE: HP49-50G: help for recursive - Albert Chan - 02-02-2024, 04:48 PM
RE: HP49-50G: help for recursive - Gil - 02-02-2024, 06:13 PM
RE: HP49-50G: help for recursive - Gil - 02-03-2024, 10:19 AM
RE: HP49-50G: help for recursive - Gil - 02-04-2024, 12:06 PM
RE: HP49-50G: help for recursive - Gjermund Skailand - 02-06-2024, 11:14 AM
RE: HP49-50G: help for recursive - Gil - 02-06-2024, 11:57 AM
RE: HP49-50G: help for recursive - DavidM - 02-06-2024, 01:14 PM
RE: HP49-50G: help for recursive - Gil - 02-06-2024, 01:29 PM
RE: HP49-50G: help for recursive - DavidM - 02-06-2024, 03:51 PM
RE: HP49-50G: help for recursive - Gil - 02-06-2024, 05:48 PM
RE: HP49-50G: help for recursive - DavidM - 02-06-2024, 08:51 PM
RE: HP49-50G: help for recursive - Gil - 02-06-2024, 08:53 PM
|
User(s) browsing this thread: 1 Guest(s)