Are these polyfit curves correct?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Giovanni Virgen
le 19 Juil 2018
Commenté : Walter Roberson
le 19 Juil 2018
This is what I have to do:
Create an m-file that uses the polyfit, linspace, polyval and plot functions to create a plot of the data listed below along with a least-squares line, a third-degree polynomial and a five-degree polynomial fit. Plot the curves with 100 data points (linspace default) to produce smooth fit curves.
x = [-8, -6, -4, -2, -1, 0, 1, 2, 4, 6, 8]
y = [0.1, 0.2, 0.5, 0.7, 2.2, 3.8, 5.5, 3.6, 2.8, 4.0, 3.5]
This is what I have so far.
x = linspace(-8,8);
y = linspace(0.1,3.5);
p = polyfit(x,y,3);
x2 = 0:0.1:3.1;
y2 = polyval(p,x2);
v = polyfit(x,y,5);
c = polyval(v,x2);
subplot(2,1,1)
plot(x,y,x2,y2)
legend('x,y,polyfit')
xlabel('x')
ylabel('y')
subplot(2,1,2)
plot(x,y,x2,c)
legend('x,y,polyfit')
xlabel('x')
ylabel('y')
Réponse acceptée
madhan ravi
le 19 Juil 2018
Modifié(e) : madhan ravi
le 19 Juil 2018
Codes are correct
%one remark
%x2=-8:0.1:8
%because the start and endpoint should be similar to x.
plot(x,y,'ob'x2,y2,'')
%use line markers to distinguish between them :)
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrices and Arrays 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!