views:

62

answers:

1

Hello,

Wondering if I'm barking up the wrong tree. I'd like a recursive function to give me the results of an n-linear interpolation, for example:

I'm applying discounts to vehicle prices. I have two types of discount: Volume and Age, such that

A. Volume = 10, Age = 10, discount = 100; Volume = 10, Age = 20, discount = 200;

B. Volume =20, Age = 10, discount = 200; Volume = 20 Age = 20, discount = 400;

I want to interpolate the following:

Volume = 15, Age =15 , discount = ??

On paper, what I would do is, using the formula yn =y0 + (x1 - xn) (y1 - y0/x1 - x0):

  1. From A, interpolate: Volume = 10, Age = 15, result = 150
  2. From B, interpolate: Volume = 20, Age = 15, result = 300
  3. From 1 and 2, interpolate Volume = 15, Age = 15, result = 225

Any ideas how to write that as a C# recursive function such that I can have any number of shocks ? Can it be represented that way?

If you need more info, let me know and many thanks in advance for any help.

A: 

I think simple iteration is the best approach here. I would start by finding the "nearest neighbor" or "nearest lower neighbor". Then iterate through your dimensions, and add offsets proportional to the jump to the next data point.

recursive
Thanks, I think you're right, having banged my head against the recursive wall for a couple of hours. Good fun, though.
bowthy