Post Reply 
What comes next?
10-10-2024, 02:55 PM (This post was last modified: 10-15-2024 09:52 AM by Gil.)
Post: #6
RE: What comes next?
Thanks for the Mathologer video, Thomas.

Here is my version of the Gregory-Newton Interpolation formulae for the HP50G.

Argument:
A non-empty list,
the 1st number being always = f(0),
the 2nd being = f(1),
the 3rd being = f(2), etc.

Example :
{0 1 4 9} NextN

and the result will be:
{ 0 1 4 9 }
f(x): 'x^2'
f(4): 16

Don't forget :
to put a zero for the 1st element in the above example list if you expect to get x². Remember: first element in the list is always f(0), ie in this example 0²=0.

If you put {1 4 9} instead,

then the program supposes that f(0) = 1, f(1) = 4 and f(2) =9, whose solution is obviously not x².

Result for {1 4 9} NextN:
{ 1 4 9 }
f(x): 'x^2+2*x+1'
f(3): 16

Example of Mathologer
{1 2 4 8 16 31} NextN

and the result will be:
{ 1 2 4 8 16 31 }
:f(x): '1/24*x^4-1/12*x^3+11/24*x^2+7/12*x+1'
f(6): 57

Attention again: suppose that the sequence were
{0 1 2 4 8 16 31}

then {0 1 2 4 8 16 31} NextN:
will give the following output:
{ 0 1 2 4 8 16 31 }
f(x): '-1/720*x^6+7/240*x^5-29/144*x^4+37/48*x^3-467/360*x^2+17/10*x'
f(7): 56

From last example, calculate for instance f(2.5):
a) DROP
2.5 'x' STO
EVAL
and you get 2.8291015625
b) or
-105 CF
25 ENTER 10 /
'x' STO
EVAL
and you get '2897/1024'.

Code below slightly changed in comparison to previous versions

Code:

\<< "Arg
{ f(0) f(1) f(2)f(n)}
Ex: { 0 1 4 9 16 24 }

Result: f(n+1)
Here: 30
" DROP DUP DUP DUP SIZE R\->I \-> L s
  \<< s 1 ==
    IF
    THEN DROP L 1 GET DUP FP 0 == { R\->I } IFT "f(x)" \->TAG
    ELSE 1 GET DUP FP 0 == { R\->I } IFT 1 \->LIST 2 s
      FOR i { } 2 s i 2 - -
        FOR j L j GET L j 1 - GET - +
        NEXT DUP 'L' STO 1 GET DUP FP 0 == { R\->I } IFT +
      NEXT -114 CF -105 CF 'x' PURGE 'L' STO 0 0 s 1 -
      FOR i L i 1 + GET DUP 0 ==
        IF
        THEN
        ELSE i R\->I DUP DUP DUP
          CASE 0 ==
            THEN 3 DROPN 1
            END 1 ==
            THEN DROP2 x
            END x 1 ROT 1 -
            FOR i x i R\->I - *
            NEXT SWAP ! /
          END EVAL *
        END +
      NEXT 1 s
      FOR i L i GET TYPE 0 ==
        IF
        THEN s 'i' STO -105 SF
        END
      NEXT EXPAN \->STR 11 14
      FOR i ".E-" i R\->I + "*0" SREPL DROP
      NEXT ".+" "+" SREPL DROP ".-" "-" SREPL DROP ".*" "*" SREPL DROP ".'" "'" SREPL DROP "." "." SREPL 0 ==
      IF
      THEN -105 CF
      END OBJ\-> EVAL EXPAN \->STR "+-" "-" SREPL DROP OBJ\-> "f(x)" \->TAG DUP EVAL s 'x' STO EVAL DUP FP 0 == { R\->I } IFT "f(" s R\->I + ")" + \->TAG 'x' PURGE
    END
  \>>
\>>


Attached File(s)
.hp  Next_NumberV8.hp (Size: 1 KB / Downloads: 1)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
What comes next? - Thomas Klemm - 10-08-2024, 12:26 AM
RE: What comes next? - chromos - 10-08-2024, 05:16 AM
RE: What comes next? - John Keith - 10-08-2024, 12:14 PM
RE: What comes next? - Thomas Klemm - 10-08-2024, 02:31 PM
RE: What comes next? - Thomas Klemm - 10-10-2024, 05:54 AM
RE: What comes next? - Gil - 10-10-2024 02:55 PM
RE: What comes next? - Thomas Klemm - 10-10-2024, 08:24 PM
RE: What comes next? - Gil - 10-10-2024, 09:17 PM
RE: What comes next? - Thomas Klemm - 10-11-2024, 03:12 AM
RE: What comes next? - C.Ret - 10-13-2024, 12:35 PM
RE: What comes next? - Thomas Klemm - 10-13-2024, 06:08 PM
RE: What comes next? - Geoff Quickfall - 10-13-2024, 06:33 PM
RE: What comes next? - John Keith - 10-13-2024, 08:49 PM
RE: What comes next? - Thomas Klemm - 10-14-2024, 02:14 AM
RE: What comes next? - Thomas Klemm - 10-14-2024, 06:21 AM
RE: What comes next? - Gilles - 10-14-2024, 08:35 PM
RE: What comes next? - John Keith - 10-15-2024, 05:39 PM
RE: What comes next? - FLISZT - 10-15-2024, 10:59 PM
RE: What comes next? - Thomas Klemm - 10-15-2024, 03:39 AM
RE: What comes next? - Gil - 10-15-2024, 10:09 AM
RE: What comes next? - Thomas Klemm - 10-15-2024, 11:41 AM
RE: What comes next? - Gil - 10-15-2024, 01:34 PM
RE: What comes next? - Gil - 10-15-2024, 01:53 PM
RE: What comes next? - Gilles - 10-15-2024, 04:08 PM
RE: What comes next? - John Keith - 10-15-2024, 09:09 PM
RE: What comes next? - Thomas Klemm - 10-15-2024, 02:53 PM
RE: What comes next? - Thomas Klemm - 10-15-2024, 03:08 PM
RE: What comes next? - Thomas Klemm - 10-16-2024, 12:56 AM
RE: What comes next? - Thomas Klemm - 10-16-2024, 04:51 AM
RE: What comes next? - Gil - 10-16-2024, 10:14 AM
RE: What comes next? - Thomas Klemm - 10-16-2024, 11:41 AM
RE: What comes next? - Gil - 10-16-2024, 01:17 PM
RE: What comes next? - John Keith - 10-16-2024, 04:54 PM
RE: What comes next? - Gilles - 10-16-2024, 07:45 PM
RE: What comes next? - Thomas Klemm - 10-16-2024, 08:38 PM
RE: What comes next? - Thomas Klemm - 10-17-2024, 05:15 AM
RE: What comes next? - Gil - 10-17-2024, 10:16 AM
RE: What comes next? - Gilles - 10-18-2024, 07:53 PM
RE: What comes next? - Gil - 10-18-2024, 10:49 PM
RE: What comes next? - John Keith - 10-18-2024, 11:57 PM
RE: What comes next? - FLISZT - 10-19-2024, 12:03 AM
RE: What comes next? - Albert Chan - 10-19-2024, 01:29 AM
RE: What comes next? - Thomas Klemm - 10-19-2024, 12:03 AM
RE: What comes next? - Thomas Klemm - 10-19-2024, 12:17 AM
RE: What comes next? - Gil - 10-19-2024, 01:00 AM
RE: What comes next? - Thomas Klemm - 10-19-2024, 08:12 AM
RE: What comes next? - Albert Chan - 10-19-2024, 09:09 PM
RE: What comes next? - Albert Chan - 10-20-2024, 08:44 PM
RE: What comes next? - Gil - 10-19-2024, 06:08 PM
RE: What comes next? - Thomas Klemm - 10-19-2024, 11:25 PM
RE: What comes next? - Thomas Klemm - 10-20-2024, 09:39 PM



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