How do I correctly code with polyfit?
Ältere Kommentare anzeigen
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 Kommentare
Jonas
am 14 Dez. 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
am 14 Dez. 2022
Jonas
am 14 Dez. 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;
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

