Re: Showing the least-squares line through a set of x,y points [message #65314] |
Mon, 23 February 2009 09:55 |
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  |
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  |
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.")
|
|
|