Interpolation Problem?

24 Views Asked by At

I'm making a computer program and I ran into a problem of mapping/interpolating number from one range into another. I've formalized it as a mathematics problem. Look over it and I'd appreciate your insights.

There is a function $f:[a,b]\to[10,100]$ for fixed $(a, b, p)$ such that:

  • $f(a)=10$
  • $f(p)=45$ for some arbitary $p$
  • $f(b)=100$

How to find the value of $f(p_o)$ where $ a\leq p_o \leq b$

Few Notes:

  1. The closer $p$ is to $a$, the more drastically the value of $f(p_o)$ should change if $ a \leq p_o \leq p$. Similarly, the closer $p$ is to $b$, the more drastically the value of $f(p_o)$ should change if $ p \leq p_o \leq b$.

Thank you!

2

There are 2 best solutions below

3
On

How about a straight line joining $(a,10)$ to $(p,45)$ and then a straight line from $(p,45)$ to $(b,100)$? That's about as linear as you can get. For exactly one value of $p$ it will be a single line.

As an alternative, you can fit a unique quadratic curve $rx^2 + sx + t$ through those three points. Finding the coefficients in terms of $a$, $b$ and $p$ is three linear equations in three unknowns. Draw a few to see if they look right for your application.

0
On

you could use Lagrange polynomial interpolation which gives: $$f(x)=\frac{10(x-p)(x-b)}{(a-p)(a-b)}+\frac{45(x-a)(x-b)}{(p-a)(p-b)}+\frac{100(x-a)(x-p)}{(b-a)(b-p)}$$ now sub in and you get a formula for $f(p_0)$