Function for line chart: Linear Interpolation Missing values
Posted: Sat Aug 14, 2010 10:39 am
I am building a line graph from an array that is built from a db of user entered data.
What I need help with is adding any missing values. (Linear Interpolation)
Figuring out the value if there is only 1 value missing is simple (start value+end value/2), but if there is more than 1 value missing in a row it becomes more difficult.
1 missing value example:
$sample=array(1.3,2.1,,4.7);
how to figure it out: the missing value is this case is (2.1+4.7)/2 = 3.4
2 missing value example:
$sample=array(2.4,3.1,,,6.9);
how to figure it out: ??
I need a php function that accepts 3 vars and returns the calculated values for each of the missing values. (I guess it makes sense to return the calculated values in an array)
function buildMissingValues($startValue,$endValue,$numberOfMissingValues){
//brilliant code here
}
In the above "2 missing value" example I would like to:
$newValues=buildMissingValues(3.1,6.9,2);
and have an array returned with 2 values that complete the line chart points.
I'm not sure if I have explained this well enough.
I REALLY appreciate your help!!
What I need help with is adding any missing values. (Linear Interpolation)
Figuring out the value if there is only 1 value missing is simple (start value+end value/2), but if there is more than 1 value missing in a row it becomes more difficult.
1 missing value example:
$sample=array(1.3,2.1,,4.7);
how to figure it out: the missing value is this case is (2.1+4.7)/2 = 3.4
2 missing value example:
$sample=array(2.4,3.1,,,6.9);
how to figure it out: ??
I need a php function that accepts 3 vars and returns the calculated values for each of the missing values. (I guess it makes sense to return the calculated values in an array)
function buildMissingValues($startValue,$endValue,$numberOfMissingValues){
//brilliant code here
}
In the above "2 missing value" example I would like to:
$newValues=buildMissingValues(3.1,6.9,2);
and have an array returned with 2 values that complete the line chart points.
I'm not sure if I have explained this well enough.
I REALLY appreciate your help!!