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

Home » Public Forums » archive » Re: IDL fitting of piecewise continuous function
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
Re: IDL fitting of piecewise continuous function [message #76112] Tue, 17 May 2011 19:35
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On May 17, 3:53 pm, Jeremy Bailin <astroco...@gmail.com> wrote:
> If you define your function analogously to the example in the MPFIT code, it might look like:
>
> FUNCTION MYFUNCT, p, X=x, Y=y, ERR=err
>   ; p[0] is A
>   x_m = SOME_CONSTANT_VALUE
>
>   ; x lt x_m is 1 if x<x_m and 0 otherwise
>   ; x ge x_m is 1 if x >= x_m and 0 otherwise
>   model = (x lt x_m) * p[0] * x^(0.5)  +  (x ge x_m) * p[0] * x_m^(1.5) / x
>
>   return, (y-model)/err
> END
>
> Of course, that assumes that x_m is a constant, not a parameter - but if it's a parameter, you would just use p[1] instead of a constant value, for example.

Yep, what he said.
Craig
Re: IDL fitting of piecewise continuous function [message #76114 is a reply to message #76112] Tue, 17 May 2011 12:53 Go to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
If you define your function analogously to the example in the MPFIT code, it might look like:

FUNCTION MYFUNCT, p, X=x, Y=y, ERR=err
; p[0] is A
x_m = SOME_CONSTANT_VALUE

; x lt x_m is 1 if x<x_m and 0 otherwise
; x ge x_m is 1 if x >= x_m and 0 otherwise
model = (x lt x_m) * p[0] * x^(0.5) + (x ge x_m) * p[0] * x_m^(1.5) / x

return, (y-model)/err
END


Of course, that assumes that x_m is a constant, not a parameter - but if it's a parameter, you would just use p[1] instead of a constant value, for example.

-Jeremy.
Re: IDL fitting of piecewise continuous function [message #76115 is a reply to message #76114] Tue, 17 May 2011 12:26 Go to previous message
Sasha Singh is currently offline  Sasha Singh
Messages: 13
Registered: November 2010
Junior Member
Thanks Jeremy,

I did look look at MPFIT. I am confused as to how do I define the
constraints x<x_m and x > x_m in the function. Sorry I am quite new to
IDL.

Sasha

On May 17, 3:21 pm, Jeremy Bailin <astroco...@gmail.com> wrote:
> Craigh Markwardt's MPFIT (and its varients) is most people's preferred fitting routine:
>
> http://www.physics.wisc.edu/~craigm/idl/fitting.html
>
> You define your own function to feed in, so it can have whatever behaviour you want. To ensure continuity, I would recommend re-parametrizing the functional form so that it is continuous by definition. In this, case, A and B aren't actually independent, so calculate B in terms of A by setting them equal at x=x_m, which gives
> B = A x_m^(3/2)
>
> So you're actually fitting:
>
> f(x) = A x_m^(1/2) x^(1/2)   x < x_m
>   A x_m^(3/2) x^(-1)   x > x_m
>
> -Jeremy.
Re: IDL fitting of piecewise continuous function [message #76116 is a reply to message #76115] Tue, 17 May 2011 12:24 Go to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
sorry, that should be:

f(x) = A x^(1/2) x < x_m
A x_m^(3/2) x^(-1) x > x_m

-Jeremy.
Re: IDL fitting of piecewise continuous function [message #76117 is a reply to message #76116] Tue, 17 May 2011 12:21 Go to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
Craigh Markwardt's MPFIT (and its varients) is most people's preferred fitting routine:

http://www.physics.wisc.edu/~craigm/idl/fitting.html

You define your own function to feed in, so it can have whatever behaviour you want. To ensure continuity, I would recommend re-parametrizing the functional form so that it is continuous by definition. In this, case, A and B aren't actually independent, so calculate B in terms of A by setting them equal at x=x_m, which gives
B = A x_m^(3/2)

So you're actually fitting:

f(x) = A x_m^(1/2) x^(1/2) x < x_m
A x_m^(3/2) x^(-1) x > x_m



-Jeremy.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL fitting of piecewise continuous function
Next Topic: HISTOGRAM, binsize, and max

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

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

Total time taken to generate the page: 0.00468 seconds