Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: 3d surface fitting
Date: Wed, 23 Apr 2008 18:32:03 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 76
Message-ID: <funvb3$79u$1@fred.mathworks.com>
References: <fum3b2$nc9$1@fred.mathworks.com> <fum7lp$sh9$1@fred.mathworks.com> <fun86d$o8a$1@fred.mathworks.com> <fun9a2$1mp$1@fred.mathworks.com> <funs5q$jaf$1@fred.mathworks.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1208975523 7486 172.30.248.35 (23 Apr 2008 18:32:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 23 Apr 2008 18:32:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:464824



"Arjun Chennu" <arjun.chennu@gmail.com> wrote in message 
<funs5q$jaf$1@fred.mathworks.com>...
> > Using an anonymous function, the call might
> > look like this:
> > 
> > [x,y] = meshgrid(1:240,1:320);
> > xdata = {x,y};
> > fun = @(c,xdata) c(1)*besselj(0, ...
> >     
> c(2)*sqrt((xdata{1}-c(3)).^2+(xdata{2}-c(4)).^2)).^2+c(5);
> > 
> > [p, resnorm] = lsqcurvefit(fun,p_start,xdata,dd);
> > 
> > John
> 
> 
> Ah, I see. I did not know of this "cell array" option with
> the curly braces. Thanks for that tip. :)
> 
> Can you tell me if there is some way I can set the lb and ub
> (bounds) so that I can constrain them to real numbers?
> Complex values in the parameters are troubling.

No. You cannot constrain it in this way.

But what you can do is to recognize that
besselj(0,x) has essentially zero imaginary
part over the entire real line. But, when x
is negative, it generates a tiny imaginary
part.

besselj(0,5)
ans =
      -0.1776

besselj(0,-5)
ans =
      -0.1776 - 4.5591e-17i

besselj(0,-25)
ans =
     0.096267 + 1.0399e-17i
besselj(0,0)

So you can ignore that imaginary part, by
inserting a call to real on the result.

fun2 = @(c,xdata) real(fun(c,xdata));
[p, resnorm] = lsqcurvefit(fun2,p_start,xdata,dd);


> I've got my lsqcurvefit line trying to come up with a set of
> 5 parameters now, however the final result is rather far
> from the data that I have. (The bessel is too thin). I'm
> trying reducing the tolerance to 1e-9, but don't think it
> has helped. Anything I might be missing?

If the curve has the wrong fundamental shape,
then insisting that it take on the shape you
want will not help.

Effectively, this is all you are doing when you
tighten the tolerance. You are demanding
more and more fervently that the curve takes
on a different shape. Your demands will fall
on deaf ears I'm afraid.

You might want to take a read through this
document. It talks about the idea of a
fundamental shape of a curve, and what
you can do.

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?
objectId=10864&objectType=FILE

John