lsqcurvefit with two functions and same vriables
조회 수: 7(최근 30일)
Hi, this is my problem:
I have two data sets X1,Y1 and X1,Y2. For exmaple
Now the data set X1,Y1 has to be fitted with the function fun_1 and the data set X1,Y2 with the function fun_2 using lsqcurvefit.
This is my code, which is NOT working:
% Putting both data sets in one vector for X and one vector for Y:
XX = [X1;X1]
YY = [Y1;Y1]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Start and boundary data
parameterstart = [start_p1,start_p2];
% Declaration of the functions
fun_1 = @(parameter,x)parameter(1).*(x).^parameter(2);
fun_2 = @(parameter,x)(-parameter(1).*cot(((parameter(2)+1)*pi)/2)).*(x).^parameter(2);
% Putting both functions in one array
% Fitting with lsqcurvefit
parameter = lsqcurvefit(fun_12,parameterstart,XX,YY,lb,ub)
The error is
Error using lsqcurvefit (line 262)
Function value and YDATA sizes are not equal
The problem is that XX has the dimension 8x1, but since XX is addressed by fun_12 twice (since it contains two functions fun_1 and fun_2) , fun_12 becomes the dimension 8x2.
How can this problem be solved?
Thanks in Advance :-)