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

Home » Public Forums » archive » curve fitting: works badly?
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
curve fitting: works badly? [message #3672] Mon, 06 March 1995 08:19 Go to next message
feil is currently offline  feil
Messages: 1
Registered: March 1995
Junior Member
I try to use CURVEFIT to get some simple data fitted to an harmonic
oscillator.

Somehow things don't work very good.


these are the datapoints:

i x(i) y(i)

0 8 6.5550 -0.3052
1 8 6.6233 -0.3076
2 8 6.6915 -0.3088
3 8 6.7598 -0.3091
4 8 6.8281 -0.3086
5 8 6.8281 -0.3086
6 8 6.8964 -0.3074
7 8 6.9647 -0.3054


the calling sequence:

;;-------------------- fit to harmonic oscillator ------------------------

a = fltarr(3)
; start estimates
a(0) = etot(icnt/2)
dx = lattice(1)-lattice(0)
a(1) = (etot(2)+etot(0)-2*etot(1))/(dx*dx)
a(2) = lattice(icnt/2)

w = fltarr(icnt)
for i = 0,icnt-1 do begin
w(i) = 1.
end


yfit = mod_curvefit(lattice,etot,w,a)



and the finction itself:

;
; the harmonic oscillator function
;
;
;
pro FUNCT,x,a,f,pder


f = a(0) + a(1)*(x-a(2))^2


PDER = FLTARR(N_ELEMENTS(X),3) ;YES, MAKE ARRAY.

PDER(*,0) = 1.0 ;COMPUTE PARTIALS
PDER(*,1) = (x-a(2))^2
PDER(*,2) = 2*a(1)*(x-a(2))
end

RETURN

end


Simple isn't it.

I never get a decent fit!!!!

HELP HELP


Hans
--
Dr.H.Feil
Philips Research Laboratories, WB-121 | phone : +31-40-742701
Prof. Holstlaan 4 | fax : +31-40-743365
5656 AA Eindhoven, The Netherlands | email : feil@prl.philips.nl
Re: curve fitting: works badly? [message #3676 is a reply to message #3672] Mon, 06 March 1995 15:49 Go to previous messageGo to next message
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
feil@prl.philips.nl (Hans Feil) writes:


> I try to use CURVEFIT to get some simple data fitted to an harmonic
> oscillator.

> Somehow things don't work very good.

(stuff deleted)

> pro FUNCT,x,a,f,pder


> f = a(0) + a(1)*(x-a(2))^2


> PDER = FLTARR(N_ELEMENTS(X),3) ;YES, MAKE ARRAY.
>
> PDER(*,0) = 1.0 ;COMPUTE PARTIALS
> PDER(*,1) = (x-a(2))^2
> PDER(*,2) = 2*a(1)*(x-a(2))
^^^^^^^^^^^^^^^
> end

> RETURN

> end

I think that your problem is here. I believe that the sign of this partial
derivative should be negative.

I've often had this problem with this technique. If the partial derivatives
are calculated wrong, you can compute till doomsday and it'll never converge.
I often just don't bother to try to figure it out anymore, and just do the
derivatives numerically.

Bill Thompson
Re: curve fitting: works badly? [message #3755 is a reply to message #3672] Tue, 14 March 1995 11:16 Go to previous message
swalton is currently offline  swalton
Messages: 2
Registered: September 1994
Junior Member
I just peeked in here and saw a discussion of one of my recent
favorite topics, nonlinear least squares. (We have IDL, but
I haven't learned it yet; my brain is full :-) ).

I've been using the routine variously known as NL2SOL or N2G. It is
described in ACM Trans. Math. Software, Vol. 9, PP. 369-383 (An
Adaptive Nonlinear Least-Squares Algorithm, By J.E. Dennis, D.M. Gay,
and R.E. Welsch). They are available by anonymous FTP from
netlib.att.com in the freely distributable subset of the AT&T PORT
library. It comes in several versions, including one which can bound
the fit parameters and versions which calculate the derivatives
numerically. The precise details of the algorithm escape me at the
moment, but I'm using it to fit an 11-parameter (!) model to some
solar data. Highly recommended.

As to errors: a recent article in Computers in Physics compared a
couple of different techniques for estimating the errors in a fit, and
concluded that Monte Carlo techniques give the best estimate.
--
Stephen Walton, California State University, Northridge
"Be careful what you wish for; you might get it." swalton@csun.edu
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: New User seeks book
Next Topic: widget_button

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

Current Time: Wed Oct 08 15:54:27 PDT 2025

Total time taken to generate the page: 0.31041 seconds