在对数-对数图中绘制一条最合适的线 [英] Drawing a line of best fit in a log-log plot

查看:149
本文介绍了在对数-对数图中绘制一条最合适的线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在对数对数图上绘制了两个矩阵,并确定了最佳拟合线的斜率,如下所示:

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);

这篇关于在对数-对数图中绘制一条最合适的线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆