在对数-对数图中绘制一条最合适的线
问题描述:
我在对数对数图上绘制了两个矩阵,并确定了最佳拟合线的斜率,如下所示:
I have graphed two matrices on a log-log plot and I determined the slope of the line of best fit with the following:
loglog(x,y);
polyfit(log(width_matrix),log(error_matrix),1)
是否有可能在同一对数-对数图上绘制最佳拟合线,并可能在图形上包括其方程式?
Is it possible to draw the line of best fit on the same log-log plot and perhaps include its equation on the graph?
答
figure; hold on;
loglog(x, y, '.');
% fit in log domain
p = polyfit(log(x), log(y), 1);
% compute fit in linear domain
y_hat = exp(p(1) * log(x) + p(2));
% make log log plot
loglog(x, y_hat);
label = ['log(y) = ' num2str(p(1)) 'log(x) + ' num2str(p(2))];
legend('data', label);