But why bother curve-fitting at all - just interpolate between points.
#include <stdio.h>
struct {
double x, y, k;
} data[] =
{
{ 2.75, 150.00 }, // volt, mm
{ 2.55, 200.00 },
{ 2.00, 300.00 },
{ 1.55, 400.00 },
{ 1.25, 500.00 },
{ 1.15, 600.00 },
{ 0.90, 700.00 },
{ 0.80, 800.00 },
{ 0.75, 900.00 },
{ 0.65, 1000.00 },
{ 0.60, 1100.00 },
{ 0.55, 1200.00 },
{ 0.50, 1300.00 },
{ 0.44, 1400.00 }
};
double get_value(double i_value) {
int i;
// Find where we are interpolating
for(i = 0; i < sizeof(data)/sizeof(data[0])-2; i++) {
if(i_value > data[i+1].x) {
break;
}
}
return data[i].y + (i_value-data[i].x) * data[i].k;
}
int main(int argc, char *argv[]) {
// Calc some constants
for(int i = 0; i < sizeof(data)/sizeof(data[0])-1; i++) {
data[i].k = (data[i+1].y-data[i].y) / (data[i+1].x-data[i].x);
}
// Check against the table values
for(int i = 0; i < sizeof(data)/sizeof(data[0]); i++) {
printf("%5.2f, %7.2f, %7.2f\n", data[i].x, data[i].y, get_value(data[i].x));
}
// Check between two numbers
printf("\n%5.2f, %7.2f, %7.2f\n", 0.85, 750.00, get_value(0.85));
}