Post Reply 
HP49-50G: help for recursive
02-02-2024, 06:13 PM (This post was last modified: 02-03-2024 12:26 PM by Gil.)
Post: #5
RE: HP49-50G: help for recursive
Thanks, Albert, for your replies.

Both following functions FNL & FNL4 work nicely.

With function FLN, no recursive process :

1) save the intermediate values of x in a list
2) pick the values of the list to build fln=... ; fln=... fln=...
« 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

With recursive changed FLN4
suppression of unused 'fnl' variable

[b]FNL4

« 0 0 -> x X2 X4
«
IF x ABS .4 >=
THEN 'x/(sqrt(1+x
)+1)' ->NUM DUP

FNL4
2 *SWAP 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
»
»
FNL4' STO

Code:
\<< 0 0 \-> x X2 X4
  \<<
    IF x ABS .4 \>=
    THEN 'x/(\v/(1+x)+1)' \->NUM DUP FNL4 2 * SWAP 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
  \>>
\>>

Question
Suppose now that the red instructions were a complicated function of x, and that we wanted to avoid to play with the stack with SWAP, DUP, etc. commands, how could we use instead the variable x here?
I ask, because, by writing 2 * x² after FLN4, the program does not take the last x[n], but always the previous one, ie x[n-1], as at the end of the IF... THEN... END, it closes one ».
Find all posts by this user
Quote this message in a reply
Post Reply 


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 - 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 - 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)