How to get a an XY plotted curve to match another curve based on observed values?
Afficher commentaires plus anciens
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?
Réponses (1)
Matt Tearle
le 15 Avr 2011
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)
Catégories
En savoir plus sur Linear and Nonlinear Regression dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!