赞
踩
首先,您的问题不称为曲线拟合.曲线拟合就是在您拥有数据时,从某种意义上说,您可以找到描述它的最佳函数.另一方面,您希望创建函数的分段线性逼近.
我建议采取以下策略:
>手动拆分为部分.截面尺寸应取决于导数,大导数 – >小节
>在节之间的节点处对函数进行采样
>找到通过上述点的线性插值.
以下是执行此操作的代码示例.您可以看到红线(插值)非常接近原始函数,尽管部分数量很少.这是由于自适应部分大小而发生的.
function fitLogLog()
x = 2:1000;
y = log(log(x));
%# Find section sizes, by using an inverse of the approximation of the derivative
numOfSections = 20;
indexes = round(linspace(1,numel(y),numOfSections));
derivativeApprox = diff(y(indexes));
inverseDerivative = 1./derivativeApprox;
weightOfSection = inverseDerivative/sum(inverseDerivative);
totalRange = max(x(:))-min(x(:));
sectionSize = weightOfSection.* totalRange;
%# The relevant nodes
xNodes = x(1) + [ 0 cumsum(sectionSize)];
yNodes = log(log(xNodes));
figure;plot(x,y);
hold on;
plot (xNodes,yNodes,'r');
scatter (xNodes,yNodes,'r');
legend('log(log(x))','adaptive linear interpolation');
end
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。