Linear Least Squares Regression

3 vues (au cours des 30 derniers jours)
A
A le 9 Déc 2022
Commenté : A le 10 Déc 2022
x = [2, -2, 3, -3];
y = [7, 8, 19, 17];
N = length(x);
X = 'ones (N, 1), x';
Y = y;
J='inv(X.*X)*X*Y';
plot(x,y,'bs',[0, 5],J(1)+J(2)*[0, 5]+J(3)*[0, 5]);
hold on
how can i turn this graph into this graph

Réponses (1)

Bora Eryilmaz
Bora Eryilmaz le 9 Déc 2022
Modifié(e) : Bora Eryilmaz le 9 Déc 2022
% Original data
x = [2, -2, 3, -3];
y = [7, 8, 19, 17];
% Take tranposes.
x = x';
y = y';
% Find coefficients of a quadratic polynomial fit using linear least
% squares method.
C = [x.^2 x ones(size(x))] \ y
C = 3×1
2.1000 0.1538 -0.9000
% Get interpolated values on the polynomial.
xi = (-4:0.1:4)';
yi = C(1)*xi.^2 + C(2)*xi + C(3);
% Plot results.
plot(x,y, 'r*')
hold on
plot(xi,yi,'b-')
  1 commentaire
A
A le 10 Déc 2022
thank bro

Connectez-vous pour commenter.

Catégories

En savoir plus sur Descriptive Statistics dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by