comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Showing the least-squares line through a set of x,y points
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Showing the least-squares line through a set of x,y points [message #65314] Mon, 23 February 2009 09:55
bobbylough is currently offline  bobbylough
Messages: 7
Registered: February 2009
Junior Member
On Feb 22, 4:34 am, David Fanning <n...@dfanning.com> wrote:
> bobbylough writes:
>> I was wondering if it could be possible to plot the least-squares line
>> for a set of points on a 2D plot for a set of x,y points. This would
>> involve reading the set of points via a textfile initially and then
>> including additional syntax that would compute the "best-fit" line
>> (this is correctly called the line of least-squares) through these
>> points. I'm well capable of doing this in Excel but have had
>> difficulty tracking the correct commands in IDL. Many thanks for any
>> help you can give me on this problem.
>
> I would do something like this:
>
> IDL> x = indgen(20)
> IDL> y = 3*x + 5 + RandomU(-3L, 20) * 10
> IDL> plot, x, y, psym=2, symsize=2
> IDL> result = linfit(x, y, YFIT=yfit)
> IDL> oplot, x, yfit, thick=2
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Thanks David, worked a treat!!

Robert.
Re: Showing the least-squares line through a set of x,y points [message #65318 is a reply to message #65314] Sun, 22 February 2009 02:52 Go to previous message
a.mozafari1211 is currently offline  a.mozafari1211
Messages: 16
Registered: February 2009
Junior Member
On Feb 22, 5:34 am, David Fanning <n...@dfanning.com> wrote:
> bobbylough writes:
>> I was wondering if it could be possible to plot the least-squares line
>> for a set of points on a 2D plot for a set of x,y points. This would
>> involve reading the set of points via a textfile initially and then
>> including additional syntax that would compute the "best-fit" line
>> (this is correctly called the line of least-squares) through these
>> points. I'm well capable of doing this in Excel but have had
>> difficulty tracking the correct commands in IDL. Many thanks for any
>> help you can give me on this problem.
>
> I would do something like this:
>
> IDL> x = indgen(20)
> IDL> y = 3*x + 5 + RandomU(-3L, 20) * 10
> IDL> plot, x, y, psym=2, symsize=2
> IDL> result = linfit(x, y, YFIT=yfit)
> IDL> oplot, x, yfit, thick=2
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
LINFIT: minimized the CHI-square error statistic.
Cheers
Re: Showing the least-squares line through a set of x,y points [message #65319 is a reply to message #65318] Sat, 21 February 2009 20:34 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
bobbylough writes:

> I was wondering if it could be possible to plot the least-squares line
> for a set of points on a 2D plot for a set of x,y points. This would
> involve reading the set of points via a textfile initially and then
> including additional syntax that would compute the "best-fit" line
> (this is correctly called the line of least-squares) through these
> points. I'm well capable of doing this in Excel but have had
> difficulty tracking the correct commands in IDL. Many thanks for any
> help you can give me on this problem.

I would do something like this:

IDL> x = indgen(20)
IDL> y = 3*x + 5 + RandomU(-3L, 20) * 10
IDL> plot, x, y, psym=2, symsize=2
IDL> result = linfit(x, y, YFIT=yfit)
IDL> oplot, x, yfit, thick=2

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: nCDF_Browser Updated to Support HDF Files
Next Topic: Band+Lat+Lon = georeferenced file?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 02:46:59 PDT 2025

Total time taken to generate the page: 0.71874 seconds