Test Machine Linearizer

P. McGill
v1.0.0

Enter a table of the input and output values of the linearizer.

data={{9.90,9.90},{9.16,9.22},{8.42,8.54},{7.71,7.86},{7.05,7.18},{6.43,6.50},{5.82,5.82},{5.21,5.14},{4.60,4.46},{3.98,3.78},{3.33,3.10},{2.62,2.42},{1.87,1.74},{1.12,1.06},{0.39,0.38}, {0.11,0.11}};

data=Reverse[data]

dataplot=ListPlot[data,{PlotRange->{{0,10},{0,10}},PlotStyle->Red}];

Show[dataplot,Plot[x,{x,0,10}]]

Do a least-squares fit to a cubic.

cubiccurvefit=Fit[data,{1,x,x^2,x^3},x]

cubiccurvefitplot=Plot[cubiccurvefit,{x,0,10}];

Show[dataplot,cubiccurvefitplot]

Find the error as the curve fit output minus the ideal output (i.e. actual minus desired). Note that this is a table of errors ranging from the first data point to the sixteenth data point.

cubicerror[i_]:=cubiccurvefit-data[[i,2]]/.x->data[[i,1]]

cubicerrors=Table[cubicerror[i],{i,16}]

ListPlot[cubicerrors,PlotStyle->Red]

Let’s look at the error as a percentage of full scale:

cubicpercenterrors=Table[100 cubicerror[i]/9.90,{i,16}];

ListPlot[cubicpercenterrors,{PlotStyle->Red,PlotRange->All}]

What position error does this correspond to?

Max[Abs[cubicpercenterrors]] 72 inches/100

Not so great. Can we reduce the error with a quartic fit?

quarticcurvefit=Fit[data,{1,x,x^2,x^3,x^4},x]

quarticcurvefitplot=Plot[quarticcurvefit,{x,0,10}];

Show[dataplot,quarticcurvefitplot]

Find the error as the curve fit output minus the ideal output:

quarticerror[i_]:=quarticcurvefit-data[[i,2]]/.x->data[[i,1]]

quarticerrors=Table[quarticerror[i],{i,16}];

ListPlot[quarticerrors,PlotStyle->Red]

Let’s look at the error as a percentage of full scale:

quarticpercenterrors=Table[100 quarticerror[i]/9.90,{i,16}];

ListPlot[quarticpercenterrors,PlotStyle->Red]

Looks better, but how good is it?

Max[Abs[quarticpercenterrors]] 72 inches/100

Is this good enough?