<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692</link>
    <title>MATLAB Central Newsreader - determining the equation of a 3-D surface</title>
    <description>Feed for thread: determining the equation of a 3-D surface</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 21 Nov 2008 16:52:01 -0500</pubDate>
      <title>determining the equation of a 3-D surface</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692#612416</link>
      <author>loic paccard</author>
      <description>Hi everybody,&lt;br&gt;
&lt;br&gt;
I collect some data in this way:&lt;br&gt;
13 positions x (discrete points: values from -36 to 36 by a 6 step)&lt;br&gt;
13 positions y (discrete points: values from -36 to 36 by a 6 step)&lt;br&gt;
basically it is a grid of 169 points&lt;br&gt;
And each point has a z-value that I am trying to minimize.&lt;br&gt;
&lt;br&gt;
I can plot a surface z=f(x,y) but I need to minimize it for several samples.&lt;br&gt;
So the best minimizer would be fmincon in my case but how I can get an equation z=f(x,y) from 169 discrete points??&lt;br&gt;
&lt;br&gt;
I want to say that using griddata is helpless in my case, I do not need to interpolate but to be able to use fmincon for my discrete values.&lt;br&gt;
&lt;br&gt;
I have looked for hours and it does not seem like fmincon can use directly elements values in matrix referenced by row and column as a function AND there is no function able to get a 3-D equation in my case.&lt;br&gt;
&lt;br&gt;
I will be glad to receive some help,&lt;br&gt;
loic.</description>
    </item>
    <item>
      <pubDate>Fri, 21 Nov 2008 17:48:02 -0500</pubDate>
      <title>Re: determining the equation of a 3-D surface</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692#612429</link>
      <author>loic paccard</author>
      <description>&quot;loic paccard&quot; &amp;lt;loic.paccard@ecam.fr&amp;gt; wrote in message &amp;lt;gg6ovh$4db$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi everybody,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I collect some data in this way:&lt;br&gt;
&amp;gt; 13 positions x (discrete points: values from -36 to 36 by a 6 step)&lt;br&gt;
&amp;gt; 13 positions y (discrete points: values from -36 to 36 by a 6 step)&lt;br&gt;
&amp;gt; basically it is a grid of 169 points&lt;br&gt;
&amp;gt; And each point has a z-value that I am trying to minimize.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I can plot a surface z=f(x,y) but I need to minimize it for several samples.&lt;br&gt;
&amp;gt; So the best minimizer would be fmincon in my case but how I can get an equation z=f(x,y) from 169 discrete points??&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I want to say that using griddata is helpless in my case, I do not need to interpolate but to be able to use fmincon for my discrete values.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have looked for hours and it does not seem like fmincon can use directly elements values in matrix referenced by row and column as a function AND there is no function able to get a 3-D equation in my case.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I will be glad to receive some help,&lt;br&gt;
&amp;gt; loic.&lt;br&gt;
&lt;br&gt;
I have tried to use spline functions but it only can work with a row x  or a column y of my matrix for the values of elements and I need a global equation for a fmincon minimization.</description>
    </item>
    <item>
      <pubDate>Fri, 21 Nov 2008 19:22:02 -0500</pubDate>
      <title>Re: determining the equation of a 3-D surface</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692#612463</link>
      <author>Bruno Luong</author>
      <description>&quot;loic paccard&quot; &amp;lt;loic.paccard@ecam.fr&amp;gt; wrote in message &amp;lt;gg6s8i$4mr$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have tried to use spline functions but it only can work with a row x  or a column y of my matrix for the values of elements and I need a global equation for a fmincon minimization.&lt;br&gt;
&lt;br&gt;
You might try to use interp2 with 'spline' method.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Fri, 21 Nov 2008 19:43:12 -0500</pubDate>
      <title>Re: determining the equation of a 3-D surface</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692#612468</link>
      <author>John D'Errico</author>
      <description>&quot;loic paccard&quot; &amp;lt;loic.paccard@ecam.fr&amp;gt; wrote in message &amp;lt;gg6ovh$4db$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi everybody,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I collect some data in this way:&lt;br&gt;
&amp;gt; 13 positions x (discrete points: values from -36 to 36 by a 6 step)&lt;br&gt;
&amp;gt; 13 positions y (discrete points: values from -36 to 36 by a 6 step)&lt;br&gt;
&amp;gt; basically it is a grid of 169 points&lt;br&gt;
&amp;gt; And each point has a z-value that I am trying to minimize.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I can plot a surface z=f(x,y) but I need to minimize it for several samples.&lt;br&gt;
&amp;gt; So the best minimizer would be fmincon in my case but how I can get an equation z=f(x,y) from 169 discrete points??&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I want to say that using griddata is helpless in my case, I do not need to interpolate but to be able to use fmincon for my discrete values.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have looked for hours and it does not seem like fmincon can use directly elements values in matrix referenced by row and column as a function AND there is no function able to get a 3-D equation in my case.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I will be glad to receive some help,&lt;br&gt;
&amp;gt; loic.&lt;br&gt;
&lt;br&gt;
There is no magic solution that will give you an equation&lt;br&gt;
from data points. Not fmincon, not griddata, nor my own&lt;br&gt;
gridfit.&lt;br&gt;
&lt;br&gt;
The fact is, there are an infinite (I won't hazard a guess at&lt;br&gt;
the order of the infinity) number of ways to model any set&lt;br&gt;
of points. The splines produced by some tools (griddata&lt;br&gt;
is one version of what might call a low order spline) will&lt;br&gt;
give you an interpolant, but they do not give you a function&lt;br&gt;
in any usable form that you can write down easily.&lt;br&gt;
&lt;br&gt;
In order to realize a usable model, you need to invest some&lt;br&gt;
time and effort of your own. (As with almost anything, you&lt;br&gt;
get what you pay for.) You need to postulate a viable model&lt;br&gt;
for the process, then you can try to estimate the parameters&lt;br&gt;
of that model from the data. Without that model, you are&lt;br&gt;
left with little more than something simple, like a polynomial&lt;br&gt;
model. My polyfitn can build such a model, but even there&lt;br&gt;
you must tell it the order of the model or the specific terms&lt;br&gt;
to be used.&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/10065&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/10065&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
HTH,&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Fri, 21 Nov 2008 19:44:02 -0500</pubDate>
      <title>Re: determining the equation of a 3-D surface</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692#612469</link>
      <author>loic paccard</author>
      <description>&quot;Bruno Luong&quot; &amp;lt;b.luong@fogale.findmycountry&amp;gt; wrote in message &amp;lt;gg71op$4c1$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;loic paccard&quot; &amp;lt;loic.paccard@ecam.fr&amp;gt; wrote in message &amp;lt;gg6s8i$4mr$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I have tried to use spline functions but it only can work with a row x  or a column y of my matrix for the values of elements and I need a global equation for a fmincon minimization.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You might try to use interp2 with 'spline' method.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Bruno&lt;br&gt;
&lt;br&gt;
Thanks for your help Bruno.&lt;br&gt;
&lt;br&gt;
I don't really think that interp2 is useful in my case.&lt;br&gt;
interp2 can provide efficiently discrete values in different x and y positions than where my data has been taken.&lt;br&gt;
This is helpful for getting discrete values but it can not give the analytical equation of my surface.&lt;br&gt;
Maybe I am wrong, in this case tell me how to use interp2 in order to get this analytical equation z= f(x,y).</description>
    </item>
    <item>
      <pubDate>Fri, 21 Nov 2008 19:53:02 -0500</pubDate>
      <title>Re: determining the equation of a 3-D surface</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692#612470</link>
      <author>Bruno Luong</author>
      <description>&quot;loic paccard&quot; &amp;lt;loic.paccard@ecam.fr&amp;gt; wrote in message &amp;lt;gg7322$p7o$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; Maybe I am wrong, in this case tell me how to use interp2 in order to get this analytical equation z= f(x,y).&lt;br&gt;
&lt;br&gt;
I don't think minimizer require an analytic expression. All it needs is you will be able to evaluate a function - preferable continuously derivable - at any point.&lt;br&gt;
&lt;br&gt;
And that is exactly interp2 with spline function can give you.&lt;br&gt;
&lt;br&gt;
Otherwise you have to give up the fact that the model (could be an analytic expression) interpolate the data, but only *approximate* your data. In this case you might call a fitting with multi-variate polynomial, or spline functions.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Fri, 21 Nov 2008 19:54:02 -0500</pubDate>
      <title>Re: determining the equation of a 3-D surface</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692#612471</link>
      <author>Johan Carlson</author>
      <description>&quot;loic paccard&quot; &amp;lt;loic.paccard@ecam.fr&amp;gt; wrote in message &amp;lt;gg7322$p7o$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Bruno Luong&quot; &amp;lt;b.luong@fogale.findmycountry&amp;gt; wrote in message &amp;lt;gg71op$4c1$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &quot;loic paccard&quot; &amp;lt;loic.paccard@ecam.fr&amp;gt; wrote in message &amp;lt;gg6s8i$4mr$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; I have tried to use spline functions but it only can work with a row x  or a column y of my matrix for the values of elements and I need a global equation for a fmincon minimization.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; You might try to use interp2 with 'spline' method.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Bruno&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks for your help Bruno.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I don't really think that interp2 is useful in my case.&lt;br&gt;
&amp;gt; interp2 can provide efficiently discrete values in different x and y positions than where my data has been taken.&lt;br&gt;
&amp;gt; This is helpful for getting discrete values but it can not give the analytical equation of my surface.&lt;br&gt;
&amp;gt; Maybe I am wrong, in this case tell me how to use interp2 in order to get this analytical equation z= f(x,y).&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
I agree with John D'Errico. From what you describe it seems like you'd like to find a function that minimizes the total sum of squared distances to your measured data (or minimizes some other norm). In general such a function does not exist.&lt;br&gt;
&lt;br&gt;
However, if you have a polynomial model in x and y, for example a second order surface with linear-, cross- and quadratic terms, you could fit this function using a simple least-squares approach. Below is an example. It should run if you just copy and paste... Good luck&lt;br&gt;
/JC&lt;br&gt;
&lt;br&gt;
% First, simulate some data... with random noise on it.&lt;br&gt;
[X1,X2] = meshgrid(-1:.2:1, -1:.2:1);&lt;br&gt;
a = [1 .5 -.5 .25 1.2 -1.3];&lt;br&gt;
Y = a(1) + a(2)*X1 + a(3)*X2 + a(4)*X1.*X2 + a(5)*X1.^2 + a(6)*X2.^2;&lt;br&gt;
Y = Y + 0.1*randn(size(Y));   % Add some noise&lt;br&gt;
&lt;br&gt;
% Then, generate a grid for your &quot;estimated surface&quot;&lt;br&gt;
[XX1,XX2] = meshgrid(-1:.1:1, -1:.1:1);&lt;br&gt;
X = [ones(prod(size(X1)),1), X1(:) X2(:), ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;X1(:).*X2(:), X1(:).^2, X2(:).^2];&lt;br&gt;
&lt;br&gt;
% Do the least-squares magic&lt;br&gt;
a_hat = inv(X'*X)*X'*Y(:);&lt;br&gt;
Y_hat = a_hat(1) + a_hat(2)*X1 + a_hat(3)*X2 + a_hat(4)*X1.*X2 ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+ a_hat(5)*X1.^2 + a_hat(6)*X2.^2;&lt;br&gt;
&lt;br&gt;
% Plot the result&lt;br&gt;
plot3(X1,X2,Y,'black+','linewidth',2);&lt;br&gt;
hold on;&lt;br&gt;
mesh(X1,X2,Y_hat); colormap(gray(1));&lt;br&gt;
hold off;&lt;br&gt;
grid on;&lt;br&gt;
xlabel('x_1'); ylabel('x_2'); zlabel('y');</description>
    </item>
    <item>
      <pubDate>Fri, 21 Nov 2008 20:07:02 -0500</pubDate>
      <title>Re: determining the equation of a 3-D surface</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692#612474</link>
      <author>loic paccard</author>
      <description>&quot;John D'Errico&quot; &amp;lt;woodchips@rochester.rr.com&amp;gt; wrote in message &amp;lt;gg730g$ofn$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; There is no magic solution that will give you an equation&lt;br&gt;
&amp;gt; from data points. Not fmincon, not griddata, nor my own&lt;br&gt;
&amp;gt; gridfit.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The fact is, there are an infinite (I won't hazard a guess at&lt;br&gt;
&amp;gt; the order of the infinity) number of ways to model any set&lt;br&gt;
&amp;gt; of points. The splines produced by some tools (griddata&lt;br&gt;
&amp;gt; is one version of what might call a low order spline) will&lt;br&gt;
&amp;gt; give you an interpolant, but they do not give you a function&lt;br&gt;
&amp;gt; in any usable form that you can write down easily.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; In order to realize a usable model, you need to invest some&lt;br&gt;
&amp;gt; time and effort of your own. (As with almost anything, you&lt;br&gt;
&amp;gt; get what you pay for.) You need to postulate a viable model&lt;br&gt;
&amp;gt; for the process, then you can try to estimate the parameters&lt;br&gt;
&amp;gt; of that model from the data. Without that model, you are&lt;br&gt;
&amp;gt; left with little more than something simple, like a polynomial&lt;br&gt;
&amp;gt; model. My polyfitn can build such a model, but even there&lt;br&gt;
&amp;gt; you must tell it the order of the model or the specific terms&lt;br&gt;
&amp;gt; to be used.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/10065&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/10065&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; HTH,&lt;br&gt;
&amp;gt; John&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Thank you John for your realistic message.&lt;br&gt;
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.&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
But assuming that my function could be approximate by a polynomial analytical expression...&lt;br&gt;
&lt;br&gt;
We both know that we can use polyfit for a row or column vector.&lt;br&gt;
Is there a function in matlab able to do it for a matrix?&lt;br&gt;
is your polyfit function able to give me an approximated analytical expression if I can guess the polynom order that I need to use??</description>
    </item>
    <item>
      <pubDate>Fri, 21 Nov 2008 20:17:01 -0500</pubDate>
      <title>Re: determining the equation of a 3-D surface</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692#612476</link>
      <author>loic paccard</author>
      <description>&quot;Bruno Luong&quot; &amp;lt;b.luong@fogale.findmycountry&amp;gt; wrote in message &amp;lt;gg73iu$44n$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;loic paccard&quot; &amp;lt;loic.paccard@ecam.fr&amp;gt; wrote in message &amp;lt;gg7322$p7o$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Maybe I am wrong, in this case tell me how to use interp2 in order to get this analytical equation z= f(x,y).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I don't think minimizer require an analytic expression. All it needs is you will be able to evaluate a function - preferable continuously derivable - at any point.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; And that is exactly interp2 with spline function can give you.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Otherwise you have to give up the fact that the model (could be an analytic expression) interpolate the data, but only *approximate* your data. In this case you might call a fitting with multi-variate polynomial, or spline functions.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Bruno&lt;br&gt;
&lt;br&gt;
Bruno,&lt;br&gt;
&lt;br&gt;
What I need is minimizing my z values and the best minimizer would be obviously&lt;br&gt;
fmincon in my case.&lt;br&gt;
I have looked for finding a way to use fmincon without an analytical expression but just function evaluations (by using interp2 I can have much more evaluations of my functions in the grid from my real data).&lt;br&gt;
&lt;br&gt;
But fmincon seems to requires an analytical expression whatever:&lt;br&gt;
&lt;br&gt;
Find minimum of constrained nonlinear multivariable function&lt;br&gt;
Equation&lt;br&gt;
&lt;br&gt;
Finds the minimum of a problem specified by&lt;br&gt;
&lt;br&gt;
x, b, beq, lb, and ub are vectors, A and Aeq are matrices, c(x) and ceq(x) are functions that return vectors, and f(x) is a function that returns a scalar. f(x), c(x), and ceq(x) can be nonlinear functions.</description>
    </item>
    <item>
      <pubDate>Fri, 21 Nov 2008 20:26:02 -0500</pubDate>
      <title>Re: determining the equation of a 3-D surface</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692#612477</link>
      <author>Bruno Luong</author>
      <description>&quot;loic paccard&quot; &amp;lt;loic.paccard@ecam.fr&amp;gt; wrote in message &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; But fmincon seems to requires an analytical expression whatever:&lt;br&gt;
&lt;br&gt;
Not necessary. Here is an example, and it's from John. &lt;a href=&quot;http://www.mathworks.com/matlabcentral/newsreader/view_thread/236835&quot;&gt;http://www.mathworks.com/matlabcentral/newsreader/view_thread/236835&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Fri, 21 Nov 2008 20:28:02 -0500</pubDate>
      <title>Re: determining the equation of a 3-D surface</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692#612480</link>
      <author>John D'Errico</author>
      <description>&quot;loic paccard&quot; &amp;lt;loic.paccard@ecam.fr&amp;gt; wrote in message &amp;lt;gg74d6$hqs$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;John D'Errico&quot; &amp;lt;woodchips@rochester.rr.com&amp;gt; wrote in message &amp;lt;gg730g$ofn$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; There is no magic solution that will give you an equation&lt;br&gt;
&amp;gt; &amp;gt; from data points. Not fmincon, not griddata, nor my own&lt;br&gt;
&amp;gt; &amp;gt; gridfit.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; The fact is, there are an infinite (I won't hazard a guess at&lt;br&gt;
&amp;gt; &amp;gt; the order of the infinity) number of ways to model any set&lt;br&gt;
&amp;gt; &amp;gt; of points. The splines produced by some tools (griddata&lt;br&gt;
&amp;gt; &amp;gt; is one version of what might call a low order spline) will&lt;br&gt;
&amp;gt; &amp;gt; give you an interpolant, but they do not give you a function&lt;br&gt;
&amp;gt; &amp;gt; in any usable form that you can write down easily.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; In order to realize a usable model, you need to invest some&lt;br&gt;
&amp;gt; &amp;gt; time and effort of your own. (As with almost anything, you&lt;br&gt;
&amp;gt; &amp;gt; get what you pay for.) You need to postulate a viable model&lt;br&gt;
&amp;gt; &amp;gt; for the process, then you can try to estimate the parameters&lt;br&gt;
&amp;gt; &amp;gt; of that model from the data. Without that model, you are&lt;br&gt;
&amp;gt; &amp;gt; left with little more than something simple, like a polynomial&lt;br&gt;
&amp;gt; &amp;gt; model. My polyfitn can build such a model, but even there&lt;br&gt;
&amp;gt; &amp;gt; you must tell it the order of the model or the specific terms&lt;br&gt;
&amp;gt; &amp;gt; to be used.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/10065&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/10065&lt;/a&gt;&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; HTH,&lt;br&gt;
&amp;gt; &amp;gt; John&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thank you John for your realistic message.&lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt;&lt;br&gt;
&lt;br&gt;
fmincon will not help you here without a model of&lt;br&gt;
some form.&lt;br&gt;
&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; But assuming that my function could be approximate by a polynomial analytical expression...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; We both know that we can use polyfit for a row or column vector.&lt;br&gt;
&amp;gt; Is there a function in matlab able to do it for a matrix?&lt;br&gt;
&amp;gt; is your polyfit function able to give me an approximated analytical expression if I can guess the polynom order that I need to use??&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
polyfitn does it for the n-d case, but you do need to&lt;br&gt;
choose the order of your model. And beware fitting&lt;br&gt;
very high order models, just to get an accurate fit.&lt;br&gt;
&lt;br&gt;
Use meshgrid to generate x and y. For example,&lt;br&gt;
&lt;br&gt;
[x,y] = meshgrid(-36:6:36);&lt;br&gt;
xy = [x(:),y(:)];&lt;br&gt;
model = polyfitn(xy,z,3);&lt;br&gt;
&lt;br&gt;
HTH,&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Fri, 21 Nov 2008 20:38:01 -0500</pubDate>
      <title>Re: determining the equation of a 3-D surface</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692#612481</link>
      <author>loic paccard</author>
      <description>&quot;Johan Carlson&quot; &amp;lt;Johan.E.Carlson@gmail.com&amp;gt; wrote in message &amp;lt;gg73kq$53o$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
Your code is very great for minimizing the total sum of squared distances to my measured data but this is not really the solution to my problem..&lt;br&gt;
&lt;br&gt;
Maybe I should explain more..&lt;br&gt;
I am working on calibrating a probe and data is taken in 169 points in a plane x by y where x is between -36 to 36 by a 6 degree step and the same for y.&lt;br&gt;
&lt;br&gt;
By measuring data in these points, a calculation using data discrete values give me a z value for each point.&lt;br&gt;
So 169 values in my grid.&lt;br&gt;
These 169 values define my surface, there is no noise, it is a physical shape surface of the probe's sensitivity.&lt;br&gt;
The goal is to minimize this value and get the position (x,y) associated with.&lt;br&gt;
For this I can interpolate easily my data values in other points of the grid by interp2 but what I need is using fmincon for get a minimum in a optimized way.&lt;br&gt;
&lt;br&gt;
And fmincon seems to work only with analytical expression function and not with&lt;br&gt;
evaluated values of a variable.&lt;br&gt;
&lt;br&gt;
I know that I could use min(min(MYmatrix) but the final purpose is to get accuracy on x and y about 0.1 for a great number of samples. So a basic search like min(min(..)) will be too lomg.&lt;br&gt;
&lt;br&gt;
So I definitively need to use a powerful minimizer like fmincon.</description>
    </item>
    <item>
      <pubDate>Fri, 21 Nov 2008 20:47:02 -0500</pubDate>
      <title>Re: determining the equation of a 3-D surface</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692#612483</link>
      <author>Bruno Luong</author>
      <description>&quot;loic paccard&quot; &amp;lt;loic.paccard@ecam.fr&amp;gt; wrote in message &amp;lt;gg7679$i6v$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; And fmincon seems to work only with analytical expression function and not with&lt;br&gt;
&amp;gt; evaluated values of a variable.&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
I repeat again: the above is not true. fmincon can even work with any function computed from a sophisticated algorithm, there is no requirement what so ever about analytical form of the function.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Fri, 21 Nov 2008 20:55:03 -0500</pubDate>
      <title>Re: determining the equation of a 3-D surface</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692#612486</link>
      <author>John D'Errico</author>
      <description>&quot;loic paccard&quot; &amp;lt;loic.paccard@ecam.fr&amp;gt; wrote in message &amp;lt;gg7679$i6v$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Johan Carlson&quot; &amp;lt;Johan.E.Carlson@gmail.com&amp;gt; wrote in message &amp;lt;gg73kq$53o$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Your code is very great for minimizing the total sum of squared distances to my measured data but this is not really the solution to my problem..&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Maybe I should explain more..&lt;br&gt;
&amp;gt; I am working on calibrating a probe and data is taken in 169 points in a plane x by y where x is between -36 to 36 by a 6 degree step and the same for y.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; By measuring data in these points, a calculation using data discrete values give me a z value for each point.&lt;br&gt;
&amp;gt; So 169 values in my grid.&lt;br&gt;
&amp;gt; These 169 values define my surface, there is no noise, it is a physical shape surface of the probe's sensitivity.&lt;br&gt;
&amp;gt; The goal is to minimize this value and get the position (x,y) associated with.&lt;br&gt;
&amp;gt; For this I can interpolate easily my data values in other points of the grid by interp2 but what I need is using fmincon for get a minimum in a optimized way.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; And fmincon seems to work only with analytical expression function and not with&lt;br&gt;
&amp;gt; evaluated values of a variable.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I know that I could use min(min(MYmatrix) but the final purpose is to get accuracy on x and y about 0.1 for a great number of samples. So a basic search like min(min(..)) will be too lomg.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; So I definitively need to use a powerful minimizer like fmincon.&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
You actually want to find a minimum point on the&lt;br&gt;
surface?&lt;br&gt;
&lt;br&gt;
Just use interp2, with one of the smooth interpolants,&lt;br&gt;
not the default interpolation method which is bilinear.&lt;br&gt;
Thus, use either 'cubic' or 'spline' as the method.&lt;br&gt;
&lt;br&gt;
Then, use an optimizer, applied to the prediction&lt;br&gt;
interpolated by interp2. The starting value you would&lt;br&gt;
use is just the location of the minimum value at any&lt;br&gt;
of the nodes in the lattice. You might want to apply&lt;br&gt;
bounds to the optimizer, to keep it within the range&lt;br&gt;
of the data points, so fmincon is an option, but also&lt;br&gt;
my fminsearchbnd from the file exchange. You do&lt;br&gt;
not need anything complicated for the optimization.&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/8277&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/8277&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Fri, 21 Nov 2008 21:16:03 -0500</pubDate>
      <title>Re: determining the equation of a 3-D surface</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692#612488</link>
      <author>loic paccard</author>
      <description>&quot;John D'Errico&quot; &amp;lt;woodchips@rochester.rr.com&amp;gt; wrote in message &amp;lt;gg7777$52l$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;loic paccard&quot; &amp;lt;loic.paccard@ecam.fr&amp;gt; wrote in message &amp;lt;gg7679$i6v$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &quot;Johan Carlson&quot; &amp;lt;Johan.E.Carlson@gmail.com&amp;gt; wrote in message &amp;lt;gg73kq$53o$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; You actually want to find a minimum point on the&lt;br&gt;
&amp;gt; surface?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Just use interp2, with one of the smooth interpolants,&lt;br&gt;
&amp;gt; not the default interpolation method which is bilinear.&lt;br&gt;
&amp;gt; Thus, use either 'cubic' or 'spline' as the method.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Then, use an optimizer, applied to the prediction&lt;br&gt;
&amp;gt; interpolated by interp2. The starting value you would&lt;br&gt;
&amp;gt; use is just the location of the minimum value at any&lt;br&gt;
&amp;gt; of the nodes in the lattice. You might want to apply&lt;br&gt;
&amp;gt; bounds to the optimizer, to keep it within the range&lt;br&gt;
&amp;gt; of the data points, so fmincon is an option, but also&lt;br&gt;
&amp;gt; my fminsearchbnd from the file exchange. You do&lt;br&gt;
&amp;gt; not need anything complicated for the optimization.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/8277&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/8277&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; John&lt;br&gt;
&lt;br&gt;
I just to minimize you are right.&lt;br&gt;
Either fmincon or fminsearchbnd would be a way.&lt;br&gt;
Ok but how can I write my objective function fun??&lt;br&gt;
I have only predicted values from real data and interpolations.&lt;br&gt;
&lt;br&gt;
x = fminsearch(fun,x0,options)</description>
    </item>
    <item>
      <pubDate>Fri, 21 Nov 2008 22:06:03 -0500</pubDate>
      <title>Re: determining the equation of a 3-D surface</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692#612494</link>
      <author>John D'Errico</author>
      <description>&quot;loic paccard&quot; &amp;lt;loic.paccard@ecam.fr&amp;gt; wrote in message &amp;lt;gg78ej$pbp$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;John D'Errico&quot; &amp;lt;woodchips@rochester.rr.com&amp;gt; wrote in message &amp;lt;gg7777$52l$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &quot;loic paccard&quot; &amp;lt;loic.paccard@ecam.fr&amp;gt; wrote in message &amp;lt;gg7679$i6v$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &quot;Johan Carlson&quot; &amp;lt;Johan.E.Carlson@gmail.com&amp;gt; wrote in message &amp;lt;gg73kq$53o$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; You actually want to find a minimum point on the&lt;br&gt;
&amp;gt; &amp;gt; surface?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Just use interp2, with one of the smooth interpolants,&lt;br&gt;
&amp;gt; &amp;gt; not the default interpolation method which is bilinear.&lt;br&gt;
&amp;gt; &amp;gt; Thus, use either 'cubic' or 'spline' as the method.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Then, use an optimizer, applied to the prediction&lt;br&gt;
&amp;gt; &amp;gt; interpolated by interp2. The starting value you would&lt;br&gt;
&amp;gt; &amp;gt; use is just the location of the minimum value at any&lt;br&gt;
&amp;gt; &amp;gt; of the nodes in the lattice. You might want to apply&lt;br&gt;
&amp;gt; &amp;gt; bounds to the optimizer, to keep it within the range&lt;br&gt;
&amp;gt; &amp;gt; of the data points, so fmincon is an option, but also&lt;br&gt;
&amp;gt; &amp;gt; my fminsearchbnd from the file exchange. You do&lt;br&gt;
&amp;gt; &amp;gt; not need anything complicated for the optimization.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/8277&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/8277&lt;/a&gt;&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; John&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I just to minimize you are right.&lt;br&gt;
&amp;gt; Either fmincon or fminsearchbnd would be a way.&lt;br&gt;
&amp;gt; Ok but how can I write my objective function fun??&lt;br&gt;
&amp;gt; I have only predicted values from real data and interpolations.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; x = fminsearch(fun,x0,options)&lt;br&gt;
&lt;br&gt;
I'll assume that z is a 13x13 array of points.&lt;br&gt;
&lt;br&gt;
[x,y] = meshgrid(-36:6:36);&lt;br&gt;
fun = @(xy) interp2(x,y,z,xy(1),xy(2),'spline');&lt;br&gt;
[junk,ind] = min(z(:));&lt;br&gt;
xystart = [x(ind),y(ind)];&lt;br&gt;
&lt;br&gt;
Now just optimize fun. You might want to use a&lt;br&gt;
bounded optimizer, either fmincon or fminsearchbnd&lt;br&gt;
to keep you inside [-36,36]X[-36,36]. Something&lt;br&gt;
like this:&lt;br&gt;
&lt;br&gt;
xy = fminsearchbnd(fun,xystart,[-36 -36],[36 36]);&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Fri, 21 Nov 2008 22:13:01 -0500</pubDate>
      <title>Re: determining the equation of a 3-D surface</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692#612499</link>
      <author>loic paccard</author>
      <description>&quot;John D'Errico&quot; &amp;lt;woodchips@rochester.rr.com&amp;gt; wrote in message &amp;lt;gg7bcb$asf$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
Thanks a lot John you're very helpful!</description>
    </item>
    <item>
      <pubDate>Wed, 22 Apr 2009 15:14:02 -0400</pubDate>
      <title>Re: determining the equation of a 3-D surface</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239692#644674</link>
      <author>Simone </author>
      <description>&quot;loic paccard&quot; &amp;lt;loic.paccard@ecam.fr&amp;gt; wrote in message &amp;lt;gg7bpd$i6c$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;John D'Errico&quot; &amp;lt;woodchips@rochester.rr.com&amp;gt; wrote in message &amp;lt;gg7bcb$asf$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks a lot John you're very helpful!&lt;br&gt;
&lt;br&gt;
Dear All,&lt;br&gt;
I am kind of new to Matlab and confused I suppose, I think we should be able to use the function defined in &quot;fun&quot; by D'Errico also to evaluate other data points but they have to be Meshgrid type or monotonic vectors, is that true? Is there a way of getting the original data points evaluated, instead of the meshgrid points or other interpolations??? Is this interpolation the same as polyfitn(thanks for this toolbox, it's very nice!!!) ???&lt;br&gt;
I have data in x,y,z format, trying to get a relationship among the three, possibly functional, but I'm getting poor fit to my data with polynomial fitting (for sure graphically in Mathematica and instead for sure numerically in Matlab): I thought it could be much more interesting to have a more general (more destructured) form for the function and that the &quot;fun&quot; specified above by D'Errico could be good for my case, if I were able to use it. &lt;br&gt;
(I don't have access to surface Fitting Tool, would that solve it though???)&lt;br&gt;
I can't find the way, maybe I am really too confused!!!&lt;br&gt;
thanks a lot for taking the time to dissipate my doubts,&lt;br&gt;
best regards,&lt;br&gt;
Simone</description>
    </item>
  </channel>
</rss>

