How to make plots with symbols(representing data points) and a fitting curve (fit the points with polynomial or other curve equations)
조회 수: 4 (최근 30일)
이전 댓글 표시
This is the code I have right which gives a smooth curve passing through the data points:
figure
x1 = [0,0.0521,0.1042, 0.1563, 0.2083, 0.2604, 0.3125, 0.3646, 0.4167];
x1q = linspace(x1(1),x1(end),100);
y1 = [2.4015, 2.9473, 4.5847, 5.7855, 7.4229, 9.6061, 12.2259, 13.2083, 13.6450];
y1q = interp1(x1,y1,x1q,'pchip');
x2 = [0, 0.0510, 0.1020, 0.1531, 0.2041, 0.2551];
x2q = linspace(x2(1),x2(end),100);
y2 = [1.6836, 2.3150, 3.2620, 3.9986, 4.9456, 6.8397];
y2q = interp1(x2,y2,x2q,'pchip');
plot(x1q,y1q,'r',x2q,y2q,'b')
hold on
plot(x1,y1,'rx',x2,y2,'bo')
댓글 수: 0
답변 (1개)
Star Strider
2019년 3월 26일
Try this:
b1 = polyfit(x1, y1, 1); % Linear Function
y1p = polyval(b1, x1q);
b2 = polyfit(x2, y2, 3); % 3-Degree Polynomial
y2p = polyval(b2, x2q);
figure
plot(x1, y1, '+r', x1q, y1p, '-r')
hold on
plot(x2, y2, 'ob', x2q, y2p, '-b')
hold off
grid
Experiment to get the result you want.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!