Post Reply 
Interpolation Equation
07-08-2024, 01:23 AM
Post: #1
Interpolation Equation
The following is from my online Hydraulics and Hydrology class.

The required elevation for a volume of 0.46 acre-ft. is somewhere between 74 ft. and 75 ft. The
accumulated volumes are therefore between 0.39 acre-ft. and 0.65 acre-ft. Use the interpolation
equation to figure it out.


I never heard of the term interpolation equation. Is it the same as linear regression? I found
y - y1 = [(y2 - y1) / (x2 - x1)] (x - x1) on Wikipedia. I could easily write something for my HP 48G to crunch these numbers, but I figure there's already something on the HP 48G to do the same thing. There always seems to be a semantics issue involved when trying to figure out how to do something like this.

My class learning module gives an example of calculating this using Microsoft Excel, but since I can't read the blurry text in the formula bar, I'm resorting to doing the math on my calculator.
Find all posts by this user
Quote this message in a reply
07-08-2024, 01:29 AM
Post: #2
RE: Interpolation Equation
You already have the formula, and should be easy to write in in RPL. you need to input x1,y1,x2,y2,and x from the stack and sore them in named variables. The you write an rPL code for the equation using your named variables.

Simple!

Namir
Find all posts by this user
Quote this message in a reply
07-08-2024, 01:33 AM
Post: #3
RE: Interpolation Equation
   

BEST!
SlideRule
Find all posts by this user
Quote this message in a reply
07-08-2024, 02:09 PM
Post: #4
RE: Interpolation Equation
You could use linear regression:

[[.39 74]
 [.65 75]]
STOΣ
.46
PREDY

74.2692307692
Find all posts by this user
Quote this message in a reply
07-08-2024, 02:43 PM
Post: #5
RE: Interpolation Equation
There are a number of interpolation formulas depending on the number of points you use to interpolate with:
Check out section 25.2 of Handbook of Mathematical functions by Abramowitz and Stegun.
https://personal.math.ubc.ca/~cbm/aands/...stegun.pdf
Find all posts by this user
Quote this message in a reply
07-08-2024, 03:00 PM
Post: #6
RE: Interpolation Equation
(07-08-2024 02:09 PM)Thomas Klemm Wrote:  You could use linear regression:

[[.39 74]
 [.65 75]]
STOΣ
.46
PREDY

74.2692307692

Cool!
Find all posts by this user
Quote this message in a reply
07-08-2024, 06:12 PM (This post was last modified: 07-08-2024 06:24 PM by Gil.)
Post: #7
RE: Interpolation Equation
You could use this program INTERP, 
that works for n (n not too big) points :
it finds the exact Polynom that goes through the n points.

Code:

\<< "1) Create once Mat XY
 w/ the n given points
 [[x1 y1]
  [x2 y2]
  [   ]
  [xn yn]] in Stack 2
 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
    \>>
  \>>
\>>


Attached File(s)
.hp  INTERP.hp (Size: 722 bytes / Downloads: 2)
Find all posts by this user
Quote this message in a reply
07-08-2024, 07:32 PM (This post was last modified: 07-08-2024 07:37 PM by Thomas Klemm.)
Post: #8
RE: Interpolation Equation
(07-08-2024 02:09 PM)Thomas Klemm Wrote:  STOΣ

For those unfamiliar:
(08-02-2022 11:54 AM)Thomas Klemm Wrote:  I was pleasantly surprised by the following:

[LeftShift] ΣDATSTOΣ
[RightShift] ΣDATRCLΣ

Both make perfect sense once you understand how those shift keys work with variables.
Find all posts by this user
Quote this message in a reply
07-08-2024, 07:46 PM
Post: #9
RE: Interpolation Equation
It works for any variable :

[LeftShift] XXxxxx→ 'XXxxxx' STO
[RightShift] XXxxxx → 'XXxxxx' RCL
Find all posts by this user
Quote this message in a reply
07-08-2024, 08:13 PM
Post: #10
RE: Interpolation Equation
(07-08-2024 07:46 PM)Gil Wrote:  It works for any variable

There’s a difference between [ΣDAT] in the VAR menu and [ΣDAT] in the STAT DATA menu.
You will notice it if you press the [LeftShift] key within a program:
Code:
« 'ΣDAT' STO »
« STOΣ »
Find all posts by this user
Quote this message in a reply
07-08-2024, 08:19 PM
Post: #11
RE: Interpolation Equation
(07-08-2024 01:23 AM)MNH Wrote:  Is it the same as linear regression?

(02-10-2024 06:26 PM)Thomas Klemm Wrote:  For just two points \(P_1 = (x_1, y_1)\) and \(P_2 = (x_2, y_2)\) we want to solve the following linear system of equations:

\(
\begin{bmatrix}
x_1 & 1 \\
x_2 & 1 \\
\end{bmatrix}
\cdot
\begin{bmatrix}
a \\
b \\
\end{bmatrix}
=
\begin{bmatrix}
y_1 \\
y_2 \\
\end{bmatrix}
\)

This leads to:

\(
\begin{align}
a &= \frac{y_1 - y_2}{x_1 - x_2} \\
\\
b &= \frac{x_1 y_2 - x_2 y_1}{x_1 - x_2} \\
\end{align}
\)

However we solve instead the following system of equations:

\(
\begin{bmatrix}
\sum x^2 & \sum x \\
\sum x & n \\
\end{bmatrix}
\cdot
\begin{bmatrix}
a \\
b \\
\end{bmatrix}
=
\begin{bmatrix}
\sum xy \\
\sum y \\
\end{bmatrix}
\)

In case of \(n = 2\) the solutions are:

\(
\begin{align}
a
&= \frac{2(x_1 y_1 + x_2 y_2) - (x_1 + x_2)(y_1 + y_2)}{2 (x_1^2 + x_2^2) - (x_1 + x_2)^2} \\
&= \frac{(x_1 - x_2)(y_1 - y_2)}{(x_1 - x_2)^2} \\
&= \frac{y_1 - y_2}{x_1 - x_2} \\
\\
b
&= \frac{(x_1^2 + x_2^2)(y_1 + y_2) - (x_1 + x_2)(x_1 y_1 + x_2 y_2)}{2 (x_1^2 + x_2^2) - (x_1 + x_2)^2} \\
&= \frac{(x_1 - x_2)(x_1 y_2 - x_2 y_1)}{(x_1 - x_2)^2} \\
&= \frac{x_1 y_2 - x_2 y_1}{x_1 - x_2} \\
\end{align}
\)

Thus, we end up with the same result.
Find all posts by this user
Quote this message in a reply
07-09-2024, 10:37 AM
Post: #12
RE: Interpolation Equation
I would like to check my comprehension and test the formulas, could you please give me an example? Thank you in advance. Pedro
Find all posts by this user
Quote this message in a reply
07-09-2024, 11:09 AM
Post: #13
RE: Interpolation Equation
Linear regression line minimize Mean Squared Error (MSE)
For 2 points, it is the same as the secant line. (MSE = 0)

Proof: from secant line, we can get regression line formula.

a * x1 + b = y1      ... (1)
a * x2 + b = y2      ... (2)

(1) * x1 + (2) * x2:

a * (x1²+x2²) + b * (x1+x2) = (y1*x1 + y2*x2)      ... (3)

(1) + (2):

a * (x1+x2) + 2 * b = (y1+y2)      ... (4)

(3) and (4) are exactly n=2 linear regression formula.
Find all posts by this user
Quote this message in a reply
07-09-2024, 12:13 PM
Post: #14
RE: Interpolation Equation
(07-09-2024 10:37 AM)PedroLeiva Wrote:  could you please give me an example?

This is the example given by MNH:

HP-15C

f CLEAR Σ
74 ENTER
.39 Σ+
75 ENTER
.65 Σ+

.46 f ŷ,r

74.26923077



HP-42S

CLΣ
74 ENTER
.39 Σ+
75 ENTER
.65 Σ+

.46 FCSTY

74.2692307692
Find all posts by this user
Quote this message in a reply
07-09-2024, 12:22 PM
Post: #15
RE: Interpolation Equation
Thanks to both, Albert and Thomas. I have just found the formula and example in "HP25 Application Programs". If X1= 7.3, Y1= 1.9879; x2= 7.4, Y2= 2.0015; for Xn= 7.37, then Yn= 1.9974. The program only takes 16 steps (pages 85-86)
Find all posts by this user
Quote this message in a reply
07-09-2024, 12:51 PM
Post: #16
RE: Interpolation Equation
(07-09-2024 12:22 PM)PedroLeiva Wrote:  I have just found the formula and example in "HP25 Application Programs".

We've been there: Lagrangian Interpolation Post: #20
Find all posts by this user
Quote this message in a reply
07-09-2024, 01:00 PM
Post: #17
RE: Interpolation Equation
Yes, you are right. It was in March 2019, I was forgotten, sorry
Find all posts by this user
Quote this message in a reply
07-09-2024, 11:27 PM (This post was last modified: 07-09-2024 11:28 PM by Johnh.)
Post: #18
RE: Interpolation Equation
That simple use of linear regression with two points is really useful! Actually it may be more useful in day-to-day engineering than the more common use of LR with multiple points. Thanks! And it's so simple that there's no point in making a dedicated program.

Today's example for me in structural design: Design standards give us wind pressure coefficients at various building heights. To get the values at intermediate heights, we interpolate from the nearest values above and below.
Find all posts by this user
Quote this message in a reply
Post Reply 




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