Variable X must be of size [12 4]. It is currently of size [12 5]. Check where the variable is assigned a value.
조회 수: 3 (최근 30일)
이전 댓글 표시
m = 1:12; m = m';
Y = [2.8 3.5 4.7 6.3 6.6 7 6.4 5.8 5.3 4.2 3.4 2.6]';
% Part (a)
X = [ones(size(m)) m m.^2 m.^3 m.^4 ];
z = X'*Y;
S = X'*X;
U = chol(S);
w = U'\z;
disp('(a) Coefficients:')
c = U\w
plot(m,Y,'o'), hold on
q = min(m):0.1:max(m);
fit = c(1) + c(2)*q + c(3)*q.^2 + c(4)*q.^3 + c(5)*q.^4;
plot(q, fit), hold off
xlabel('m'), ylabel('Y')
legend('Data Points', 'Curve Fit')
title('Part (a)')
% Part (b)
c = X\Y
c = c([5:-1:1]);
figure, plot(m,Y,'o'), hold on
q = min(m):0.1:max(m);
fit = polyval(c, q);
plot(q, fit), hold off
xlabel('m'), ylabel('Y')
legend('Data Points', 'Curve Fit')
title('Part (b)')
댓글 수: 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!