How do I correctly code with polyfit?
显示 更早的评论
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 个评论
Jonas
2022-12-14
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
2022-12-14
Jonas
2022-12-14
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;
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

