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

Home » Public Forums » archive » Re: help with mathematics
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: help with mathematics [message #80318 is a reply to message #80313] Mon, 28 May 2012 21:02 Go to previous messageGo to previous message
Russell Ryan is currently offline  Russell Ryan
Messages: 122
Registered: May 2012
Senior Member
On May 28, 10:46 am, nata <bernat.puigdomen...@gmail.com> wrote:
> Hi All,
>
> I have a set of measurements, X and Y, and I need to fit a polynomial function with the following "constraints":
>
> Y = a + bX + CX^2 + ((1-b-4C)/12)X^3
>
> I tried to do this with the AMOEBA function but the result is not consistent at all. You can see my code below...
>
> I need some help with this problem. Could anyone help me with this problem ?
> Thank you in advance
>
> nata
>
> ; First define the function FUNC:
> FUNCTION FUNC P
>   COMMON FUNC_XY, X, Y
>   RETURN, MAX(ABS(Y - (P[0] + P[1]*X + P[2]*X^2 + ((1-P[1]-4*P[2]) / 12)*X^3)))
> END
>
> PRO PROGRAM
>
> COMMON FUNC_XY, X, Y
> X=[11.0,13.0,14.5,15.5,16.5,17.5,18.5,19.5,20.5,21.5,22.5,23 .5,24.5,25.5, $
> 26.5,27.5,28.5,29.5,30.5,31.5,32.5,33.5,34.5,35.5,37.0,39.0, 41.5,44.5,48.0]
>
> Y=[-0.921,-0.735,-0.627,-0.554,-0.439,-0.379,-0.313,-0.247,- 0.186,-0.126, $
> -0.092,-0.018,0.052,0.108,0.185,0.255,0.308,0.375,0.443,0.52 5,0.597,0.656, $
> 0.733,0.816,0.950,1.109,1.269,1.562,2.044]
>
> R = AMOEBA(1.0e-25, SCALE=[1e2,1e2,1e2], P0=[0,0,0], FUNCTION_VALUE=fval, FUNCTION_NAME='FUNC')
>
>  PLOT, X, Y
> OPLOT, X, (R[0] + R[1]*X + R[2]*X^2. + ((1-R[1]-4*R[2])/12)*X^3.), COLOR=222
>
> END

Wait, you're not making any sense. Are you saying that you have two
vectors (x and y) to which you want to fit a function of the form:

ymodel = a + bX + CX^2 + ((1-b-4C)/12)X^3

and determine the coefficients a, b, c? If so, then there are a
dozen ways to do this and amoeba is among the worst. Not to mention,
your definition of the minimization function (while what IDL suggests)
is not very good, because it's not differentiable. Always minimize a
distance metric of the form

X^2 = sum_i (y_i - ymodel(x_i))^2

where i runs over points --- unless you have a very good reason *NOT*
to do this.. This way, you can take the derivative of X^2 w.r.t. each
parameter, set them to zero, and solve the resulting set of
equations. If the problem is linear (and this one is), then you can
solve the problem exactly by inverting a simple matrix.

Please look into curvefit.pro (comes with IDL) or mpfit.pro (built and
maintained by C. Markwardt).

Russell
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: help with sorting vector elements in to subarrays
Next Topic: help with sorting vector elements in to subarrays

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

Current Time: Sat Oct 11 04:53:48 PDT 2025

Total time taken to generate the page: 0.16237 seconds