lsqcurvefit with two functions and same vriables
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi, this is my problem:
I have two data sets X1,Y1 and X1,Y2. For exmaple
X1 =
0.0079
0.0157
0.0314
0.0629
Y1 =
2.5172
3.0338
2.5687
2.2744
Y2 =
0.3167
0.7461
0.3454
0.3072
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
%%%-----Parameter(1):
start_p1=10;
lb_p1=0;
ub_p1=100;
%%%-----Parameter(2):
start_p2=-0.5;
lb_p2=-1;
ub_p2=0;
parameterstart = [start_p1,start_p2];
lb =[lb_p1,lb_p2];
ub =[ub_p1,ub_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
fun_12=@(parameter,x)[fun_1(parameter,x), fun_2(parameter,x)];
% 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 :-)
댓글 수: 1
채택된 답변
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!