<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168085</link>
    <title>MATLAB Central Newsreader - 3d surface fitting</title>
    <description>Feed for thread: 3d surface fitting</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>Wed, 23 Apr 2008 01:28:02 -0400</pubDate>
      <title>3d surface fitting</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168085#428318</link>
      <author>Arjun Chennu</author>
      <description>Hi,&lt;br&gt;
&lt;br&gt;
I have a 320x240 pixel grayscale image, which captures the&lt;br&gt;
intensity profile information of a beam. The beam is a&lt;br&gt;
nondiffracting bessel beam... and hence, features a bessel&lt;br&gt;
function distribution in 3D.&lt;br&gt;
&lt;br&gt;
I'm trying to fit a 5 parameter bessel function to the data,&lt;br&gt;
so that I can extract the bessel parameters. While I've done&lt;br&gt;
some 2d curve fitting before, I'm not sure how to do 3D&lt;br&gt;
surface fitting. &lt;br&gt;
&lt;br&gt;
I tried using lsqcurvefit and some other functions, but&lt;br&gt;
nothing seems to work. Mainly, I'm not sure how to pass the&lt;br&gt;
data and the objective function correctly.&lt;br&gt;
&lt;br&gt;
My 5 parameter objective function is:&lt;br&gt;
&lt;br&gt;
a * [besselj(0,b * sqrt( (x-c)^2 + (y-d)^2 ) )]^2 + e&lt;br&gt;
&lt;br&gt;
My image data is a 320x240 array of type 'double'.&lt;br&gt;
&lt;br&gt;
Can somebody please guide me about fitting my data to the&lt;br&gt;
equation, and producing a mesh of it?&lt;br&gt;
&lt;br&gt;
Thanks in advance!&lt;br&gt;
Arjun</description>
    </item>
    <item>
      <pubDate>Wed, 23 Apr 2008 02:42:01 -0400</pubDate>
      <title>Re: 3d surface fitting</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168085#428323</link>
      <author>John D'Errico</author>
      <description>&quot;Arjun Chennu&quot; &amp;lt;arjun.chennu@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;fum3b2$nc9$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have a 320x240 pixel grayscale image, which captures the&lt;br&gt;
&amp;gt; intensity profile information of a beam. The beam is a&lt;br&gt;
&amp;gt; nondiffracting bessel beam... and hence, features a bessel&lt;br&gt;
&amp;gt; function distribution in 3D.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I'm trying to fit a 5 parameter bessel function to the data,&lt;br&gt;
&amp;gt; so that I can extract the bessel parameters. While I've done&lt;br&gt;
&amp;gt; some 2d curve fitting before, I'm not sure how to do 3D&lt;br&gt;
&amp;gt; surface fitting. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I tried using lsqcurvefit and some other functions, but&lt;br&gt;
&amp;gt; nothing seems to work. Mainly, I'm not sure how to pass the&lt;br&gt;
&amp;gt; data and the objective function correctly.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; My 5 parameter objective function is:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; a * [besselj(0,b * sqrt( (x-c)^2 + (y-d)^2 ) )]^2 + e&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; My image data is a 320x240 array of type 'double'.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Can somebody please guide me about fitting my data to the&lt;br&gt;
&amp;gt; equation, and producing a mesh of it?&lt;br&gt;
&lt;br&gt;
[x,y] = meshgrid(1:240,1:320);&lt;br&gt;
fun = @(c) c(!)*besselj(0,c(2)*sqrt((x-c(3)).^2+(y-c(4)).^2)).^2+c(5);&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Wed, 23 Apr 2008 11:57:01 -0400</pubDate>
      <title>Re: 3d surface fitting</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168085#428391</link>
      <author>Arjun Chennu</author>
      <description>&lt;br&gt;
&amp;gt; [x,y] = meshgrid(1:240,1:320);&lt;br&gt;
&amp;gt; fun = @(c)&lt;br&gt;
c(!)*besselj(0,c(2)*sqrt((x-c(3)).^2+(y-c(4)).^2)).^2+c(5);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; John&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Hi John,&lt;br&gt;
&lt;br&gt;
Thanks a lot for your quick reply!&lt;br&gt;
&lt;br&gt;
Indeed, I have defined my function as:&lt;br&gt;
&lt;br&gt;
function err = myfit(p, realdata)&lt;br&gt;
[x,y] = meshgrid(1:240,1:320);&lt;br&gt;
calcval = p(1)*besselj(0,&lt;br&gt;
p(2)*sqrt((x-p(3)).^2+(y-p(4)).^2)).^2 +p(5);&lt;br&gt;
size(calcval)&lt;br&gt;
err = (calcval - realdata).^2;&lt;br&gt;
return&lt;br&gt;
&lt;br&gt;
However, when I use lsqcurvefit:&lt;br&gt;
&lt;br&gt;
[p, resnorm] = lsqcurvefit(@myfit,p_start,dd)&lt;br&gt;
&lt;br&gt;
it says it needs a fourth argument. (dd is the experimental&lt;br&gt;
data to which I'm trying to fit my function myfit).&lt;br&gt;
&lt;br&gt;
The help file says:&lt;br&gt;
x = lsqcurvefit(fun,x0,xdata,ydata) starts at x0 and finds&lt;br&gt;
coefficients x to best fit the nonlinear function&lt;br&gt;
fun(x,xdata) to the data ydata (in the least-squares sense).&lt;br&gt;
ydata must be the same size as the vector (or matrix) F&lt;br&gt;
returned by fun.&lt;br&gt;
&lt;br&gt;
so here ydata is dd.&lt;br&gt;
&lt;br&gt;
But what is xdata? I'm not sure what I'm supposed to pass as&lt;br&gt;
xdata.&lt;br&gt;
&lt;br&gt;
Help muchos appreciated! Thanks again.&lt;br&gt;
&lt;br&gt;
Arjun</description>
    </item>
    <item>
      <pubDate>Wed, 23 Apr 2008 12:16:02 -0400</pubDate>
      <title>Re: 3d surface fitting</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168085#428396</link>
      <author>John D'Errico</author>
      <description>&quot;Arjun Chennu&quot; &amp;lt;arjun.chennu@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;fun86d$o8a$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; [x,y] = meshgrid(1:240,1:320);&lt;br&gt;
&amp;gt; &amp;gt; fun = @(c)&lt;br&gt;
&amp;gt; c(!)*besselj(0,c(2)*sqrt((x-c(3)).^2+(y-c(4)).^2)).^2+c(5);&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; &lt;br&gt;
&amp;gt; Hi John,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks a lot for your quick reply!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Indeed, I have defined my function as:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; function err = myfit(p, realdata)&lt;br&gt;
&amp;gt; [x,y] = meshgrid(1:240,1:320);&lt;br&gt;
&amp;gt; calcval = p(1)*besselj(0,&lt;br&gt;
&amp;gt; p(2)*sqrt((x-p(3)).^2+(y-p(4)).^2)).^2 +p(5);&lt;br&gt;
&amp;gt; size(calcval)&lt;br&gt;
&amp;gt; err = (calcval - realdata).^2;&lt;br&gt;
&amp;gt; return&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; However, when I use lsqcurvefit:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; [p, resnorm] = lsqcurvefit(@myfit,p_start,dd)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; it says it needs a fourth argument. (dd is the experimental&lt;br&gt;
&amp;gt; data to which I'm trying to fit my function myfit).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The help file says:&lt;br&gt;
&amp;gt; x = lsqcurvefit(fun,x0,xdata,ydata) starts at x0 and finds&lt;br&gt;
&amp;gt; coefficients x to best fit the nonlinear function&lt;br&gt;
&amp;gt; fun(x,xdata) to the data ydata (in the least-squares sense).&lt;br&gt;
&amp;gt; ydata must be the same size as the vector (or matrix) F&lt;br&gt;
&amp;gt; returned by fun.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; so here ydata is dd.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; But what is xdata? I'm not sure what I'm supposed to pass as&lt;br&gt;
&amp;gt; xdata.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Help muchos appreciated! Thanks again.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Arjun&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
There are two things to do here. First, Do NOT&lt;br&gt;
square the residuals. lsqcurvefit will subtract&lt;br&gt;
the aim (ydata) and square the residuals itself.&lt;br&gt;
&lt;br&gt;
Next, you can probably save some small amount&lt;br&gt;
of time by not generating the meshgrid for every&lt;br&gt;
call into your function. Since you must pass in&lt;br&gt;
xdata anyway, this should already contain x&lt;br&gt;
and y.&lt;br&gt;
&lt;br&gt;
Using an anonymous function, the call might&lt;br&gt;
look like this:&lt;br&gt;
&lt;br&gt;
[x,y] = meshgrid(1:240,1:320);&lt;br&gt;
xdata = {x,y};&lt;br&gt;
fun = @(c,xdata) c(1)*besselj(0, ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;c(2)*sqrt((xdata{1}-c(3)).^2+(xdata{2}-c(4)).^2)).^2+c(5);&lt;br&gt;
&lt;br&gt;
[p, resnorm] = lsqcurvefit(fun,p_start,xdata,dd);&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Wed, 23 Apr 2008 17:38:02 -0400</pubDate>
      <title>Re: 3d surface fitting</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168085#428472</link>
      <author>Arjun Chennu</author>
      <description>&amp;gt; Using an anonymous function, the call might&lt;br&gt;
&amp;gt; look like this:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; [x,y] = meshgrid(1:240,1:320);&lt;br&gt;
&amp;gt; xdata = {x,y};&lt;br&gt;
&amp;gt; fun = @(c,xdata) c(1)*besselj(0, ...&lt;br&gt;
&amp;gt;     &lt;br&gt;
c(2)*sqrt((xdata{1}-c(3)).^2+(xdata{2}-c(4)).^2)).^2+c(5);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; [p, resnorm] = lsqcurvefit(fun,p_start,xdata,dd);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; John&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Ah, I see. I did not know of this &quot;cell array&quot; option with&lt;br&gt;
the curly braces. Thanks for that tip. :)&lt;br&gt;
&lt;br&gt;
Can you tell me if there is some way I can set the lb and ub&lt;br&gt;
(bounds) so that I can constrain them to real numbers?&lt;br&gt;
Complex values in the parameters are troubling.&lt;br&gt;
&lt;br&gt;
I've got my lsqcurvefit line trying to come up with a set of&lt;br&gt;
5 parameters now, however the final result is rather far&lt;br&gt;
from the data that I have. (The bessel is too thin). I'm&lt;br&gt;
trying reducing the tolerance to 1e-9, but don't think it&lt;br&gt;
has helped. Anything I might be missing?&lt;br&gt;
&lt;br&gt;
Arjun</description>
    </item>
    <item>
      <pubDate>Wed, 23 Apr 2008 18:32:03 -0400</pubDate>
      <title>Re: 3d surface fitting</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168085#428478</link>
      <author>John D'Errico</author>
      <description>&quot;Arjun Chennu&quot; &amp;lt;arjun.chennu@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;funs5q$jaf$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Using an anonymous function, the call might&lt;br&gt;
&amp;gt; &amp;gt; look like this:&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; [x,y] = meshgrid(1:240,1:320);&lt;br&gt;
&amp;gt; &amp;gt; xdata = {x,y};&lt;br&gt;
&amp;gt; &amp;gt; fun = @(c,xdata) c(1)*besselj(0, ...&lt;br&gt;
&amp;gt; &amp;gt;     &lt;br&gt;
&amp;gt; c(2)*sqrt((xdata{1}-c(3)).^2+(xdata{2}-c(4)).^2)).^2+c(5);&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; [p, resnorm] = lsqcurvefit(fun,p_start,xdata,dd);&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; &lt;br&gt;
&amp;gt; Ah, I see. I did not know of this &quot;cell array&quot; option with&lt;br&gt;
&amp;gt; the curly braces. Thanks for that tip. :)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Can you tell me if there is some way I can set the lb and ub&lt;br&gt;
&amp;gt; (bounds) so that I can constrain them to real numbers?&lt;br&gt;
&amp;gt; Complex values in the parameters are troubling.&lt;br&gt;
&lt;br&gt;
No. You cannot constrain it in this way.&lt;br&gt;
&lt;br&gt;
But what you can do is to recognize that&lt;br&gt;
besselj(0,x) has essentially zero imaginary&lt;br&gt;
part over the entire real line. But, when x&lt;br&gt;
is negative, it generates a tiny imaginary&lt;br&gt;
part.&lt;br&gt;
&lt;br&gt;
besselj(0,5)&lt;br&gt;
ans =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-0.1776&lt;br&gt;
&lt;br&gt;
besselj(0,-5)&lt;br&gt;
ans =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-0.1776 - 4.5591e-17i&lt;br&gt;
&lt;br&gt;
besselj(0,-25)&lt;br&gt;
ans =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.096267 + 1.0399e-17i&lt;br&gt;
besselj(0,0)&lt;br&gt;
&lt;br&gt;
So you can ignore that imaginary part, by&lt;br&gt;
inserting a call to real on the result.&lt;br&gt;
&lt;br&gt;
fun2 = @(c,xdata) real(fun(c,xdata));&lt;br&gt;
[p, resnorm] = lsqcurvefit(fun2,p_start,xdata,dd);&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&amp;gt; I've got my lsqcurvefit line trying to come up with a set of&lt;br&gt;
&amp;gt; 5 parameters now, however the final result is rather far&lt;br&gt;
&amp;gt; from the data that I have. (The bessel is too thin). I'm&lt;br&gt;
&amp;gt; trying reducing the tolerance to 1e-9, but don't think it&lt;br&gt;
&amp;gt; has helped. Anything I might be missing?&lt;br&gt;
&lt;br&gt;
If the curve has the wrong fundamental shape,&lt;br&gt;
then insisting that it take on the shape you&lt;br&gt;
want will not help.&lt;br&gt;
&lt;br&gt;
Effectively, this is all you are doing when you&lt;br&gt;
tighten the tolerance. You are demanding&lt;br&gt;
more and more fervently that the curve takes&lt;br&gt;
on a different shape. Your demands will fall&lt;br&gt;
on deaf ears I'm afraid.&lt;br&gt;
&lt;br&gt;
You might want to take a read through this&lt;br&gt;
document. It talks about the idea of a&lt;br&gt;
fundamental shape of a curve, and what&lt;br&gt;
you can do.&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?&lt;/a&gt;&lt;br&gt;
objectId=10864&amp;objectType=FILE&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Fri, 25 Apr 2008 00:25:05 -0400</pubDate>
      <title>Re: 3d surface fitting</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168085#428762</link>
      <author>Arjun Chennu</author>
      <description>&lt;br&gt;
&amp;gt; If the curve has the wrong fundamental shape,&lt;br&gt;
&amp;gt; then insisting that it take on the shape you&lt;br&gt;
&amp;gt; want will not help.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Effectively, this is all you are doing when you&lt;br&gt;
&amp;gt; tighten the tolerance. You are demanding&lt;br&gt;
&amp;gt; more and more fervently that the curve takes&lt;br&gt;
&amp;gt; on a different shape. Your demands will fall&lt;br&gt;
&amp;gt; on deaf ears I'm afraid.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You might want to take a read through this&lt;br&gt;
&amp;gt; document. It talks about the idea of a&lt;br&gt;
&amp;gt; fundamental shape of a curve, and what&lt;br&gt;
&amp;gt; you can do.&lt;br&gt;
&lt;br&gt;
Thanks! That was indeed an interesting read on data&lt;br&gt;
modelling... cleared up a few concepts better! :-)&lt;br&gt;
&lt;br&gt;
However, from my theoretical predictions the intensity&lt;br&gt;
profile must be the square of a bessel function (of the&lt;br&gt;
first kind). That is the model I'm applying... &lt;br&gt;
&lt;br&gt;
... and the fit does find a bessel, but not centered at the&lt;br&gt;
same spot as my empirical curve, and neither the same&lt;br&gt;
'thickness' of the central core. &lt;br&gt;
&lt;br&gt;
Thus: a huge resnorm (of 1e7 or 1e8 order), and a residual&lt;br&gt;
with bumps and humps from the zero plane.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
While I realize I'm trying to coerce the minimization to&lt;br&gt;
render a bessel form, there ARE some problems with my data:&lt;br&gt;
&lt;br&gt;
1. In some of the frames, the central core has saturated the&lt;br&gt;
ccd, and so the &quot;heads&quot; of the bessel are chopped off at the&lt;br&gt;
ends.&lt;br&gt;
&lt;br&gt;
2. Due to a slight amount of astigmatism, the annular rings&lt;br&gt;
are not perfectly symmetrical but have a higher intensity in&lt;br&gt;
one direction, or so.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
I thought these limitations would not change severly affect&lt;br&gt;
the fit, because the smallest residual should be the one&lt;br&gt;
with the bessel's &quot;head&quot; filled out, with the annular rings&lt;br&gt;
matching up. &lt;br&gt;
&lt;br&gt;
But that doesn't seem to be the case. Is there an&lt;br&gt;
intelligent way to edit my model to incorporate the planar&lt;br&gt;
top of the bessel into the fit? &lt;br&gt;
&lt;br&gt;
This has been a journey into modelling for me. Thanks for&lt;br&gt;
the guidance! :)&lt;br&gt;
&lt;br&gt;
Arjun</description>
    </item>
    <item>
      <pubDate>Fri, 25 Apr 2008 03:02:01 -0400</pubDate>
      <title>Re: 3d surface fitting</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168085#428775</link>
      <author>John D'Errico</author>
      <description>&quot;Arjun Chennu&quot; &amp;lt;arjun.chennu@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;fur8d1$8ja$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; If the curve has the wrong fundamental shape,&lt;br&gt;
&amp;gt; &amp;gt; then insisting that it take on the shape you&lt;br&gt;
&amp;gt; &amp;gt; want will not help.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Effectively, this is all you are doing when you&lt;br&gt;
&amp;gt; &amp;gt; tighten the tolerance. You are demanding&lt;br&gt;
&amp;gt; &amp;gt; more and more fervently that the curve takes&lt;br&gt;
&amp;gt; &amp;gt; on a different shape. Your demands will fall&lt;br&gt;
&amp;gt; &amp;gt; on deaf ears I'm afraid.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; You might want to take a read through this&lt;br&gt;
&amp;gt; &amp;gt; document. It talks about the idea of a&lt;br&gt;
&amp;gt; &amp;gt; fundamental shape of a curve, and what&lt;br&gt;
&amp;gt; &amp;gt; you can do.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks! That was indeed an interesting read on data&lt;br&gt;
&amp;gt; modelling... cleared up a few concepts better! :-)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; However, from my theoretical predictions the intensity&lt;br&gt;
&amp;gt; profile must be the square of a bessel function (of the&lt;br&gt;
&amp;gt; first kind). That is the model I'm applying... &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ... and the fit does find a bessel, but not centered at the&lt;br&gt;
&amp;gt; same spot as my empirical curve, and neither the same&lt;br&gt;
&amp;gt; 'thickness' of the central core. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thus: a huge resnorm (of 1e7 or 1e8 order), and a residual&lt;br&gt;
&amp;gt; with bumps and humps from the zero plane.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; While I realize I'm trying to coerce the minimization to&lt;br&gt;
&amp;gt; render a bessel form, there ARE some problems with my data:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 1. In some of the frames, the central core has saturated the&lt;br&gt;
&amp;gt; ccd, and so the &quot;heads&quot; of the bessel are chopped off at the&lt;br&gt;
&amp;gt; ends.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 2. Due to a slight amount of astigmatism, the annular rings&lt;br&gt;
&amp;gt; are not perfectly symmetrical but have a higher intensity in&lt;br&gt;
&amp;gt; one direction, or so.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I thought these limitations would not change severly affect&lt;br&gt;
&amp;gt; the fit, because the smallest residual should be the one&lt;br&gt;
&amp;gt; with the bessel's &quot;head&quot; filled out, with the annular rings&lt;br&gt;
&amp;gt; matching up. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; But that doesn't seem to be the case. Is there an&lt;br&gt;
&amp;gt; intelligent way to edit my model to incorporate the planar&lt;br&gt;
&amp;gt; top of the bessel into the fit? &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; This has been a journey into modelling for me. Thanks for&lt;br&gt;
&amp;gt; the guidance! :)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Arjun&lt;br&gt;
&lt;br&gt;
Modeling is a sometimes tricky thing, as you&lt;br&gt;
are finding. It sounds like your data has some&lt;br&gt;
problems. Why does data always come out that&lt;br&gt;
way? ;-)&lt;br&gt;
&lt;br&gt;
One option is to down-weight data points that&lt;br&gt;
you don't trust. Its not that hard to build a&lt;br&gt;
weighted fit.&lt;br&gt;
&lt;br&gt;
Do you have good enough starting values?&lt;br&gt;
Sometimes if the starting values are poor on&lt;br&gt;
problematic data, the whole thing diverges on&lt;br&gt;
you. One way to improve things is to use a&lt;br&gt;
partitioned fit. The idea is to use a tool like&lt;br&gt;
my fminspleas, which reduces the problem&lt;br&gt;
to a 3 variable one from 5 variables. So you&lt;br&gt;
only need to choose starting values for those&lt;br&gt;
three parameters.&lt;br&gt;
&lt;br&gt;
data = {x,y};&lt;br&gt;
funlist = {@(params,data) besselj(0, ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;params(1)*sqrt( (data{1}-params(2)).^2 + ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;(data{2}-params(3)).^2 )).^2,1};&lt;br&gt;
&lt;br&gt;
[INLP,ILP] = fminspleas(funlist,NLPstart,data,z)&lt;br&gt;
&lt;br&gt;
The nonlinear parameters are [b,c,d] in your&lt;br&gt;
model, and the linear parameters are [a,e].&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?&lt;/a&gt;&lt;br&gt;
objectId=10093&amp;objectType=FILE&lt;br&gt;
&lt;br&gt;
I'm not certain about what the problem is with&lt;br&gt;
your data. Is it the asymmetry? Or is it that&lt;br&gt;
the central peak has the wrong shape?&lt;br&gt;
&lt;br&gt;
You might try down weighting the outer lobes,&lt;br&gt;
or vice-versa. Or perhaps build an asymmetric&lt;br&gt;
bessel, so that the radial behavior is a function&lt;br&gt;
of angle. Or, you might add a secondary term&lt;br&gt;
to tweak the shape of that central peak. There&lt;br&gt;
are lots of things you might try here, so don't&lt;br&gt;
give in.&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Sun, 27 Apr 2008 16:26:02 -0400</pubDate>
      <title>Re: 3d surface fitting</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168085#429058</link>
      <author>Arjun Chennu</author>
      <description>&amp;gt; Modeling is a sometimes tricky thing, as you&lt;br&gt;
&amp;gt; are finding. It sounds like your data has some&lt;br&gt;
&amp;gt; problems. Why does data always come out that&lt;br&gt;
&amp;gt; way? ;-)&lt;br&gt;
&lt;br&gt;
I don't know, but there should be a statistical law about&lt;br&gt;
the errors of experimentation.... as oppossed to just &quot;being&lt;br&gt;
careful&quot;. :)&lt;br&gt;
&lt;br&gt;
I'm really thankful for your (yet another) tip about&lt;br&gt;
fminspleas. Reducing it to a 3 NLP fit already starting&lt;br&gt;
giving me the right bessel form, but still couldn't do it&lt;br&gt;
well for half the datasets.&lt;br&gt;
&lt;br&gt;
After that I used the built-in weighting options to focus&lt;br&gt;
mainly on the central lobe, and now the fits work for&lt;br&gt;
(almost) all the datasets! :-)&lt;br&gt;
&lt;br&gt;
I'm not sure I really understand though what fminspleas does&lt;br&gt;
different from lsqcurvefit. They both seem to solve problems&lt;br&gt;
in a least square sense, but the main difference seems to be&lt;br&gt;
in the way the parameters are handled/prioritized. &lt;br&gt;
&lt;br&gt;
However, I couldn't really understand why it is faster or&lt;br&gt;
more effective?&lt;br&gt;
&lt;br&gt;
Thanks again! :) A real pleasure to talk with an 'expert'.</description>
    </item>
    <item>
      <pubDate>Mon, 28 Apr 2008 01:07:02 -0400</pubDate>
      <title>Re: 3d surface fitting</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168085#429093</link>
      <author>John D'Errico</author>
      <description>&quot;Arjun Chennu&quot; &amp;lt;arjun.chennu@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;fv29eq$38p$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Modeling is a sometimes tricky thing, as you&lt;br&gt;
&amp;gt; &amp;gt; are finding. It sounds like your data has some&lt;br&gt;
&amp;gt; &amp;gt; problems. Why does data always come out that&lt;br&gt;
&amp;gt; &amp;gt; way? ;-)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I don't know, but there should be a statistical law about&lt;br&gt;
&amp;gt; the errors of experimentation.... as oppossed to just &quot;being&lt;br&gt;
&amp;gt; careful&quot;. :)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I'm really thankful for your (yet another) tip about&lt;br&gt;
&amp;gt; fminspleas. Reducing it to a 3 NLP fit already starting&lt;br&gt;
&amp;gt; giving me the right bessel form, but still couldn't do it&lt;br&gt;
&amp;gt; well for half the datasets.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; After that I used the built-in weighting options to focus&lt;br&gt;
&amp;gt; mainly on the central lobe, and now the fits work for&lt;br&gt;
&amp;gt; (almost) all the datasets! :-)&lt;br&gt;
&lt;br&gt;
(Great!)&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;gt; I'm not sure I really understand though what fminspleas does&lt;br&gt;
&amp;gt; different from lsqcurvefit. They both seem to solve problems&lt;br&gt;
&amp;gt; in a least square sense, but the main difference seems to be&lt;br&gt;
&amp;gt; in the way the parameters are handled/prioritized. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; However, I couldn't really understand why it is faster or&lt;br&gt;
&amp;gt; more effective?&lt;br&gt;
&lt;br&gt;
lsqcurvefit must search a parameter space of&lt;br&gt;
five dimensions on your problem.&lt;br&gt;
&lt;br&gt;
When fminspleas does the optimization, it&lt;br&gt;
breaks the problem into two different classes&lt;br&gt;
of parameters. Two of the parameters can be&lt;br&gt;
estimated using a simple linear regression,&lt;br&gt;
so fminspleas does not need to iterate over&lt;br&gt;
that portion of the parameter space. These&lt;br&gt;
are the &quot;linear&quot; parameters. In fact, a better&lt;br&gt;
description is &quot;conditionally linear&quot;. The&lt;br&gt;
reduction of the problem dimensionality from&lt;br&gt;
five to three dimensions is far more significant&lt;br&gt;
than is the fact that fminsearch is not really a&lt;br&gt;
terribly efficient optimizer.&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
  </channel>
</rss>

