HP Forums
Interpolation linear f(x0,x¹x²), quadratic f(x0, x¹x²x³), cubic f(x0,x¹x²x³x⁴), etc. - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: Interpolation linear f(x0,x¹x²), quadratic f(x0, x¹x²x³), cubic f(x0,x¹x²x³x⁴), etc. (/thread-15151.html)



Interpolation linear f(x0,x¹x²), quadratic f(x0, x¹x²x³), cubic f(x0,x¹x²x³x⁴), etc. - Gil - 06-06-2020 08:44 PM

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


RE: HP 49G/ HP50G : Interpolation linear, quadratic, cubic, etc. - Gil - 07-11-2020 01:20 AM

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


RE: HP 49G/ HP50G : Interpolation linear, quadratic, cubic, etc. - Gil - 01-12-2023 02:14 PM

File with .hp ending.