need help to plot smooth of 𝑦̂ the least-squares fit to the data, over the range of x-values
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
function [coefficients, MSE] = pnnnfit(x, y, order)
coefficients = polyfit(x, y, order)
y_fitted = polyval(coefficients, x)
squaredError = (y - y_fitted) .^ 2
MSE = sum(squaredError)
plot(x, y,'o')
end
%x=[0 .5 1 1.5 2 2.5 3 3.5 4 4.5 5];
% y=[0 -5.27 -8.10 -8.46 -6.38 -1.84 5.15 14.59 26.48 40.83 57.63];
Réponses (1)
Ameer Hamza
le 2 Déc 2020
Modifié(e) : Ameer Hamza
le 2 Déc 2020
You are just plotting the actual points. The y_fitted will be smooth
x=[0 .5 1 1.5 2 2.5 3 3.5 4 4.5 5];
y=[0 -5.27 -8.10 -8.46 -6.38 -1.84 5.15 14.59 26.48 40.83 57.63];
pnnnfit(x, y, 2);
function [coefficients, MSE] = pnnnfit(x, y, order)
coefficients = polyfit(x, y, order)
y_fitted = polyval(coefficients, x)
squaredError = (y - y_fitted) .^ 2
MSE = sum(squaredError)
plot(x, y,'o')
hold on
plot(x, y_fitted)
end
0 commentaires
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots 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!