quadratic curvature doesn't went smoothly
조회 수: 3 (최근 30일)
이전 댓글 표시
Anyone can help me?
I am trying to fit my data with first and second order polynomial, but the result of quadratic curvature doesn't smoothly, seems it repeat several time in certain point. Here is my code
%Loads the vectors x and y.
load steam
% Fit a first degree polynomial to the data.
[p s]= polyfit(x,y,2);
y1=polyval(p,x);
% PLOTTING DATA
plot(x,y,'o',MarkerFaceColor='k',MarkerEdgeColor='none')
hold on
plot(x,y1,'--')
steam data is
댓글 수: 0
채택된 답변
John D'Errico
2023년 10월 24일
편집: John D'Errico
2023년 10월 24일
load steam
% Fit a first degree polynomial to the data.
[p s]= polyfit(x,y,2);
y1=polyval(p,x);
% PLOTTING DATA
plot(x,y,'o',MarkerFaceColor='k',MarkerEdgeColor='none')
hold on
plot(x,y1,'--')
What is the problem? You are confused by the line that is plotted, I know. That just means your data was not sorted. Plot connects the dots. But if the dots are not in sequential order for x, then it back tracks.
diff(x)
Do you see some the elements of x are not uniformly increasing? The negative elements in the diff tell you that.
[xs,tags] = sort(x);
ys = y(tags);
yshat = polyval(p,xs);
figure
plot(x,y,'o',MarkerFaceColor='k',MarkerEdgeColor='none')
hold on
plot(xs,yshat,'--')
There is no problem when you plot only the points as dots, but when you connect the dots, watch out!!!!!!!
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!