How do I correctly code with polyfit?
Afficher commentaires plus anciens
Hello everyone, I've been working on this problem for the last hour and I can't find a way to use polyfit and polyval like how they want it in the instructions
(1 pt) Enter the following data
x = 0 : 1 : 8;
y = [47, 12, 0, 40, 30, 36, 60, 110, 156];
(1 pt) Open a figure and plot the data with circle markers.
(3 pts) Use the polyfit() function to compute the coefficients of a 3rd-order fit to this data.
(3 pts) Set x3 = 0 : 0.2 : 8;
Use the polyval() function with the computed coefficients and the x3 vector to compute the y values of the 3rd-
order fit.
(2 pts) Use hold on and grid on.
Then plot the 3rd-order fit on the same figure.
My code
x = 0 : 1 : 8;
y = [47, 12, 0, 40, 30, 36, 60, 110, 156];
figure;
plot(x,y,'o')
3 commentaires
Jonas
le 14 Déc 2022
just call polyfit with x, y and your order. then, use the output argument with the polyval function and the new x values which are asked for
and yes, i could write down the code, but it's your homework
Eduardo Gallegos
le 14 Déc 2022
Jonas
le 14 Déc 2022
perfect
but please use code format to post code in the forum here (see the most left button in the code tool section)
e.g.
x3 = 0:0.2:8;
instead of
x3 = 0:0.2:8;
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Get Started with Curve Fitting Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

