Using lsqcurvefit without knowning the function
조회 수: 4 (최근 30일)
이전 댓글 표시
This is what I understand from the matlab help
x = lsqcurvefit(@myfun,x0,xdata,ydata)
function F = myfun(x,xdata)
F = ... % Compute function values at x, xdata
The least square non-linear fit will match the ydata and the F-output by changing the x value.
My question is that " is xdata the input to calculate F?" Does xdata have to have the same size as ydata?
It is hard for me to apply lsqcurvefit to my problem. I have Xdata_e, Ydata_e from the experiments ( XYdata_e combines Xdata_e and Ydata_e) and I want to match with Xdata_s, Ydata_s from the simulation by changing the parameter x.
I have
function F = myfun(x,XYdata_s) % where XYdata_s contains Xdata_s and Ydata_s
giving the initial position X0 contains both x,y. Also giving time step, so on
The code will calculate Xdata_s, Ydata_s
F= the code that solves for Xdata_s and Ydata_s from simulation. Xdata_s is NOT using to calculate Ydata.
I set F=XYdata_s;
This is my lsqcurvefit
x = lsqcurvefit(@myfun,x0,XYdata_s,XYdata_e) % x0 is initial guess of x
I feel like there is something wrong in my code because XYdata_s is NOT the input to calculate F. Because XYdata_s is the matrix of my output that I want to match with XYdata_e. Basing on my code, the input is the initial position of x and y which does not have the same dimension as XYdata_e. The initial position X0 contains both x and y having the dimension of 6 x1. However, the dimension of XYdata_e has the dimension of 100 x 6. I dont know how to set it correctly. Please helps.
Any thoughts will be appreciated. Thank you.
댓글 수: 1
Matt J
2014년 1월 30일
Laura,
Please don't delete your Comments/Questions from the thread (assuming it was you!) once people have responded to them. It makes the thread hard to interpret for others who read it later.
채택된 답변
Matt J
2014년 1월 30일
편집: Matt J
2014년 1월 30일
However, the dimension of XYdata_e has the dimension of 100 x 6. I dont know how to set it correctly.
If the given target data XYdata_e has dimension 100 x 6, then F(x,XYdata_s) must always return an output array of dimension 100x6. That is the only restriction.
댓글 수: 1
Matt J
2014년 1월 30일
편집: Matt J
2014년 1월 30일
x = lsqcurvefit(@myfun,x0,X0,XYdata_e)
does look correct. The dimension of X0 has no importance. Only that F(x,X0) produce an output the same size as your measured output data XYdata_e.
The input X0 can even be empty [] as the following example shows
>> f=@(x,X0)(1:6)*x; X0=[]; XYdata_e=(1:6)*2;
>> x_estimate= lsqcurvefit(f,0,X0,XYdata_e)
x_estimate =
2
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!