Interpolation algorithms

Posted on 2013-09-19
Medium Priority
Last Modified: 2013-09-20

I want to implement interpolation algorithms..I can only find papers or description about it...Is there any site or anything that gives info on how to implement it ..
For example, meshgrid, linspace ...something to get someone started ...
Question by:zizi21
LVL 16

Expert Comment

ID: 39505687
Interpolation is simple mathematics.  The basic premise is you know the value of point A and you know the value of point C and you want to know the value of point B that you know is 30% of the way between A and C.  So you take the value of A and and 30% of the difference between A and C (linear interpolation).

So if A = 100 and C = 200, then B located 30% of the way to C from A is 130.

What more do you need... what exactly are you trying to interpolate?
LVL 40

Expert Comment

ID: 39505772
The GNU Science Library supports a range of interpolation methods.

If you don't need to reinvent the wheel and you can use this library that would be my recommendations.

Author Comment

ID: 39505783
I am looking for Inverse_distance_weighting
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

LVL 37

Accepted Solution

TommySzalapski earned 2000 total points
ID: 39505968
Inverse distance weighting is very simple. You just take each point and multiply it by some function. The simplest function is 1/d (where d is the distance to the point). Some people use 1/d^2 or some other function.

So you would take all the points, calculate their distance from the target point, and compute the weighted average.
Example in untested C++ code
struct Point
   double x;
   double y;
   double value;

double InverseDistanceWeight(Point &target, Point allPoints[], int count)
   double total = 0;
   double sum = 0;
   double distance, weight, value;
   for (int i = 0; i < count; ++i)
      // Euclidean distance
      distance = sqrt(pow(target.x - allPoints[i].x, 2) + pow(target.y - allPoints[i].y, 2));
      weight = 1/distance; // the weighting function
      value = weight * allPoints[i].value; // the adjusted value
      total += value; // sum it all up
      sum += weight;

   // get the weighted average
   target.value = total/sum;

Open in new window


Author Comment

ID: 39507223
Thanks a lot...I am studying it now...

Author Comment

ID: 39507288
I am confussed. Say, I have this data set. These points are allPoints[]

x=10, y=10, value=1,
x=20, y=25, value=2,
x=40, y=40, value=3

Am i correct in understanding that i would need to do a linspace on my own..
for example,
x=15, y = 15, value=?
x=25, y=35, value=?

These above points are called target? Is that right ?
LVL 37

Expert Comment

ID: 39507391
Yes. If you did a linspace to add points, then ran each of those new points through the InverseDistanceWeight function (using only the original points in the array), you would get the result I think you want.

Author Closing Comment

ID: 39508325
Apologies for the late reply as i lost internet connection for the day.

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

When we purchase storage, we typically are advertised storage of 500GB, 1TB, 2TB and so on. However, when you actually install it into your computer, your 500GB HDD will actually show up as 465GB. Why? It has to do with the way people and computers…
What to do if a split doesn't fit? Or a bunch of invoice lines must be rounded while the sum must match a total? It takes a little, but - when done - it is extremely easy to implement.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question