Re: 3D Curve Fitting [message #62729] |
Thu, 02 October 2008 09:05 |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
Wox <nomail@hotmail.com> writes:
> On 01 Oct 2008 13:07:37 -0400, Craig Markwardt
> <craigmnet@REMOVEcow.physics.wisc.edu> wrote:
>
>> Wox <nomail@hotmail.com> writes:
>>>
>>> Sorry for the confusing, it must be: "If you have 3 DEPENDENT
>>> variables, you can't use mpfit or curvefit or whatever"
>>
>> I don't think your claim is correct. If you have the independent
>> variable, X, and *two* measurements per X point, (say Y and Z) then it
>> is straightforward to fit both of those points simultaneously. That
>> is effectively fitting a 2D function. The method is the same,
>> MPFITFUN('MYFUNCT', X, [Y, Z], [ERR_Y, ERR_Z], ...)
>> and your function is responsible for computing both functions
>> separately and then stacking them together.
>
> Yes, you're right, but what if X would be measured too?
Well as I said, you need to define your problem first. MPFIT solves
the chi-square problem, so if you can rigorously define how the
chi-square value is calculated for your case, then MPFIT will solve
for the best parameters.
If all "X" "Y" and "Z" are measured values, then you no longer have a
simple chi-square problem. The closest technique to solve this kind
of problem is orthogonal distance regression (ODRPACK, in FORTRAN).
But even with ODR you need to be able to define in a formal way how
the function and chi-square are calculated.
Happy fitting,
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: cbmarkwardt+usenet@gmail.com
------------------------------------------------------------ --------------
|
|
|
Re: 3D Curve Fitting [message #62730 is a reply to message #62729] |
Thu, 02 October 2008 09:01  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
Wox <nomail@hotmail.com> writes:
> On 01 Oct 2008 13:07:37 -0400, Craig Markwardt
> <craigmnet@REMOVEcow.physics.wisc.edu> wrote:
>
>> Wox <nomail@hotmail.com> writes:
>
>>> The point is, mpfit (and all curvefitting routines) can handle only 1
>>> dependent variable and any number if independent variables.
>>
>> Again, not true, see above.
>
> I know one can concatenate several independent variables, but I didn't
> know you could do the same with dependent variables. So if the
> dependent variables have a different error-model, you can just supply
> the appropriate weights and that's it? Good to know, I stand
> corrected.
Right!
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: cbmarkwardt+usenet@gmail.com
------------------------------------------------------------ --------------
|
|
|
Re: 3D Curve Fitting [message #62737 is a reply to message #62730] |
Thu, 02 October 2008 04:50  |
Wox
Messages: 184 Registered: August 2006
|
Senior Member |
|
|
On 01 Oct 2008 13:07:37 -0400, Craig Markwardt
<craigmnet@REMOVEcow.physics.wisc.edu> wrote:
> Wox <nomail@hotmail.com> writes:
>> The point is, mpfit (and all curvefitting routines) can handle only 1
>> dependent variable and any number if independent variables.
>
> Again, not true, see above.
I know one can concatenate several independent variables, but I didn't
know you could do the same with dependent variables. So if the
dependent variables have a different error-model, you can just supply
the appropriate weights and that's it? Good to know, I stand
corrected.
|
|
|
Re: 3D Curve Fitting [message #62739 is a reply to message #62737] |
Thu, 02 October 2008 04:13  |
Wox
Messages: 184 Registered: August 2006
|
Senior Member |
|
|
On 01 Oct 2008 13:07:37 -0400, Craig Markwardt
<craigmnet@REMOVEcow.physics.wisc.edu> wrote:
> Wox <nomail@hotmail.com> writes:
>>
>> Sorry for the confusing, it must be: "If you have 3 DEPENDENT
>> variables, you can't use mpfit or curvefit or whatever"
>
> I don't think your claim is correct. If you have the independent
> variable, X, and *two* measurements per X point, (say Y and Z) then it
> is straightforward to fit both of those points simultaneously. That
> is effectively fitting a 2D function. The method is the same,
> MPFITFUN('MYFUNCT', X, [Y, Z], [ERR_Y, ERR_Z], ...)
> and your function is responsible for computing both functions
> separately and then stacking them together.
Yes, you're right, but what if X would be measured too?
|
|
|
Re: 3D Curve Fitting [message #62740 is a reply to message #62739] |
Thu, 02 October 2008 02:59  |
jaz
Messages: 6 Registered: October 2008
|
Junior Member |
|
|
Hi - thanks for all your replies.
What i've ended up doing, is using the curve fitting program in iplot,
to fit a polynomial (quintic) to my points in the x and y plane, and
then in the new x and z plane. This seems to have the desired effect.
Thanks
|
|
|
Re: 3D Curve Fitting [message #62744 is a reply to message #62740] |
Wed, 01 October 2008 11:04  |
R.G. Stockwell
Messages: 363 Registered: July 1999
|
Senior Member |
|
|
"jaz" <jazpearson@gmail.com> wrote in message
news:126f7c59-020d-43f3-823c-777bb5cbc011@y71g2000hsa.google groups.com...
> I'm trying to fit a curve to some points in 3D space (using a
> polynomial such as a quartic to fit), and was wondering if there was
> any IDL procedure or function that allowed you to do this easily?
You can fit a function like 1 + x + y + z +xy + xz + yz + x^2 + y^2 + z^2
with the svd functions, or the cholesky ( a bit faster). Those termes
lead to the columns of your "A" matrix - there is nothing special about 3D.
Cheers,
bob
|
|
|
Re: 3D Curve Fitting [message #62747 is a reply to message #62744] |
Wed, 01 October 2008 10:07  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
Wox <nomail@hotmail.com> writes:
>
> Sorry for the confusing, it must be: "If you have 3 DEPENDENT
> variables, you can't use mpfit or curvefit or whatever"
I don't think your claim is correct. If you have the independent
variable, X, and *two* measurements per X point, (say Y and Z) then it
is straightforward to fit both of those points simultaneously. That
is effectively fitting a 2D function. The method is the same,
MPFITFUN('MYFUNCT', X, [Y, Z], [ERR_Y, ERR_Z], ...)
and your function is responsible for computing both functions
separately and then stacking them together.
> The point is, mpfit (and all curvefitting routines) can handle only 1
> dependent variable and any number if independent variables.
Again, not true, see above.
However, your original request was entirely different. You wanted to
fit a "quartic" curve through some "points in 3D space." Again, a
quartic function of what? Define your problem first, please.
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: cbmarkwardt+usenet@gmail.com
------------------------------------------------------------ --------------
|
|
|
Re: 3D Curve Fitting [message #62748 is a reply to message #62747] |
Wed, 01 October 2008 09:53  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
jaz <jazpearson@gmail.com> writes:
> Yeah i've seen this, but it only seems to do up to 2D. Or am i missing
> a trick here?
MPFIT doesn't really care about the dimensionality of your data. All
it really needs is a function which returns a set of residuals. For
example, if you have a set of measured *heights* above the XY plane,
and want to fit to the surface function Z(X,Y), then, you can easily
do something like,
MPFITFUN('MYFUNC', [X,Y], Z, ...)
As long as your MYFUNC handles several stacked input variables, it
should easily be able to return the model Z heights.
More information,
http://cow.physics.wisc.edu/~craigm/idl/fitqa.html#multivar
But your original question said you wanted to "fit a curve to some
points in 3D space ... such as a quartic..." That's a little too
generic. A quartic function of *what*?
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: cbmarkwardt+usenet@gmail.com
------------------------------------------------------------ --------------
|
|
|
Re: 3D Curve Fitting [message #62752 is a reply to message #62748] |
Wed, 01 October 2008 06:07  |
jameskuyper
Messages: 79 Registered: October 2007
|
Member |
|
|
Wox wrote:
> Pfff, nice collection of typo's. It seems this group doesn't allow
> cancelling messages?
It's not determined by the group, it's determined by the news servers.
Since there are many different news servers, each with their own
cancellation policy, for practical purposes it's impossible to cancel a
message once it's been posted.
|
|
|
Re: 3D Curve Fitting [message #62753 is a reply to message #62752] |
Wed, 01 October 2008 05:19  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Wox writes:
> Pfff, nice collection of typo's. It seems this group doesn't allow
> cancelling messages?
This is done deliberately in an effort to foster humility. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
|
Re: 3D Curve Fitting [message #62755 is a reply to message #62754] |
Wed, 01 October 2008 04:50  |
Wox
Messages: 184 Registered: August 2006
|
Senior Member |
|
|
On Wed, 1 Oct 2008 04:08:29 -0700 (PDT), Rob.Dimeo@gmail.com wrote:
> On Oct 1, 4:55�am, Wox <nom...@hotmail.com> wrote:
>> On Wed, 1 Oct 2008 00:35:08 -0700 (PDT), jaz <jazpear...@gmail.com>
>> wrote:
>>
>> If you have 3 independent variables, you can't use mpfit or curvefit
>> or whatever. There was a recent thread about fitting a plane through
>> 3D points:http://groups.google.com/group/comp.lang.idl-pvwave/b rowse_thread/thr...
>
> Using either MPFIT or MPCURVEFIT, I am not aware of any such
> limitation on the number of independent variables with which one can
> fit a user-supplied model to data (other than computational
> resources).
Sorry for the confusing, it must be: "If you have 3 DEPENDENT
variables, you can't use mpfit or curvefit or whatever"
The point is, mpfit (and all curvefitting routines) can handle only 1
dependent variable and any number if independent variables.
The example I was referring to was fitting a plane ax+by+cz+d=0
through measured points in 3D.
|
|
|
Re: 3D Curve Fitting [message #62757 is a reply to message #62755] |
Wed, 01 October 2008 04:08  |
Rob.Dimeo
Messages: 21 Registered: September 2007
|
Junior Member |
|
|
On Oct 1, 4:55 am, Wox <nom...@hotmail.com> wrote:
> On Wed, 1 Oct 2008 00:35:08 -0700 (PDT), jaz <jazpear...@gmail.com>
> wrote:
>
>> Yeah i've seen this, but it only seems to do up to 2D. Or am i missing
>> a trick here?
>
> If you have 2 independent and 1 dependent variable (e.g. z as a
> function of x and y), mpfit can be used. In IDL's CURVEFIT
> terminology, x would be [x,y] and y would be z.
>
> If you have 3 independent variables, you can't use mpfit or curvefit
> or whatever. There was a recent thread about fitting a plane through
> 3D points:http://groups.google.com/group/comp.lang.idl-pvwave/b rowse_thread/thr...
Using either MPFIT or MPCURVEFIT, I am not aware of any such
limitation on the number of independent variables with which one can
fit a user-supplied model to data (other than computational
resources). The concatenation method mentioned above works. Your
model function just needs to know how to disentangle these independent
variables, x1,x2,x3,..., from your X variable.
|
|
|
|
|
|