How do I perform a linear least squares fit
307 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Alexander MacFarlane IV
le 21 Déc 2018
Modifié(e) : Tamas Kis
le 26 Juil 2021
Hello.
I would like to perform a linear least squares fit to 3 data points.
The help files are very confusing, to the point where i can't figure out whether this is a base function of Matlab, I need the curve fitting toolbox, optimization toolbox, or both.
Thanks,
Alex
0 commentaires
Réponse acceptée
Plus de réponses (2)
Image Analyst
le 21 Déc 2018
Modifié(e) : Image Analyst
le 21 Déc 2018
See attached polyfit demo. Adapt as needed. All you need is base MATLAB - no toolboxes.
For example
coefficients = polyfit(x, y, 1);
yFitted = polyval(coefficients, x); % yFitted will be at the 3 points where x is. There will be 3 yFitted values.
If you want a lot more points, you can pass in more x to polyval():
xFit = linspace(min(x), max(x), 1000); % 1000 points.
yFitted = polyval(coefficients, xFit);
Tamas Kis
le 25 Juil 2021
Modifié(e) : Tamas Kis
le 26 Juil 2021
Function to perform curve fitting using linear least squares:
Linear and polynomial fits are linear least square fits, while the other fits (power, exponential, logarithmic) are approximated by first linearizing the data.
0 commentaires
Voir également
Catégories
En savoir plus sur Interpolation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!