How to get a an XY plotted curve to match another curve based on observed values?

If I have as function that is supposed to model an observable phenomenon with a variable that can be adjusted, how can I get Matlab to adjust that variable to achieve an output that can be compared to and matched as closely as possible to an observed set of data points?

답변 (1개)

Sounds like a regression/curve fitting problem? The right function to use depends a bit on the form of the model. If it's just a single parameter, I'm guessing it's a nonlinear model, in which case use nlinfit if you have Statistics Toolbox. Otherwise, you can brute force it and use fminsearch.
For example, to fit a model y = cos(kx) to data stored in vectors xdata & ydata, using an initial guess of pi for k:
f = @(k,x) cos(k*x);
kfit = nlinfit(xdata,ydata,f,pi)
or
f = @(k) norm(ydata - cos(k*xdata));
kfit = fminsearch(f,pi)

카테고리

도움말 센터File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

질문:

2011년 4월 15일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by