MATLAB: Vector valued guess parameter in fitting function

MATLABnonlinearoptimization

I would like to fit a function of the form (in myfunc):
ydata = x(1) + ((1 – x(2) – x(3) * log(xdata/f))/v)
to a set of data (using lsqcurvefit or lsqnonlin). the input: ydata is a vector, xdata a matrix. I want to get an estimate of parameter x(2) and x(3) which are constants. x(1) is a constant for every entry of xdata and ydata, meaning it has the same dimension as xdata and ydata, but at some entries I know it is zero beforehand. Does one of the matlab functions allow x(1) to vary with different datapoints? And if so, how do I have to code it in myfunc? All the examples I found so far do not match my problem and I don't know how to call lsqnonlin correctly. Thank you in advance for your help.
sandra

Best Answer

LSQCURVEFIT looks more suitable and that's what I do here, but it should be pretty obvious how to modify it if you insist on using LSQNONLIN
x = lsqcurvefit(@(p,xdata)datamatch(p,xdata,non0Indices,f,v),...
p0,xdata,ydata);
function ydata=datamatch(p,xdata,non0Indices,f,v)
x2=p(1);
x3=p(2);
x1=p(3:end);
X1=zeros(size(xdata));
X1(non0Indices) = x1;
ydata = X1 + ((1 - x2 - x3 * log(xdata./f))./v);
Related Question