Curve fitting with a general function
이전 댓글 표시
Hello Everyone,
I am working on a project and I need to fit a curve with a general function. I am not sure if it can be done in Matlab. I did some search. It looks like Matlab can work if the function can be solved as a y=f(x). But what if a function can not be solved analytically like y=A*x*sin(x+B*y) (A,B are parameters). How can I use this kind of functions to do curve fitting and get parameters A,B? Thanks in advance for any help you can provide.
답변 (3개)
It should be straightfoward with LSQNONLIN or FSOLVE, if you have the Optimization Toolbox. The objective function would be the residual,
f(A,B) = y-A*x.*sin(x+B*y)
Or, even if you don't have the toolbox, FMINSEARCH shouldn't be too bad, with only 2 unknonws
f=@(AB) norm(y-AB(1)*x.*sin(x+AB(2)*y);
fminsearch(f, AB_guess);
Image Analyst
2013년 8월 15일
0 개 추천
If there is no known equation that you believe you can fit your data to, then you can use a spline fit, where you have a new cubic equation between every pair of points. It sounds more complicated than it is. People use them all the time. It's a numerical description rather than an analytical description. Or you might try something like SLM: http://www.mathworks.com/matlabcentral/fileexchange/24443
Matlab can work if the function can be solved as a y=f(x). But what if a function can not be solved analytically like y=A*x*sin(x+B*y)
Even though 'y' appears on both the left and right hand side, you can probably make any "y=f(x) curve fitter" work by replacing the right-hand y with an artificial 3rd variable z
y=A*x*sin(x+B*z)
So, now you have y=f(x,z). As long as you feed z-data equal to the y-data to the curve fitting algorithm, it will see the exact same residuals (difference between left and right hand side) for every pair A,B that it explores. So, I think that from the point of view of the fitting software, you will get the same result as with y=A*x*sin(x+B*y).
댓글 수: 2
Peng
2013년 8월 15일
There is an error in defining function: Error in MuPAD command: The number of arguments is incorrect.
You shouldn't be using (or have need for) any Symbolic Toolbox commands here.
x and y are the column arrays...Error using Inner matrix dimensions must agree.
I assume this error is really coming from EXPM. If x and y are column vectors and A,B,C are scalars, then EXPM won't work. Are you sure EXP isn't the appropriate thing here?
카테고리
도움말 센터 및 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!