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

Home » Public Forums » archive » Re: least square error for a regression
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: least square error for a regression [message #41040 is a reply to message #41037] Wed, 15 September 2004 17:25 Go to previous message
Kenneth P. Bowman is currently offline  Kenneth P. Bowman
Messages: 585
Registered: May 2000
Senior Member
In article <ciafmg$al3$1@sunburst.ccs.yorku.ca>,
"yaj" <tgupta2000@hotmail.com> wrote:

> Hello,
> I am fitting a function of the form
> ASin(wt + theta) + constant to a set of points. Instead of a readymade
> fitting routine from IDL (to avoid any potential problems with small numbers
> later), I use the three linear equations to minimize the least square error,
> then use an IDL function to solve the matrix equation. Could someone suggest
> a simple way to calculate the least squares error and goodness of fit using
> some higher level IDL functions ?
> Thanks in advance
> Y. Bhattacharya
> yajnaval_at-hotmail
>
>

I think you want something like this:

n = 32
eps = 0.1D0
x = DINDGEN(n)/n
y = COS(2.0D0*!DPI*x - !DPI/4) + eps*RANDOMN(seed, n, /DOUBLE)

c = COS(2.0*!PI*x)
s = SIN(2.0*!PI*x)
f = TRANSPOSE([[c], [s]])

coeff = REGRESS(f, y, CONST = a0, YFIT = yfit, CHISQ = chisq, FTEST =
ftest, /DOUBLE)

a = coeff[0]
b = coeff[1]
amp = SQRT(a^2 + b^2)
phz = ATAN(b, a)

PRINT, a0, a, b, amp, phz, chisq, ftest

PLOT, x, y
OPLOT, x, yfit


Regards, Ken Bowman
[Message index]
 
Read Message
Read Message
Previous Topic: OO IDL
Next Topic: Re: OO IDL

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

Current Time: Sat Oct 11 04:29:29 PDT 2025

Total time taken to generate the page: 0.56850 seconds