Post Reply 
Interpolation linear f(x0,x¹x²), quadratic f(x0, x¹x²x³), cubic f(x0,x¹x²x³x⁴), etc.
06-06-2020, 08:44 PM (This post was last modified: 01-13-2023 12:31 PM by Gil.)
Post: #1
Interpolation linear f(x0,x¹x²), quadratic f(x0, x¹x²x³), cubic f(x0,x¹x²x³x⁴), etc.
For HP49-HP50
Small interpolation program.

Valid for 2 points (linear solution) and
for 3 points (quadratic function).
Valid also for 4 points (cubic function).
Valid also for 5 points, 6, 7, 8,...,68, 69, 70, 71... points.

It is not a linear regression program :
the function calculated here goes really exactly through all the given points.

Once you have introduced the points in the calculator (stared / stored in matrix XY), you get the requested result in one single step (numbers 3 and4 below).

Observation 1
The program works in RPN mode.

Suppose you have the two points
A(1;10), B(2;20).
Find a function that goes exactly through them.
Find f(x=1.7) = 17

Solution
1) Write Matrix XY:
[[1 10]
[2 20]]
ENTER[/b]

2) Save/store it in XY:
'XY' STO

3)Press
1.7 INTERPOL

4) New values of xo,
for example f(1.9) :
skip steps 1 and 2
Press 1.9 INTERPOL

Suppose now that you have the 3 points
A(1;10), B(2;20), C(3;35).
Find a function that goes exactly through them.
Find f(x=1.7) = 16.475

Solution
1) Write Matrix XY:
[[1 10]
[2 20]
[3 35]]
ENTER

2) Save/store it again in XY:
'XY' STO

3)Press
1.7 INTERPOL

4) New values of xo,
for example f(1.9) :
skip steps 1 and 2
Press 1.7 INTERPOL

Suppose now that you have n points
A(1;10), B(2;20), C(3;35)... ZZn(n; f(n)).
Find a function that goes exactly through them.
Find f(x=1.7)

Solution
1) Write Matrix XY:
[[1 10]
[2 20]
[3 30]
[... ....]
[n f(n)]]
ENTER

2) Save/store it again in XY:
'XY' STO

3)Press
1.7 INTERPOL

4) New values of xo,
for example f(1.9) :
skip steps 1 and 2
Press 1.7 INTERPOL

Observation 2
You can have already the first coordinate xi of all the points saved in matrix X.
All the second coordinates yi of all the points already in matrix Y.
To build the requested matrix XY:
1) X ENTER
2) Y ENTER
3) 2 COL+
4) 'XY' STO
Then 1.7 INTERPOL

Hope that it is useful.

Regards,
Gil


Attached File(s)
.hp  INTERPOL.hp (Size: 722 bytes / Downloads: 3)
Find all posts by this user
Quote this message in a reply
07-11-2020, 01:20 AM (This post was last modified: 01-12-2023 02:13 PM by Gil.)
Post: #2
RE: HP 49G/ HP50G : Interpolation linear, quadratic, cubic, etc.
New version 1.2 with slight changes : explanations for the arguments given at the beginning of the program and explanations given how to build once for all the matrix XY with the n given points.

Two separate files in the directory called interp.1.2doc:
- the "n-points" Matrix XY
- and the program itself.

Just copy / transfer
the directory called interp.1.2.doc in your calculator or phone EMU48 Android application.

Code for the program itself:
\<< "1) Create once Mat XY
w/ the n given points
[[x1 y1]
[x2 y2]
[  ]
[xn yn]] 'XY' STO
2)Arg:value xo INTERP
3)Repeat step 2)
for other values xo
" DROP XY \-> xo XY
\<< XY SIZE OBJ\-> 1 ==
IF
THEN DROP XY OBJ\-> 1 SWAP + \->ARRY 'XY' STO
ELSE DROP2
END XY SIZE 1 GET 1 ==
IF
THEN XY DUP 2 * 2 ROW+ 'XY' STO
END XY 1 COL- DUP SIZE OBJ\-> DROP 1 - \-> x size
\<< 1 size 1 +
FOR i 0 size
FOR j x i GET j ^
NEXT
NEXT size 1 + DUP 2 \->LIST \->ARRY / "a0\183x^0"
IF size 1 >
THEN "+" +
END "+a" + size \->STR DUP SIZE 1 - 1 SWAP SUB + "\183x^" + size \->STR DUP SIZE 1 - 1 SWAP SUB + \->TAG DUP TRN 0 size
FOR i xo i ^
NEXT size 1 + 1 2 \->LIST \->ARRY * OBJ\-> DROP "y(" xo + ")" + \->TAG
\>>
\>>
\>>

Remarks welcome.

Regards,
Gil


Attached File(s)
.hp  INTERPOL.hp (Size: 722 bytes / Downloads: 6)
Find all posts by this user
Quote this message in a reply
01-12-2023, 02:14 PM (This post was last modified: 01-12-2023 02:14 PM by Gil.)
Post: #3
RE: HP 49G/ HP50G : Interpolation linear, quadratic, cubic, etc.
File with .hp ending.


Attached File(s)
.hp  INTERPOL.hp (Size: 722 bytes / Downloads: 3)
Find all posts by this user
Quote this message in a reply
Post Reply 




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