redsun001
11-03-2017, 02:47 PM
Hi all,
I have to do linear interpolation and extrapolation for a given data given below (This data can be extended). I am trying to use an if function to do it but still finding it difficult to understand what conditions to use for if function. There are certain things I need to do... If someone can please help me with the code. It will be hugely appreciated it. Example given below:
A
B
x
y
1
10
2
25
3
50
4
65
6
75
7
85
8
100
9
125
10
150
This is an example data which needs to be interpolated. Let's say I have to find the data point in column B for value of 5 from Column. I realise there are initial steps I need to take to find this.
1. Need to find if the value exist within this range("A") and find its closest larger and smaller number from Column A and B
2. I need to hold those values so that I can interpolate using equation: y = y1 + (x - x1) *(y2-y1)/(x2-x1)
Also, on side note: how do i make this range as an array; should i treat x and y values as different arrays or can I define it as multidimensional array. If latter is correct, how will it be able to find larger and smaller value for x and y from a multidimensional array.
I might be able to figure out extrapolation once I have the code set up for Interpolation. Sorry, if this is too much of trouble. I am still learning how to use vba properly.
/thanks
I have to do linear interpolation and extrapolation for a given data given below (This data can be extended). I am trying to use an if function to do it but still finding it difficult to understand what conditions to use for if function. There are certain things I need to do... If someone can please help me with the code. It will be hugely appreciated it. Example given below:
A
B
x
y
1
10
2
25
3
50
4
65
6
75
7
85
8
100
9
125
10
150
This is an example data which needs to be interpolated. Let's say I have to find the data point in column B for value of 5 from Column. I realise there are initial steps I need to take to find this.
1. Need to find if the value exist within this range("A") and find its closest larger and smaller number from Column A and B
2. I need to hold those values so that I can interpolate using equation: y = y1 + (x - x1) *(y2-y1)/(x2-x1)
Also, on side note: how do i make this range as an array; should i treat x and y values as different arrays or can I define it as multidimensional array. If latter is correct, how will it be able to find larger and smaller value for x and y from a multidimensional array.
I might be able to figure out extrapolation once I have the code set up for Interpolation. Sorry, if this is too much of trouble. I am still learning how to use vba properly.
/thanks