Re: mpfit: multivariate fit [message #53956 is a reply to message #53918] |
Fri, 11 May 2007 01:05  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
Dave <Confused.Scientist@gmail.com> writes:
> Thanks hradilv, that does help. I also found that I could get it to
> work if I expand the dimensions and make everything a vector prior to
> fitting. I'd be interested in knowing from Craig if your fix is ok as
> I greatly prefer it to the fiddling below.
>
> function trans, K, X=x, Y=y, err=err, forward=fw
>
> kk = reform(K, 3, n_elements(k)/3)
> xx = reform(x, 3, n_elements(x)/3)
>
> model = KK # xx
>
> model = reform(model, n_elements(model))
>
> if keyword_set(fw) then return, model else return, (y-model)/err
> end
David Fanning is right. You can't simply recode the function like you
did. According to the documentation:
; In general there are no restrictions on the number of dimensions in
; X, Y or ERR. However the deviates *must* be returned in a
; one-dimensional array, and must have the same type (float or
; double) as the input arrays.
The output of your function *must* be one dimensional :-)
Just reform() it before you return it.
By the way, I would say that fitting all 9 matrix components is a sure
path to problems. At the very least, you should enforce the
constraint that the matrix must be symmetric. If there is a simple
rotation (no scale or skew factors), then I would suggest using Euler
angles, or even better, use quaternions and fit the quaternion
components. You can use QTVROT in my library to apply a quaternion
rotation to a 3-vector.
Good luck!
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|