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!

