vector valued guess parameter in fitting function

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

2 个评论

When you say "constant" it sounds like you really mean "scalar".

请先登录,再进行评论。

 采纳的回答

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);

更多回答(0 个)

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by