From: John G on
I'm trying to fit m x n data (let's call it "Q") to a 2D function using lsqnonlin but am having a lot of trouble implementing it. How do you do it for a 2D case? For the 1D case it seems to be something like

x = lsqnonlin(@myfxn, [initial parameters], 1:somenumber, Q);

where

function F = myfxn(x, xdata)
F = function with some parameters
From: Matt J on
"John G" <asdf(a)yahoo.com> wrote in message <i0tisv$oc7$1(a)fred.mathworks.com>...
> I'm trying to fit m x n data (let's call it "Q") to a 2D function using lsqnonlin but am having a lot of trouble implementing it. How do you do it for a 2D case?
==============

You do it for 2D by turning all your 2D arrays into 1D arrays,

Q--->Q(:)

> For the 1D case it seems to be something like
>
> x = lsqnonlin(@myfxn, [initial parameters], 1:somenumber, Q);
>
======

No, that doesn't look right to me. The 3rd and 4th arguments are for upper and lower bounds, not the data to be fitted. And why are you making vague guesses? Didn't you read the help doc?
From: Alan Weiss on
On 7/5/2010 5:30 PM, John G wrote:
> I'm trying to fit m x n data (let's call it "Q") to a 2D function using
> lsqnonlin but am having a lot of trouble implementing it. How do you do
> it for a 2D case? For the 1D case it seems to be something like
>
> x = lsqnonlin(@myfxn, [initial parameters], 1:somenumber, Q);
>
> where
>
> function F = myfxn(x, xdata)
> F = function with some parameters

For the syntax of lsqnonlin, see
http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/lsqnonlin.html

For some examples, see
http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brn4noo.html

Alan Weiss
MATLAB mathematical toolbox documentation
From: Steve on
Alan Weiss <aweiss(a)mathworks.com> wrote in message <i0v5m4$on8$2(a)fred.mathworks.com>...
> On 7/5/2010 5:30 PM, John G wrote:
> > I'm trying to fit m x n data (let's call it "Q") to a 2D function using
> > lsqnonlin but am having a lot of trouble implementing it. How do you do
> > it for a 2D case? For the 1D case it seems to be something like
> >
> > x = lsqnonlin(@myfxn, [initial parameters], 1:somenumber, Q);
> >
> > where
> >
> > function F = myfxn(x, xdata)
> > F = function with some parameters
>
> For the syntax of lsqnonlin, see
> http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/lsqnonlin.html
>
> For some examples, see
> http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brn4noo.html
>
> Alan Weiss
> MATLAB mathematical toolbox documentation

My guess is that you might want lsqcurvefit, which takes input data as xdata with the responses as ydata:
[...] = lsqcurvefit(fun,x0,xdata,ydata,lb,ub,options)

Check here to be sure:
http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/lsqcurvefit.html

-Steve