Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: determining the equation of a 3-D surface
Date: Fri, 21 Nov 2008 20:28:02 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 57
Message-ID: <gg75ki$8fc$1@fred.mathworks.com>
References: <gg6ovh$4db$1@fred.mathworks.com> <gg730g$ofn$1@fred.mathworks.com> <gg74d6$hqs$1@fred.mathworks.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1227299282 8684 172.30.248.37 (21 Nov 2008 20:28:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 21 Nov 2008 20:28:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:502405


"loic paccard" <loic.paccard@ecam.fr> wrote in message <gg74d6$hqs$1@fred.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in message <gg730g$ofn$1@fred.mathworks.com>...
> > There is no magic solution that will give you an equation
> > from data points. Not fmincon, not griddata, nor my own
> > gridfit.
> > 
> > The fact is, there are an infinite (I won't hazard a guess at
> > the order of the infinity) number of ways to model any set
> > of points. The splines produced by some tools (griddata
> > is one version of what might call a low order spline) will
> > give you an interpolant, but they do not give you a function
> > in any usable form that you can write down easily.
> > 
> > In order to realize a usable model, you need to invest some
> > time and effort of your own. (As with almost anything, you
> > get what you pay for.) You need to postulate a viable model
> > for the process, then you can try to estimate the parameters
> > of that model from the data. Without that model, you are
> > left with little more than something simple, like a polynomial
> > model. My polyfitn can build such a model, but even there
> > you must tell it the order of the model or the specific terms
> > to be used.
> > 
> > http://www.mathworks.com/matlabcentral/fileexchange/10065
> > 
> > HTH,
> > John
> 
> 
> Thank you John for your realistic message.
> To be honest I was expecting that I was actually impossible to get a 3-D analytical expression from data without knowing some hypothesis about this hypothetic equation.
> And that is my case, I have no model of this curve, I am just trying to minimize (by fmincon) the z value of it in order to get the x and y positions.
>

fmincon will not help you here without a model of
some form.

> 
> But assuming that my function could be approximate by a polynomial analytical expression...
> 
> We both know that we can use polyfit for a row or column vector.
> Is there a function in matlab able to do it for a matrix?
> is your polyfit function able to give me an approximated analytical expression if I can guess the polynom order that I need to use??
> 

polyfitn does it for the n-d case, but you do need to
choose the order of your model. And beware fitting
very high order models, just to get an accurate fit.

Use meshgrid to generate x and y. For example,

[x,y] = meshgrid(-36:6:36);
xy = [x(:),y(:)];
model = polyfitn(xy,z,3);

HTH,
John