How to get a an XY plotted curve to match another curve based on observed values?
1 view (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Matt Tearle
on 15 Apr 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)
0 Comments
See Also
Categories
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!