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 
Return to the default flat view Create a new topic Submit Reply
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.")
[Message index]
 
Read Message
Read Message
Read Message
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: Fri Oct 10 12:41:46 PDT 2025

Total time taken to generate the page: 3.36106 seconds