<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168706</link>
    <title>MATLAB Central Newsreader - polyfit in 3D</title>
    <description>Feed for thread: polyfit in 3D</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2008 by The 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>The MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 08 May 2008 23:07:03 -0400</pubDate>
      <title>Re: polyfit in 3D</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168706#431166</link>
      <author>Roger Stafford</author>
      <description>"Nicolas Guillemette" &amp;lt;nico_guillemette@hotmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;fvl1q3$8sv$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I'm looking for a function that finds the coefficients of a &lt;br&gt;
&amp;gt; polynomial of degree n that fits the data of a three &lt;br&gt;
&amp;gt; dimensional set of variables. I have X, Y and Z vectors and &lt;br&gt;
&amp;gt; I want to fit a plan (not a curve)on XY plan ?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; How can I proceed ?&lt;br&gt;
&amp;gt; Thx&lt;br&gt;
&amp;gt; Nicolas Guillemette&lt;br&gt;
------------&lt;br&gt;
&amp;nbsp;&amp;nbsp;It isn't clear what you are asking, Nicolas.  It doesn't require a polynomial of &lt;br&gt;
degree higher than 1 to define a plane, which is what you seem to be asking &lt;br&gt;
for.  With only degree 2 in x, y, and z, you would be in the realm of ellipsoids, &lt;br&gt;
hyperboloids, paraboloids, and the like.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Also you haven't told us what you regard as your criterion for best fit here.  &lt;br&gt;
In the case of a plane you might want to minimize the mean square deviation &lt;br&gt;
of the points' z coordinates from that of the plane, or you might want to &lt;br&gt;
minimize their mean square orthogonal distances from the plane.  Matlab &lt;br&gt;
provides methods for solving either kind of problem.  Similar questions apply &lt;br&gt;
to higher degree polynomial surfaces.&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 08 May 2008 21:50:19 -0400</pubDate>
      <title>Re: polyfit in 3D</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168706#431160</link>
      <author>alessandro mura</author>
      <description>Here's an example. Also: help inline, help fminsearch, ecc....&lt;br&gt;
Regards&lt;br&gt;
&lt;br&gt;
Ale&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
% make some data&lt;br&gt;
&lt;br&gt;
p=randn(1,6);&lt;br&gt;
&lt;br&gt;
[x,y]=ndgrid([0:.1:1],[0:.1:1]);&lt;br&gt;
&lt;br&gt;
z=polyval(p(1:3),x)+polyval(p(4:6),y)+.1*randn(size(x));&lt;br&gt;
&lt;br&gt;
plot3(x(:),y(:),z(:),'+')&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
hold on&lt;br&gt;
&lt;br&gt;
disp(p)&lt;br&gt;
&lt;br&gt;
clear('p')&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
%fit&lt;br&gt;
&lt;br&gt;
fun='polyval(p(1:3),x)+polyval(p(4:6),y)';&lt;br&gt;
&lt;br&gt;
chi=inline(['sum((' fun '-z).^2)'],'p','x','y','z');&lt;br&gt;
&lt;br&gt;
h=@(p)chi(p,x(:),y(:),z(:));&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
options = &lt;br&gt;
optimset('display','on','MaxIter',1d4,'TolFun',1d-49,'TolX',1d-49,'maxfuneval',1d4);&lt;br&gt;
&lt;br&gt;
p=fminsearch(h,randn(1,6),options);&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
zf=feval(inline(fun,'p','x','y'),p,x,y);&lt;br&gt;
&lt;br&gt;
surf(x,y,zf)&lt;br&gt;
&lt;br&gt;
disp(p)&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Alessandro Mura&lt;br&gt;
Istituto Nazionale di Astrofisica - IFSI&lt;br&gt;
&lt;a href="http://pptt4.ifsi-roma.inaf.it/~mura/index.html"&gt;http://pptt4.ifsi-roma.inaf.it/~mura/index.html&lt;/a&gt;&lt;br&gt;
&lt;a href="http://www.alessandromura.it"&gt;http://www.alessandromura.it&lt;/a&gt; &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sun, 04 May 2008 19:33:38 -0400</pubDate>
      <title>Re: polyfit in 3D</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168706#430205</link>
      <author>Bruno Luong</author>
      <description>Sorry for the typo (uppercase z)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; [X(:) Y(:) ones(numel(Z),1)] \ Z(:)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sun, 04 May 2008 19:26:03 -0400</pubDate>
      <title>Re: polyfit in 3D</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168706#430204</link>
      <author>Bruno Luong</author>
      <description>"Nicolas Guillemette" &amp;lt;nico_guillemette@hotmail.com&amp;gt; wrote&lt;br&gt;
in message &amp;lt;fvl1q3$8sv$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I'm looking for a function that finds the coefficients of a &lt;br&gt;
&amp;gt; polynomial of degree n that fits the data of a three &lt;br&gt;
&amp;gt; dimensional set of variables. I have X, Y and Z vectors and &lt;br&gt;
&amp;gt; I want to fit a plan (not a curve)on XY plan ?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; How can I proceed ?&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
[X(:) Y(:) ones(numel(z),1)] \ Z(:)&lt;br&gt;
&lt;br&gt;
provides you (a,b,c) of the fitted plane z=ax+by+c&lt;br&gt;
&lt;br&gt;
Bruno&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sun, 04 May 2008 19:12:03 -0400</pubDate>
      <title>polyfit in 3D</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168706#430200</link>
      <author>Nicolas Guillemette</author>
      <description>&lt;br&gt;
I'm looking for a function that finds the coefficients of a &lt;br&gt;
polynomial of degree n that fits the data of a three &lt;br&gt;
dimensional set of variables. I have X, Y and Z vectors and &lt;br&gt;
I want to fit a plan (not a curve)on XY plan ?&lt;br&gt;
&lt;br&gt;
How can I proceed ?&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Thx&lt;br&gt;
&lt;br&gt;
Nicolas Guillemette&lt;br&gt;
</description>
    </item>
  </channel>
</rss>
