在excel中,我记得能够选择一条称为"功率"的特定趋势线
,根据文档:"功率趋势线是一条曲线,最适合与数据集一起使用,这些数据集比较以特定速率增加的测量值 - 例如,赛车以一秒间隔加速。如果数据包含零值或负值,则无法创建幂趋势线。
如何在 matlab 中实现这一点?
例如:
a = [15.5156,0.1995;
7.6003,0.2999;
9.4829,0.2592;
12.2185,0.2239;
23.4094,0.1811];
figure;scatter(a(:,1),a(:,2))
这是一个有效的解决方案:
a = [15.5156,0.1995;
7.6003,0.2999;
9.4829,0.2592;
12.2185,0.2239;
23.4094,0.1811];
x = a(:, 1);
y = a(:, 2);
n = 2; % order of the fitted polynomial trendline
p = polyfit(x, y, n);
m = 1000; % number of trendline points (the larger the smoother)
xx = linspace(min(x), max(x), m);
yy = polyval(p, xx);
figure;
hold on;
scatter(a(:,1), a(:,2));
plot(xx, yy, 'r-');
您可以轻松地将趋势线计算器代码放入单独的函数中。
我在 excel 上绘制了您的数据,并使用以下等式添加了一条"功率"趋势线:
y = 0.7188 x^{-0.4513}
这当然是幂律。
Matlab 中的类似是对数据的对数-对数变换执行线性拟合(这解释了 excel 中"幂"趋势线应用程序施加的约束(:
x = a(:, 1);
y = a(:, 2);
p = polyfit(log(x), log(y), 1); % <-- linear fit
这给了
p =
-0.4513 -0.3302
要叠加趋势线,请喜欢@kol但使用幂律:
xx = linspace(min(x), max(x), 100);
yy = exp(p(2))*xx.^p(1);
figure;
hold on;
scatter(x, y);
plot(xx, yy, 'r-');
对于具有某些值<0 的xx
或yy
,在尝试此操作之前需要进行数据转移。