[SciPy-User] point-curve distance estimation or calculation

Christopher Barker Chris.Barker@noaa....
Wed Jun 2 11:53:55 CDT 2010

Matthieu Rigal wrote:

> In the y = ax²+bx+c case, I know have a curve. I want to calculate or 
> estimate the distance between each point (combination of two data sets) 
> and the curve.

Usually, one is trying to find the "error", or difference between the y 
you get from the fitted curve and the actual y you have measured. This 
is also called the "residual". And if this is your case, it's really easy:

r = y1 - (ax²+bx+c)

where x is a 1-d array of your x values, and y1 is a 1-d array of the 
corresponding y values.

So I don't know why you need to use:

> Calculation is doable by applying this formula 
> http://mathcentral.uregina.ca/QQ/database/QQ.09.07/s/elliot1.php

Though if I have misunderstood, then you can still use that formula, and 
simply plug in a 1-d arrays of values, rather than scalar values, and 
numpy will do it all in c loops for you. If that still isn't fast 
enough, then there are tricks to reduce the amount of data copying going 
on -- post your code here and ask for help.

> Second, it may be better to get a close estimation of the distance to the 
> curve.

I'm still wondering if you really need the distance, in 2-d space to the 
curve, or if you need the difference between you measured value and the 
one predicted by the fitted curve. If the later, then it is the distance 
in the y-direction, not the closest distance, which is much easier (see 



Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception


More information about the SciPy-User mailing list