Variable X must be of size [12 4]. It is currently of size [12 5]. Check where the variable is assigned a value.
4 次查看(过去 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!