MATLAB: Global fit of two set data points with common parameters (lsqcurvefit) but different models

lsqcurvefitnonlinear regression

Hi. I have two set of data points (with common xdata set e.g. (x,y1,y2)). That means two yexp are there for each (x1,x2,x3..). Now for lsqcurvefit, I have designed my set of two functions (which are partially different but use same set of parameters) and the output for two functions are collected in a Y(calc) vector. e.g
Y(calc)= [(y1calc(x1),y1calc(x2),y1calc(x3)….y2calc(x1),y2calc(x2)y2calc(x3)…], where y1calc's are calculated values from model1 and y2calc's are from model2. Also the Ydata (exp) that I am giving is in same order so that lsqcurvefit can work correctly. Xdata for which Y's are calculated at each points are repeated according to Y(calc) e.g. Xdata=(x1,x2,x3….x1,x2,x3) Is this the right approach to the situation? I hope I was able to explain it correctly. Thanks

Best Answer

Xdata for which Y's are calculated at each points are repeated according to Y(calc) e.g. Xdata=(x1,x2,x3....x1,x2,x3) Is this the right approach to the situation?
No, duplicating the Xdata is unnecessary and likely to cause errors. You should write your model function Ycalc=F(x,Xdata) so that it takes as input an Xdata matrix containing a single copy of all the x-values
Xdata=[x1,x2,x3,...xN]
and returns as output a matrix of all the y-values
Ycalc=[(y1calc(x1),y1calc(x2),y1calc(x3)
y2calc(x1),y2calc(x2)y2calc(x3)...]
The output Ycalc should be a matrix of the same size and shape as your Ydata input and the elements Ycalc(i) should be ordered such that you want Ycalc(i) to fit Ydata(i) as closely as possible. That is all that lsqcurvefit cares about.