使用polyfit进行垂直线拟合 [英] Vertical line fit using polyfit

查看:221
本文介绍了使用polyfit进行垂直线拟合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这只是一个基本问题.我正在使用polyfit拟合线以分散点. 在某些情况下,我的散点具有相同的X值,并且polyfit无法对其拟合直线.必须有可以处理这种情况的东西.毕竟,这只是一条线.

Its just a basic question. I am fitting lines to scatter points using polyfit. I have some cases where my scatter points have same X values and polyfit cant fit a line to it. There has to be something that can handle this situation. After all, its just a line fit.

我可以尝试交换X和Y,然后换行.任何更简单的方法,因为我有很多分散点集,并希望使用通用方法来检查线.

I can try swapping X and Y and then fir a line. Any easier method because I have lots of sets of scatter points and want a general method to check lines.

主要目标是找到合适的线条并删除非线性特征.

Main goal is to find good-fit lines and drop non-linear features.

推荐答案

首先,这是由于您使用的拟合方法而发生的.进行polyfit时,您在距直线Y的距离上使用最小二乘法.

First of all, this happens due to the method of fitting that you are using. When doing polyfit, you are using the least-squares method on Y distance from the line.


(来源: une.edu.au )


(source: une.edu.au)

显然,它不适用于垂直线.顺便说一句,即使您有一些接近垂直线的地方,也可能会得到数值不稳定的结果.

Obviously, it will not work for vertical lines. By the way, even when you have something close to vertical lines, you might get numerically unstable results.

有2种解决方案:

  1. 如您所说,交换x和y,如果您知道直线几乎是垂直的.然后,计算线性逆函数.
  2. 在与直线垂直的距离上使用最小二乘,而不是垂直(请参见下图)(
    (摘自MathWorld-Wolfram网络资源:
    wolfram.com )


    (from MathWorld - A Wolfram Web Resource: wolfram.com)

    这篇关于使用polyfit进行垂直线拟合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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