1.从公式来说,非线性误差(Non-linearity error)的计算公式(单位和Y,X有关):
非线性误差=100*|Max(Y-Y0)|/(Xmax-Xmin)
2,为了便于分析不同y值下非线性误差,取无量纲下的非线性误差(单位是百分比) :
非线性误差=Max(Y-Y0)|/max(Y)
举例:
求x和y之间的非线性误差,其中
x = [ 1 2 3 4 5 6 7 8 9 10 ];
y = [ 10 21 35 44 50 66 79 99 120 150];
x = [ 1 2 3 4 5 6 7 8 9 10 ];
y = [ 10 21 35 44 50 66 79 99 120 150];
num = length(x);
y_max = max(y) ;
%---------------------------
p = polyfit(x,y,1) %拟合系数
y1 = polyval(p , x);
for i = 1: 1: num
re(i) = abs( y(i) - y1(i) ) / y_max;
end
nonlinearity_error = max(re)
%-----------------------
figure(11)
plot(x,y,'r^')
hold on
plot(x,y1,'b')
xlabel('X')
ylabel('Y')
set(gca,'FontName','Times New Roman','FontSize',14)
set(get(gca,'XLabel'),'FontSize',14);set(get(gca,'XLabel'),'FontName','Times New Roman');
set(get(gca,'YLabel'),'FontSize',14);set(get(gca,'YLabel'),'FontName','Times New Roman');
set(get(gca,'title'),'FontSize',14);set(get(gca,'title'),'FontName','Times New Roman');
grid on
nonlinearity_error =
0.115393939393939
则此时无量纲下的非线性误差是11.539%。